HTML Favicon
π What is a Favicon?
A favicon (short for βfavorite iconβ) is a small icon that appears in a browser tab, bookmark list, or shortcut when your site is saved. It's an essential part of your website's branding and user experience β¨.
>>βTiny in size, massive in identity β that's the power of a favicon.β π§
π§± How to Add a Favicon in HTML
Favicons are added using a <link> tag inside the <head> section of your HTML document.
Basic Favicon Syntax
<head>
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
</head>Note
π‘ The file favicon.ico should be placed in the root directory of your website, or you must specify the correct path in href.
π¨ Supported Favicon Formats
| Format | Usage |
|---|---|
| .ico | Classic format supported by all browsers |
| .png | High-quality, modern browsers only |
| .svg | Vector, scalable, great for modern browsers |
π Examples of Favicon Usage
πΉ Using PNG Format
PNG Favicon
<link rel="icon" type="image/png" href="/favicon.png" />πΈ Using SVG Format
SVG Favicon
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />π§© Providing Multiple Sizes (Optional)
You can specify multiple favicons for different devices or resolutions:
Multiple Sizes Example
<link rel="icon" sizes="32x32" href="/favicon-32x32.png" />
<link rel="icon" sizes="16x16" href="/favicon-16x16.png" />π§ͺ Testing Your Favicon
- Place the favicon file in your public folder
- Ensure your <link> tag is inside the <head> tag
- Clear your browser cache and refresh the page
Note
β οΈ Some browsers aggressively cache favicons β try using Ctrl + F5 or open in incognito if changes don't appear.
π Tips for Better Favicons
- Keep it simple β icons are very small
- Use high contrast and avoid text in the icon
- Use a square dimension (e.g., 16x16, 32x32, 64x64)
π§° Favicon Generator Tools
>>βEven the smallest details like a favicon leave a lasting impression.β π