HOW-TO

How to add a favicon in HTML

The one-line <link rel="icon"> tag, PNG vs SVG vs ICO, the sizes worth making, why browsers keep showing the old icon, and an icon that lives inside the HTML file itself.

4 min read·

Have the file already? Upload it and get a link anyone can open. Free plan, no card.

Get a link free

To add a favicon in HTML, put this line inside the <head> of your page: <link rel="icon" href="favicon.png" type="image/png">. The href is the path to your icon file, relative to the HTML file. Save, then open the page in a new tab; the icon appears to the left of the tab title.

The tags

  • ✓PNG: <link rel="icon" href="favicon.png" type="image/png">. A 32×32 or 48×48 pixel square is enough for browser tabs.
  • ✓SVG: <link rel="icon" href="favicon.svg" type="image/svg+xml">. One file stays sharp at every size. Current Chrome, Edge and Firefox support it; Safari support is more recent, so add a PNG line as well if Safari users matter.
  • ✓ICO: <link rel="icon" href="favicon.ico">. The old format. Browsers also request /favicon.ico from the top of the site on their own when a page has no icon tag, which is why a file with that exact name at the root works without any tag.
  • ✓Home screen icon for iPhone and iPad: <link rel="apple-touch-icon" href="apple-touch-icon.png"> with a 180×180 PNG.

A complete example

<!DOCTYPE html><html><head><meta charset="utf-8"><title>My page</title><link rel="icon" href="favicon.svg" type="image/svg+xml"><link rel="icon" href="favicon.png" type="image/png"><link rel="apple-touch-icon" href="apple-touch-icon.png"></head><body>…</body></html>. Put the icon files in the same folder as the HTML file so the paths match.

Make the icon file

  • ✓Start from a square image. Logos with fine detail turn to mush at 16 pixels; a single letter or a simple shape reads best.
  • ✓Export a 48×48 PNG from any image editor (Preview on a Mac: Tools, Adjust Size). A transparent background looks right on both light and dark tabs.
  • ✓For SVG, a short file works: <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="50" fill="#3a6bc2"/></svg>.
  • ✓An emoji makes a quick icon with no file at all, shown in the next section.

Put the icon inside the HTML file

If you share a single .html file, a separate favicon.png does not travel with it, and the icon breaks. Put the icon in the tag itself as a data URL instead:

Emoji: <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🚀</text></svg>">. Swap the rocket for any emoji. The %22 stands for a double quote so the attribute does not end early.

PNG: convert the image to base64 (on a Mac, base64 -i favicon.png | pbcopy copies it) and use href="data:image/png;base64,PASTE_HERE". Keep the image small; a 32×32 PNG is usually under 2 KB of text.

Why the favicon does not show up

  • ✓The tag is in the <body>. It only works inside <head>.
  • ✓The path is wrong. Open the href in its own tab; if you get a 404 or a download, fix the path. A leading slash (/favicon.png) means the top of the site, not the folder the page is in.
  • ✓The browser cached the old icon. Browsers hold favicons longer than pages. Hard-refresh (Ctrl+Shift+R or Cmd+Shift+R), open the page in a private window, or add a version to the path: favicon.png?v=2.
  • ✓The file opened from your own computer (a file:// address). Some browsers skip favicons for local files; check the page once it is hosted.
  • ✓Two icon tags point to different files. The browser picks one by type and size; delete the ones you do not need.

Pages made with AI tools

Pages from Claude, ChatGPT or Gemini usually come without a favicon, so the tab shows a blank page icon. Ask for one in plain words ("add an emoji favicon as an inline SVG data URL in the head") and the tool adds the line from the section above, which keeps the page a single file.

Share the page as a link

With FileShare Pro you upload the .html file from the dashboard, copy the link and send it; it opens as a page in any browser and the person opening it needs no account. Use the inline data-URL icon so the favicon comes along with the single file. When you change the page, upload it to the same link. Related: make an HTML file self-contained and how to add an image in HTML. Sign up free to share your first page.

Frequently asked

How do I add a favicon in HTML?

Add <link rel="icon" href="favicon.png" type="image/png"> inside the <head> of the page, with href pointing to your icon file.

What size should a favicon be?

A 32×32 or 48×48 pixel square PNG covers browser tabs. Add a 180×180 PNG as apple-touch-icon for iPhone home screens, or use one SVG that scales to any size.

Why is my favicon not showing?

The usual causes are a tag outside <head>, a wrong path, or a cached old icon. Open the icon path in its own tab to test it, then hard-refresh or add ?v=2 to the path.

Can I add a favicon without a separate file?

Yes. Use a data URL in the href, such as an inline SVG with an emoji or a base64-encoded PNG. The icon then lives inside the HTML file.

Got a page to share?

Drop the file, copy the link — live in seconds, free plan included.

Start sharing free