How to add a favicon
Save your icon on the site and point to it from a <link rel="icon"> tag in <head>:
<link rel="icon" href="/favicon.ico">
That is the whole answer for a basic site. The href can point to an .ico, .png or .svg file. The example below uses an SVG written straight into the href as a data URI, so it needs no separate file. A preview inside another page cannot change your browser tab, so the script draws the same icon in a mock tab and at three sizes:
At 16 pixels there is room for one bold letter or a simple shape, and fine detail disappears. Design the icon for the smallest size first. Change fill='%232563eb' to another color (%23 is the URL-encoded #) and every copy updates.
Which files to ship
Browsers, phones and app launchers look for different icons. A small set covers all of them:
<link rel="icon" href="/favicon.ico" sizes="32x32">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="manifest" href="/manifest.webmanifest">
| File | Size | Used for |
|---|---|---|
favicon.ico | 32×32 | Browser tabs, and tools that only look for /favicon.ico |
icon.svg | Any (vector) | Sharp tabs at every screen density, in Chrome, Edge and Firefox |
apple-touch-icon.png | 180×180 | The icon when someone adds your site to an iPhone or iPad home screen |
| Manifest icons | 192×192 and 512×512 PNG | Android home screen and installed web apps |
Most browsers also request /favicon.ico from the site root on their own when a page has no icon link, so placing a favicon.ico there is a useful default. The sizes attribute tells the browser which size each file is, so it can pick the best match. Use rel="icon"; the older rel="shortcut icon" works only because browsers ignore the extra word.
An emoji favicon
For a prototype or a personal page, an emoji makes a quick favicon. Put it inside an SVG <text> element:
%F0%9F%8D%AA is the cookie emoji, URL-encoded. The emoji is drawn by the operating system's emoji font, so it looks different on Windows, macOS and Android, and for a real product a designed icon is the better choice.
An icon that follows dark mode
An SVG favicon can carry its own CSS, including a prefers-color-scheme media query, so a dark icon can turn light when the browser uses a dark theme:
<!-- icon.svg -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
<style>
circle { fill: #111827; }
@media (prefers-color-scheme: dark) { circle { fill: #f9fafb; } }
</style>
<circle cx="16" cy="16" r="14"/>
</svg>
Changing the favicon with JavaScript
Sites use a changing favicon for a notification dot or a status color. Draw the new icon on a <canvas> and set the link's href to the canvas image:
On a real page in Chrome or Firefox, the tab icon changes each time href is set, the same moment the preview image changes here.
Common mistakes
- A wrong path.
href="favicon.ico"is relative to the current page, so it breaks on/blog/post. Use a root path:href="/favicon.ico". - Expecting an update to show at once. Browsers cache favicons hard. Reload with the cache cleared, or change the URL (
/favicon.ico?v=2) when you replace the icon. - A detailed logo shrunk to 16 pixels. Simplify it: one letter or one shape with strong contrast.
- Only an SVG. Keep an ICO or PNG too for browsers without SVG favicon support, and add the
apple-touch-iconfor iOS. - Putting the link in
<body>. Keep it in<head>with the title tag and other metadata.
Frequently Asked Questions
How do I add a favicon in HTML?
Put the icon file on your site and add <link rel="icon" href="/favicon.ico"> (or a PNG or SVG path) inside <head>. Browsers then show it in the tab, in bookmarks and in the history list.
What size should a favicon be?
Ship a 32×32 favicon.ico (or PNG) for tabs, an SVG that scales to any size, and a 180×180 PNG apple-touch-icon for iPhone home screens. Web apps with a manifest also list 192×192 and 512×512 PNGs.
Why is my favicon not showing?
The usual causes are a wrong path in href, the <link> sitting outside <head>, or the browser still showing a cached old icon. Open the icon URL directly to check the path, then reload with the cache cleared or add a version such as ?v=2 to the URL.
Can I use an SVG or PNG as a favicon?
Yes. Use <link rel="icon" href="/icon.svg" type="image/svg+xml"> or <link rel="icon" href="/icon.png" type="image/png">. SVG works in Chrome, Edge and Firefox; keep an ICO or PNG as well for browsers that do not support it.
Do I need rel="shortcut icon"?
No. rel="icon" is the standard value. The word shortcut is a leftover from old Internet Explorer and does nothing in current browsers.
Can I use an emoji as a favicon?
Yes, by wrapping it in an SVG: an SVG data URI containing a <text> element with the emoji. It is handy for prototypes, but the emoji looks different on each operating system.