Academic Block

Academic Block logo
HTML Tutorial

HTML Favicon

What Is a Favicon in HTML?

A favicon (short for “favorite icon”) is a small icon associated with your website, visible in browser tabs, bookmark lists, and sometimes even in search results.


How to Add a Favicon in HTML?

To set favicon HTML correctly, include a <link> element in your document’s <head> section. You can add favicon HTML using an ICO (recommended for backward compatibility) or PNG (for sharper icons and transparent backgrounds) file. Also make sure that your favicon size is at least 32×32 pixels. To support high-DPI displays, you should consider adding a 16×16 and 48×48 PNG alongside your ICO file. You can place it in your site’s root directory for automatic detection by some browsers.

HTML Favicon Examples

1. Basic ICO Favicon

This example shows how to add a favicon in HTML with an ICO file named favicon.ico placed in your root folder.

          <!-- Example: Basic ICO favicon setup -->
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Basic ICO Favicon</title>
    <link rel="icon" href="/favicon.ico" type="image/x-icon">
  </head>
  <body>
    <p>Image below shows how your Favicon will look in the Browser.</p>
<img src="https://www.academicblock.net/wp-content/uploads/2025/05/HTML-Favicon-Example-AB.png" >
  </body>
</html>
        

2. PNG Favicon with Multiple Sizes

In this HTML code example, you’ll learn how to set PNG images as favicon in various devices.

          <!-- Example: PNG favicon setup for multiple sizes -->
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>PNG Favicon Example</title>
    <link rel="icon" href="/favicon-32x32.png" sizes="32x32" type="image/png">
    <link rel="icon" href="/favicon-16x16.png" sizes="16x16" type="image/png">
  </head>
  <body>
    <h1>Multiple Sizes Favicon Demo</h1>
<img src="https://www.academicblock.net/wp-content/uploads/2025/05/Different-Favicon-Size-Example.jpg" >
  </body>
</html>
        

3. Custom Favicon with Android Support

Likewise, you can also add Android-specific icons or Apple icons using HTML favicon tags. Using this HTML Code, browser will automatically detect device type and will display suitable favicon accordingly.

          <!-- Example: Custom favicon for Apple and Android -->
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Custom Favicon Example</title>
    <link rel="icon" href="/favicon.ico" type="image/x-icon">
    <link rel="apple-touch-icon" href="/apple-touch-icon.png">
  </head>
  <body>
    <h1>Custom Favicon, Code explanation </h1>
   <p>This code will allow you to display custom favicon depending on the user device. With this code "favicon.ico" will appear in android device, while the apple device will see "apple-touch-icon.png".</p>
  </body>
</html>
        

4. Using Inline SVG as Favicon

Inline SVG as a favicon embeds your SVG markup directly in the <link rel=”icon” href=”data:image/svg+xml,…”> tag, removing the need for separate image files. This technique delivers sharp, resolution-independent icons that scale perfectly on any device and can be styled or animated via CSS.

          <!-- Example: SVG favicon inline -->
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>SVG Favicon</title>
    <link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><text y='14' font-size='16'>🚀</text></svg>" type="image/svg+xml">
  </head>
  <body>
    <h1>SVG Favicon Inline</h1>
    <p> When you will run this HTML code you can see 🚀 as favicon in your web browser.</p>
  </body>
</html>
        

Additional Tips for HTML Favicon

You should always check your favicon in different browsers and devices. In conclusion, by following above examples and using proper favicon setup for website, you can ensure a consistent brand presence and user accessibility. Table below provides a consolidated overview of favicon formats and usage across all major browsers:

Format
MIME Type
HTML Tag
Recommended Sizes
Browser Support
ICO
image/x-icon
<link rel=”icon” href=”/favicon.ico”>
16×16, 32×32, 48×48 (bundled in one file)
All major desktop browsers (Chrome, Firefox, Edge, IE, Opera)
PNG
image/png
<link rel=”icon” type=”image/png” sizes=”32×32″ href=”/favicon-32×32.png”>
16×16, 32×32, 96×96, 192×192
All modern browsers; automatically scaled as needed
SVG
image/svg+xml
<link rel=”icon” type=”image/svg+xml” href=”/favicon.svg”>
Scalable vector (no fixed size)
Chrome 80+, Firefox 41+, Edge, Safari via mask-icon only
GIF
image/gif
<link rel=”icon” type=”image/gif” href=”/favicon.gif”>
16×16, 32×32
Supported by most browsers, but limited animation support
Apple Touch
image/png
<link rel=”apple-touch-icon” sizes=”180×180″ href=”/apple-touch-icon.png”>
180×180 (iPhone/iPad Retina); 120×120 for older
Native support in iOS Safari when adding to Home Screen
Mask Icon
image/svg+xml
<link rel=”mask-icon” href=”/safari-pinned-tab.svg” color=”#5bbad5″>
Scalable vector (monochrome mask)
Safari pinned tabs on macOS and iOS
Web Manifest
application/manifest+json
<link rel=”manifest” href=”/site.webmanifest”>
Defined per icon entry in JSON (e.g., 192×192, 512×512)
Chrome, Edge, Firefox, Android browsers for PWAs

Web Resources on HTML Favicon

1. University of Washington – Creating a Favicon
2. Marietta College – Favicon Tutorial
3. UMass Amherst – Add a Favicon to Your Website
4. San José State University – Spirit Mark Favicon
5. MDN Web Docs – Favicon
6. Washington and Lee University: HTML5, Web Tools, and Favicon

Questions and Answers related to HTML Favicon

+ How do I add a favicon in HTML using the favicon code HTML snippet? >

To add a favicon in HTML, place the following line inside the <head> section of your HTML file:
<link rel="icon" type="image/png" href="favicon.png">
Ensure the favicon file is in the correct directory, and clear the browser cache if the favicon does not update.

+ What is the proper HTML favicon tag to set a custom favicon in my website? >

The proper HTML favicon tag is:
<link rel="icon" type="image/x-icon" href="favicon.ico">
For best compatibility, use both favicon.ico and favicon.png files in your root directory and reference them correctly in the head section.

+ How can I change favicon in HTML and ensure that my HTML favicon is not showing issues? >

To change a favicon, replace the current favicon file and update the <link> tag in the <head>. Clear browser cache or force refresh using Ctrl + F5 to see changes. Also, check the correct file path and format.

+ What are the best practices for favicon setup for website using HTML favicon best practices? >

Use multiple favicon sizes (16×16, 32×32, 48×48, 64×64). Provide PNG and ICO formats for broad compatibility. Store the favicon in the root directory and reference it correctly in the <head> section for all devices and browsers.

+ How do I convert a PNG to favicon and add an HTML favicon PNG to my web page? >

Use an online favicon generator to convert PNG to ICO. Save the output as favicon.ico and place it in the root directory. Add <link rel="icon" type="image/png" href="favicon.png"> in the <head> section.

+ How do I use a favicon generator HTML tool to create a free favicon for my website? >

Visit a favicon generator website, upload an image, and download the generated ICO file. Place it in your website’s root directory and link it in the HTML head using the <link> tag.

+ What is the difference between a favicon ICO HTML file and other favicon formats when adding a favicon in HTML? >

ICO files support multiple resolutions and are widely supported. PNG provides better transparency but may not work on older browsers. WebP and SVG favicons are emerging but not universally supported.

+ How do I insert the favicon code in the head section of my HTML document using HTML favicon code? >

Insert the following in the <head> section:
<link rel="icon" href="favicon.ico" type="image/x-icon">. Ensure the favicon file is correctly placed and accessible.

+ What HTML favicon size is recommended and how can I ensure it displays correctly across devices? >

The recommended favicon sizes are 16×16, 32×32, and 48×48 pixels. Use multiple resolutions in an ICO file or include various sizes in the <head> section for compatibility.

+ How do I follow an HTML favicon tutorial or example to add a favicon in HTML using tools like Dreamweaver? >

Follow online tutorials or Dreamweaver’s built-in tools. Use the <link> tag in the head section, ensuring correct file paths and testing across browsers for proper display.

You can Edit the codes Here

HTML a programming Language MATLAB a programming Language PHP a programming Language C++ a programming Language