HTML Favicon

Beginner
8 min read
Updated: Nov 2026
6 examples
rel=icon

Definition and Usage

A favicon is the small brand icon browsers show in tabs and bookmarks. In HTML you declare it inside <head> with <link rel="icon" href="…">, optionally with sizes and type. Add rel="apple-touch-icon" for iOS home-screen icons.

What is a favicon for in an HTML tutorial?

Help users recognize your site among many tabs. A clear icon reinforces brand and reduces mix-ups.

Where does the link go?

Only in <head>, alongside title, charset, and stylesheets. The icon file itself lives on your server (often /favicon.ico or /images/favicon.png).

When should you add one?

As soon as the site has a public URL. Even a simple 32×32 PNG improves polish. Ship multiple sizes when you care about high-DPI tabs and home-screen installs.

Always in head.

Favicon <link> elements belong in <head>, not in <body>.

Caching is aggressive.

Browsers cache favicons hard. After replacing a file, bump the query string (?v=2) or rename the asset to force a refresh.

Root fallback.

Many browsers still request /favicon.ico automatically. Providing that file avoids 404 noise in logs.

Favicon link Syntax

The basic form:

favicon.html
<link rel="icon" href="/favicon.ico">
HTML
<head>
  <meta charset="UTF-8">
  <title>My Site</title>

  <link rel="icon" href="/favicon.ico" sizes="any">
  <link rel="icon" href="/images/favicon-32.png" type="image/png" sizes="32x32">
  <link rel="icon" href="/images/favicon.svg" type="image/svg+xml">
  <link rel="apple-touch-icon" href="/images/apple-touch-icon.png" sizes="180x180">
</head>

Use absolute-from-root paths (/favicon.ico) so icons resolve on every page. Set type to match the file (image/png, image/svg+xml, image/x-icon).

Core HTML Concepts

Attributes that control which icon loads:

ConceptMeaning
rel="icon"Primary tab/bookmark icon
hrefURL of the icon file
sizesIcon dimensions, e.g. 32x32, or any for scalable formats
typeMIME type hint for the resource
rel="apple-touch-icon"iOS home-screen / touch icon
favicon.icoClassic multi-resolution ICO, often at site root
SVG faviconScalable modern option with PNG/ICO fallback

Common sizes

SizeTypical use
16×16 / 32×32Browser tabs
180×180Apple touch icon
192×192 / 512×512PWA / Android icons (often via web manifest)
SVG (any)Sharp at every density

How to Add a Favicon in HTML

From asset to head declaration.

  1. Export a square icon (PNG, SVG, or ICO) and place it on the server.
  2. In <head>, add <link rel="icon" href="/path/to/icon">.
  3. Set type and sizes when you offer multiple bitmaps.
  4. Add rel="apple-touch-icon" pointing at a ~180×180 PNG.
  5. Optionally keep /favicon.ico at the site root as a fallback.
  6. Hard-refresh or version the URL after replacing icons.
GoalPattern
Classic ICO<link rel="icon" href="/favicon.ico" sizes="any">
PNG tab icon<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32.png">
SVG + fallbackSVG rel=icon plus a PNG/ICO link
iOS home screen<link rel="apple-touch-icon" href="/apple-touch-icon.png">

Live Preview

Switch head snippets to compare icon declarations.

Favicons appear in the browser tab chrome, not in page body content.

Head snippet

Tab would show your /favicon.ico icon.

<link rel="icon" href="/favicon.ico" sizes="any">

HTML Examples

Six patterns: basic ICO, PNG sizes, SVG, apple-touch-icon, multiple icons, and a full page head.

Example 1 — Basic rel=icon

HTML
<head>
  <meta charset="UTF-8">
  <title>My Site</title>
  <link rel="icon" href="/favicon.ico">
</head>
Try It Yourself

How It Works

  1. link rel=icon declares the tab icon.
  2. href points at the icon file on your server.
  3. head only — not visible as page text.
  4. Start here for the simplest setup.

Example 2 — PNG with sizes

HTML
<head>
  <title>PNG favicon</title>
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16.png">
</head>
Try It Yourself

How It Works

  1. type="image/png" matches the file format.
  2. sizes advertises pixel dimensions.
  3. Multiple links let the UA choose the best file.
  4. Export crisp squares from your design tool.

Example 3 — SVG Favicon with Fallback

HTML
<head>
  <title>SVG favicon</title>
  <link rel="icon" href="/images/favicon.svg" type="image/svg+xml">
  <link rel="icon" href="/favicon.ico" sizes="any">
</head>
Try It Yourself

How It Works

  1. SVG stays sharp at any scale.
  2. ICO fallback covers older clients.
  3. Order often lists preferred formats first.
  4. Keep SVG simple for tiny tab rendering.

Example 4 — apple-touch-icon

HTML
<head>
  <title>Touch icon</title>
  <link rel="icon" href="/favicon.ico">
  <link rel="apple-touch-icon" href="/images/apple-touch-icon.png" sizes="180x180">
</head>
Try It Yourself

How It Works

  1. apple-touch-icon is separate from tab icons.
  2. 180×180 PNG is a common target size.
  3. Avoid transparency issues on some iOS versions—use a solid background if needed.
  4. Still include a normal rel=icon for browsers.

Example 5 — Multiple Icons Together

HTML
<head>
  <title>Full icon set</title>
  <link rel="icon" href="/images/favicon.svg" type="image/svg+xml">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32.png">
  <link rel="icon" href="/favicon.ico" sizes="any">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
</head>
Try It Yourself

How It Works

  1. Layer formats for different clients.
  2. sizes disambiguates bitmap choices.
  3. Root ICO satisfies automatic requests.
  4. Production default for most marketing sites.

Example 6 — Complete HTML Page

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Favicon Example</title>
  <link rel="icon" href="/favicon.ico" sizes="any">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32.png">
  <link rel="apple-touch-icon" href="/images/apple-touch-icon.png" sizes="180x180">
</head>
<body>
  <h1>Hello with a favicon</h1>
  <p>Check the browser tab for the site icon.</p>
</body>
</html>
Try It Yourself

How It Works

  1. Icons live in head next to charset and title.
  2. Body shows normal page content only.
  3. Multiple link tags cover tab and touch icons.
  4. Serve real files at those paths for the icons to appear.

Edge Cases & Pitfalls

Missing icons are usually wrong paths, stale cache, or links placed outside head.

path

Relative path breakage

On nested URLs, favicon.ico without a leading / may 404. Prefer root-absolute paths.

cache

Stale favicon cache

Tabs keep old icons. Version the file (?v=3) after updates.

body

link in body

Invalid placement. Move favicon links into head.

type

Wrong MIME type

Server must serve PNG as image/png, SVG as image/svg+xml.

square

Non-square artwork

Browsers may crop oddly. Design on a square canvas.

404

Missing /favicon.ico

Automatic requests still happen. Add a root ICO or accept log noise.

Browser Support

link rel=icon is universal; SVG favicons and apple-touch-icon are widely supported on their target platforms.

✓ Baseline · Widely available

HTML favicons

Every browser that shows tabs can load an icon declared in head.

100% rel=icon
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
Favicon link Universal

Bottom line: Declare rel=icon (and apple-touch-icon) in head, set sizes/type when needed, and keep a root favicon.ico fallback.

Key Takeaways

  • <link rel="icon"> in head sets the tab icon.
  • sizes and type help when you ship several bitmaps.
  • apple-touch-icon covers iOS home-screen installs.
  • Cache bust after replacing icon files.

One line: Put <link rel="icon"> (plus sizes/type and apple-touch-icon as needed) in <head> so tabs and home screens show your brand.

Frequently Asked Questions

A favicon is the small site icon shown in browser tabs, bookmarks, and some history lists. You declare it in the document head with a link element such as rel="icon".
Inside <head>, usually near other metadata. Browsers discover icons early while parsing head.
sizes tells the browser the pixel dimensions of that icon file (for example 32x32). It helps pick the best match when you offer several icons.
rel="apple-touch-icon" points to an image (often 180×180 PNG) used when someone adds your site to an iOS home screen.
Many sites still place /favicon.ico at the site root because browsers and crawlers look there by default. Prefer also declaring link rel=icon for modern PNG or SVG icons.
Yes in modern browsers: <link rel="icon" href="/favicon.svg" type="image/svg+xml">. Keep a PNG or ICO fallback for older clients.

Practice in the editor

Open a Try It demo and wire favicon links in head.

Open Try It editor →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful