A favicon (short for “favorite icon”) is a small icon associated with a particular website or web page. Favicons are displayed in places such as the browser’s address bar, tabs, bookmarks, and sometimes in the history. They provide a visual identifier for a site, helping users recognize it quickly.

How Favicons Work

Favicons are typically 16×16 pixels in size, but they can also be larger (e.g., 32×32, 48×48, 64×64) to support different devices and high-resolution screens. They are usually saved in the ‘.ico‘ format, but modern browsers also support other formats like ‘.png‘, ‘.gif‘, and ‘.svg‘.

Steps to Add a Favicon to Your Website

  1. Create the Favicon File:

    • You can create a favicon using an image editor (e.g., Photoshop, GIMP) or an online favicon generator.
    • Save the favicon in an appropriate format (e.g., .ico, .png).
  2. Place the Favicon File in Your Website’s Directory:

    • It’s common to place the favicon file in the root directory of your website (e.g., example.com/favicon.ico).
  3. Link the Favicon in Your HTML:

    • Add a link to the favicon in the <head> section of your HTML document. Here are examples for different formats:

Examples:

Basic Favicon (ICO Format):

				
					<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Example with Favicon</title>
    <link rel="icon" href="/favicon.ico" type="image/x-icon">
</head>
<body>
    <h1>Hello, World!</h1>
</body>
</html>

				
			

Favicon in PNG Format:

				
					<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Example with Favicon</title>
    <link rel="icon" href="/favicon.png" type="image/png">
</head>
<body>
    <h1>Hello, World!</h1>
</body>
</html>

				
			

Favicon in Multiple Formats (for better compatibility):

				
					<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Example with Favicon</title>
    <link rel="icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" href="/favicon.png" type="image/png">
    <link rel="icon" href="/favicon.svg" type="image/svg+xml">
</head>
<body>
    <h1>Hello, World!</h1>
</body>
</html>

				
			

Apple Touch Icon (for iOS Devices):

				
					<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Example with Favicon</title>
    <link rel="icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" href="/favicon.png" type="image/png">
    <link rel="apple-touch-icon" href="/apple-touch-icon.png">
</head>
<body>
    <h1>Hello, World!</h1>
</body>
</html>

				
			

Advanced Tips

  • Different Sizes: Provide favicons in multiple sizes to ensure they look good on different devices and resolutions. This can be done using multiple <link> elements.
  • Modern Browsers and Standards: Use the appropriate type attribute to ensure compatibility with modern browsers.
  • Caching: Browsers cache favicons, so if you update your favicon, you might need to clear the browser cache or use a new file name to see the changes immediately.
Scroll to Top