What is a favicon?

A favicon is the small icon that represents a site in browser tabs, bookmarks, history, search results and home screens. You declare it with <link rel="icon"> in <head>; browsers also look for /favicon.ico at the site root automatically.

A modern, minimal setup

  • favicon.ico (32×32) at the root for legacy browsers and tools that request it directly.
  • An SVG icon (<link rel="icon" href="/icon.svg" type="image/svg+xml">): scales perfectly and can even adapt to dark mode with a prefers-color-scheme media query inside the SVG.
  • apple-touch-icon (180×180 PNG) for iOS home screens.
  • A web app manifest (manifest.webmanifest) with 192×192 and 512×512 PNG icons for Android and installable PWAs, including a maskable icon.

Tips

  • Design for tiny sizes: a bold, simple mark, not a full logo with text.
  • Give the SVG favicon padding and good contrast on both light and dark tab bars.
  • Browsers cache favicons aggressively; change the file name or add a query string when you update it.
  • Google Search shows favicons in mobile results, so it must be crawlable and at least 48×48.

In frameworks

In the Next.js App Router, placing icon.svg, favicon.ico or apple-icon.png in app/ generates the right <link> tags automatically.

Interview tip

Mention that the favicon contributes to brand recognition among many open tabs, and that the SVG plus ICO plus apple-touch-icon trio covers nearly every platform.

Code example

html
1<!doctype html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>Favicon demo</title>
6 <link rel="icon" href="/favicon.ico" sizes="32x32">
7 <link rel="icon" href="/icon.svg" type="image/svg+xml">
8 <link rel="apple-touch-icon" href="/apple-touch-icon.png">
9 <link rel="manifest" href="/manifest.webmanifest">
10</head>
11<body style="font-family: system-ui">
12 <p>Watch the tab icon change:</p>
13 <button id="alert">Show unread badge</button>
14 <script>
15 // Swap the favicon at runtime (e.g. to show a notification dot)
16 const svg = (dot) => `data:image/svg+xml,${encodeURIComponent(
17 `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
18 <rect width="64" height="64" rx="14" fill="#2b4bff"/>
19 ${dot ? '<circle cx="50" cy="14" r="12" fill="#e11d48"/>' : ""}
20 </svg>`)}`;
21 const link = document.querySelector('link[rel="icon"][type="image/svg+xml"]');
22 link.href = svg(false);
23 document.getElementById("alert").onclick = () => (link.href = svg(true));
24 </script>
25</body>
26</html>

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the HTML & CSS set.

Open in study app