HTML Favicon
In this page:
<link rel="icon" type="image/x-icon" href="favicon.ico">
What is a Favicon?
A favicon (short for 'favorite icon') is a tiny graphic associated with a specific webpage or website. It acts as a visual anchor that represents your brand across the browser interface.
Example: What is a Favicon?
<!-- Favicon: the small icon shown in the browser tab -->
Favicon File Formats (ICO vs. PNG vs. SVG)
In the early days of the web, favicons had to be saved in the Microsoft ICO format. Today, modern browsers support PNG and scalable vector SVG formats, allowing for much sharper, translucent, and even responsive icons.
Example: Favicon File Formats (ICO vs. PNG vs. SVG)
<!-- favicon.ico, favicon.png, favicon.svg -->
Adding a Favicon to Your HTML
To add a favicon, you insert a special link tag inside the head section of your HTML document. The link tag requires a rel attribute set to icon and an href attribute pointing to your image path.
- Always write your favicon link tags inside the head section, ideally right after the title tag.
- Accepted attributes:
- rel — icon | shortcut icon (legacy) | apple-touch-icon
- href — URL of the icon file
- type — MIME type such as image/png | image/svg+xml | image/x-icon
- sizes — WxH list (e.g. 32x32) | any
Example: Adding a Favicon to Your HTML
<head>
<title>My Page</title>
<link rel="icon" href="favicon.png">
</head>
Apple Touch Icons for Mobile Devices
When mobile users bookmark your website or add it directly to their smartphone home screen, standard favicons often look blurry. Apple introduced the apple-touch-icon format to supply high-quality home screen web clips.
- Create a 180x180 pixel PNG with a solid background for the ultimate apple-touch-icon layout.
- Accepted attributes:
- rel — apple-touch-icon
- href — URL of the icon file (PNG)
- sizes — e.g. 180x180
Example: Apple Touch Icons for Mobile Devices
<link rel="apple-touch-icon" href="apple-touch-icon.png">
Managing Favicon Caching Issues
Web browsers cache favicons aggressively to save network data. This means that if you update your website logo icon, users might continue to see the old version for weeks unless you force a browser refresh.
Example: Managing Favicon Caching Issues
<link rel="icon" href="favicon.png?v=2">
Favicon Icons in the PWA Manifest
When a site is installed as a Progressive Web App, the icons shown on a phone's home screen come from the icons array inside manifest.json, not directly from the favicon link tags in the HTML head.
These manifest icons are usually much larger than a typical favicon, since they need to look sharp as a full home screen app icon.
Example: Favicon Icons in the PWA Manifest
<link rel="manifest" href="manifest.json">
<!-- manifest.json icons array includes 192x192 and 512x512 sizes -->
- Placing the favicon link tag inside the body tag instead of the head section.
- Changing a standard image filename extension to .ico on your desktop without converting the file structure.
- Neglecting mobile bookmark configurations, causing home screen web clips to look low-resolution and pixelated.
- A favicon is a brand-identifying graphic displayed on tabs, bookmark menus, and search indexing rows.
- Insert the link tag with the rel="icon" attribute inside the head container to declare your icon.
- Supply standard modern formats like PNG or SVG, alongside apple-touch-icons for mobile bookmark layouts.
Standard favicon formats are universally supported by all desktop, mobile, and legacy browsers.
Chapter Quiz — Complete all 26 topics to unlock
0/26 topics done
Complete these topics first:
- HTML Favicon
- HTML Page Title
- HTML Tables
- HTML Lists
- HTML Block & Inline
- HTML Comments
- HTML Colors
- HTML CSS
- HTML Links
- HTML Images
- HTML RGB Colors
- HTML HEX Colors
- HTML HSL Colors
- HTML Link Colors
- HTML Link Bookmarks
- HTML Background Images
- HTML Table Borders
- HTML Table Sizes
- HTML Table Headers
- HTML Table Padding & Spacing
- HTML Colspan & Rowspan
- HTML Table Styling
- HTML Table Colgroup
- HTML Unordered Lists
- HTML Ordered Lists
- HTML Other Lists / Description Lists