TExcelTAD
Home › HTML › HTML Favicon

HTML Favicon

A favicon ("favorite icon") is the small picture shown next to a page's title in the browser tab. It also appears in bookmarks, history and on phone home screens when someone saves your site. A good favicon makes your site easy to spot among a row of open tabs.

Adding a favicon

Favicons are added with a <link> element inside the <head>:

html
<!DOCTYPE html>
<html>
<head>
  <title>My Site</title>
  <link rel="icon" type="image/png" href="/favicon.png">
</head>
<body>
  ...
</body>
</html>
  • rel="icon" tells the browser this link is the page's icon.
  • href points to the image file.
  • type (optional) states the file format.

If you don't add any <link rel="icon">, many browsers automatically look for a file called /favicon.ico in the root of your site.

File formats

Format type value Notes
ICO image/x-icon The classic format; can hold several sizes in one file
PNG image/png Simple and widely supported
SVG image/svg+xml Scales to any size; supported by all modern browsers
GIF image/gif Rarely used for icons now

Sizes

Icons are small, but different places use different sizes. A typical modern set is:

Size Used for
16×16, 32×32 Browser tabs and bookmarks
180×180 Apple touch icon (iPhone/iPad home screen)
192×192, 512×512 Android home screen and web app manifests
html
<link rel="icon" href="/favicon.ico" sizes="any">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">

Tip: Keep the design simple: one letter, a bold shape or a strong color. Fine detail disappears at 16 pixels.

An emoji favicon with no files

Because SVG can be written inline as a data URI, you can make a favicon without any image file at all. This trick puts an emoji in an SVG:

html
<link rel="icon"
      href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🌐</text></svg>">

The playground below can't change the tab icon of this tutorial site (it runs inside a frame), but it shows you what your icon would look like at real favicon sizes. Edit the emoji or colors and run it again.

html · try it yourself
<style>
  body { font-family: sans-serif; }
  .tab {
    display: inline-flex; align-items: center; gap: 8px;
    background: #f1f3f4; border-radius: 8px 8px 0 0;
    padding: 8px 14px; font-size: 13px; border: 1px solid #ccc; border-bottom: none;
  }
  .tab img { width: 16px; height: 16px; }
</style>
<p>Your icon in a fake browser tab:</p>
<div class="tab">
  <img alt="" src="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🌐</text></svg>">
  My Awesome Site
</div>
<p>Same icon at 16, 32 and 64 pixels:</p>
<img alt="" width="16" height="16" src="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🌐</text></svg>">
<img alt="" width="32" height="32" src="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🌐</text></svg>">
<img alt="" width="64" height="64" src="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🌐</text></svg>">

Designing a letter icon in SVG

Many sites use a single letter on a colored shape. Here is one written as SVG. Try changing the letter, the colors or rx (corner rounding):

html · try it yourself
<svg width="128" height="128" viewBox="0 0 32 32" role="img" aria-label="Favicon preview">
  <rect width="32" height="32" rx="7" fill="#e34c26"/>
  <text x="16" y="23" font-size="20" font-weight="bold" font-family="sans-serif"
  text-anchor="middle" fill="white">E</text>
</svg>
<svg width="32" height="32" viewBox="0 0 32 32" role="img" aria-label="Favicon at 32px">
  <rect width="32" height="32" rx="7" fill="#e34c26"/>
  <text x="16" y="23" font-size="20" font-weight="bold" font-family="sans-serif"
  text-anchor="middle" fill="white">E</text>
</svg>
<svg width="16" height="16" viewBox="0 0 32 32" role="img" aria-label="Favicon at 16px">
  <rect width="32" height="32" rx="7" fill="#e34c26"/>
  <text x="16" y="23" font-size="20" font-weight="bold" font-family="sans-serif"
  text-anchor="middle" fill="white">E</text>
</svg>

Save that SVG markup into a file called icon.svg, then link it with <link rel="icon" href="icon.svg" type="image/svg+xml">.

Troubleshooting

  • Icon doesn't change? Browsers cache favicons aggressively. Try a hard refresh, or add a version to the URL: favicon.png?v=2.
  • Icon missing on some pages? Make sure every page includes the <link> tag, and that the href path is correct from that page (an absolute path like /favicon.png avoids surprises).
  • Blurry icon? Provide a size that matches, or use SVG.

Test yourself

Which element adds a favicon to a page?

  1. <icon src="favicon.png">
  2. <link rel="icon" href="favicon.png">
  3. <img rel="favicon" src="favicon.png">
  4. <meta name="icon" content="favicon.png">

Where should the favicon <link> element be placed?

  1. At the end of <body>
  2. Inside <head>
  3. Inside <title>
  4. Anywhere in the page

Which favicon format scales cleanly to any size?

  1. ICO
  2. PNG
  3. SVG
  4. GIF