HTML Favicon: How to Add a Favicon, Sizes, and Formats
What is HTML Favicon: How to Add a Favicon, Sizes, and Formats? A favicon (favorites icon) is the small branding logo displayed on browser tabs, bookmarks, and mobile home screens. It is linked inside the HTML using the ta...
How do you add, configure, and optimize favicons for desktop browsers, iOS, and Android?
Explanation & In-Depth Details
2) The Evolution of Favicon Formats:
- SVG (.svg): Modern industry standard. Infinitely sharp, tiny file size, and supports CSS dark mode media queries (@media (prefers-color-scheme: dark)) inside the SVG file itself!
- PNG (.png): High-quality raster icons in 32x32 and 192x192 pixel resolutions.
- ICO (.ico): Legacy format containing multi-resolution bitmaps; supported by 100% of browsers back to Internet Explorer.
3) Essential Favicon Declarations:
- Modern SVG: <link rel="icon" type="image/svg+xml" href="/favicon.svg">
- Standard 32x32: <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
- Apple Touch Icon: <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
4) Web App Manifest for Android: Linking a 'manifest.json' file (<link rel="manifest" href="/site.webmanifest">) provides high-resolution 192x192 and 512x512 icons when users install your Progressive Web App (PWA).
5) Placing favicon.ico in the Root Directory: Even without explicit <link> tags, browsers automatically make a background HTTP request to '/favicon.ico'. Always ensure a physical 'favicon.ico' exists at your root web server directory to prevent 404 error logs.
Code Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Modern Favicon Setup</title>
<!-- 1. Modern Scalable SVG Favicon with Dark/Light Support -->
<link rel="icon" type="image/svg+xml" href="/icons/favicon.svg">
<!-- 2. Standard 32x32 PNG for desktop browsers -->
<link rel="icon" type="image/png" sizes="32x32" href="/icons/favicon-32x32.png">
<!-- 3. Apple Touch Icon for iPhone / iPad Home Screens -->
<link rel="apple-touch-icon" sizes="180x180" href="/icons/apple-touch-icon.png">
<!-- 4. Web Application Manifest for Android PWA -->
<link rel="manifest" href="/site.webmanifest">
</head>
<body>
<h1>Modern Favicon Architecture</h1>
<p>Look at the browser tab above to see the active favicon icon.</p>
</body>
</html>Interview Question & Tips
A1: SVG is resolution-independent (infinitely sharp on Retina displays), has an extremely small byte payload, and can contain CSS @media queries that automatically change icon colors when the user switches to Dark Mode.
Q2: What is the 'apple-touch-icon' and what dimensions should it have?
A2: It is the high-resolution app icon used by iOS when a user adds a website to their iPhone/iPad home screen. The recommended dimension is 180x180 pixels PNG.
Q3: Why should every website maintain a physical '/favicon.ico' file in the root web folder?
A3: Browsers, feed readers, and automated web scrapers will proactively send requests to 'https://example.com/favicon.ico' by default. If it is missing, your server logs become filled with thousands of unnecessary 404 errors.
Best Practices
This study reference for HTML Favicon: How to Add a Favicon, Sizes, and Formats is curated and verified against recognized curriculum benchmarks, peer-reviewed textbooks, and official technical documentation: