Page titles can get cut short when several browser tabs are open. An HTML page can supply a favicon, the small image beside its title that helps readers spot the tab.
A simple square PNG with a bold shape is easier to recognize at tab size than artwork with small lettering. The browser loads the image from the URL in the icon link.
A browser can keep showing an older favicon after the image changes. A new filename gives the replacement icon its own URL.
Steps to add a favicon in HTML:
Use just the filename when the PNG sits beside the HTML page and the page has no <base> element. Otherwise, use the icon's path from the site root, such as /site-icon.png, or its full URL if the base URL changes the scheme, hostname, or port.
- Copy your square PNG into the same folder as the HTML page you serve in your local preview.
The image here is a 32 × 32 pixel PNG named
site-icon.png. If that filename is already in use, give the new image an unused name. - Open your HTML file in your text editor.
The example uses
index.html, with a <head> element above the page body. - Insert an icon link with your PNG's path in href immediately before </head>.
<link rel="icon" href="site-icon.png">
If the page already has a tab icon link, replace it in place.
- Save the HTML file.
- Open the page from your local preview in a new tab in desktop Chrome.
The address in the screenshot is http://localhost:8000/index.html.
- Verify that the new tab shows the PNG from your icon link next to the page title.
The new Plant Notes tab shows a blue square with a white diamond.
- Verify that clicking the saved rel="icon" link's href in Chrome's View page source for that tab opens your intended PNG.
In the example, clicking site-icon.png opens the blue square with a white diamond at http://localhost:8000/site-icon.png.