A favicon, or favorite icon, is a small icon that represents a website or webpage and appears in the browser tab, bookmark bar, and other places in the user interface.
<!DOCTYPE html> <html> <head> <title>My Website</title> <link rel="icon" href="favicon.ico" type="image/x-icon"> </head> <body> <h1>Welcome to My Website</h1> <p>Some content here...</p> </body> </html>
In the above HTML code, we have added a ‘<link>’ element to the ‘<head>’ section of our HTML document. The ‘rel’ attribute specifies the relationship between the current document and the linked document, which in this case in the favicon. The ‘href’ attribute specifies the location of the favicon file on the server, which can be an image file in the ‘.ico’, ‘.png’, or ‘.svg’ format. The ‘type’ attribute spcifies the MIME type of the favicon file.
NOTE: The favicon file must be located in the root directory or your website and should be named ‘favicon.ico’. If you use a different file name or location, you need to update the ‘href’ attribute accordingly.
By adding a favicon to your website, you can make it look more professional and recognizable, and help users quickly identify your website among multiple open tags.