Table of Contents
1. Prepare Your Favicon File
3. Support for Apple and Other Devices (Optional but Recommended)
4. Test Your Favicon
Home Web Front-end H5 Tutorial How to add a favicon to your website with HTML5

How to add a favicon to your website with HTML5

Aug 27, 2025 am 02:35 AM
html5 favicon

To add a website favicon correctly, first prepare a 32×32 or 64×64 pixel .ico, .png or .svg format icon file and name it favicon.ico, etc., place it in the website root directory or a specified path, and then use <link> to explicitly declare it in the HTML

tag, for example: <link rel="icon" href="/favicon.ico" type="image/x-icon">. It is recommended to support multiple formats and devices at the same time, such as adding PNG different size versions, SVG icons, and Apple touch icons. Finally, clear the cache and test whether it displays normally, to ensure that the path is correct and the file is accessible. The entire process requires attention to the file format, path and compatibility to avoid loading failure.

How to add a favicon to your website with HTML5

Adding a favicon to your website using HTML5 is simple and only requires a few steps. A favicon is the small icon that appears in the browser tab, bookmarks, and on mobile device home screens when someone saves your site. Here's how to do it properly.

1. Prepare Your Favicon File

Start by creating or choosing a square image, ideally 32×32 or 64×64 pixels in size. The most widely supported format is .ico , but modern browsers also accept .png , .svg , and even .webp .

  • Save your file as favicon.ico or favicon.png (or favicon.svg if using SVG).
  • Place it in your website's root directory (eg, /favicon.ico ) so browsers can find it automatically.

Alternatively, you can keep it in a subfolder like /images/favicon.ico , but then you'll need to specify the path in HTML.

2. Add the Favicon Link in the HTML

Even though some browsers will look for favicon.ico in the root by default, it's best practice to explicitly declare it in your HTML using the <link> tag inside the section.

For a standard .ico file:

 <link rel="icon" href="/favicon.ico" type="image/x-icon">

For a PNG favicon:

 <link rel="icon" type="image/png" href="/images/favicon.png">

For an SVG favicon (great for scalability and modern browsers):

 <link rel="icon" type="image/svg xml" href="/images/favicon.svg">

You can also use multiple formats for better compatibility:

 <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png">
<link rel="icon" type="image/svg xml" href="/images/favicon.svg">
<link rel="shortcut icon" href="/favicon.ico">

Note: Using rel="shortcut icon" is a legacy convention but still recommended for backward compatibility.

Apple devices use their own format for favicons when a site is saved to the home screen. To support them:

 <link rel="apple-touch-icon" href="/images/apple-touch-icon.png">

You can also specify sizes:

 <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">

For modern web apps, you might want to use a web app manifest, which can define icons for different devices:

 <link rel="manifest" href="/site.webmanifest">

4. Test Your Favicon

After adding the code:

  • Clear your browser cache or do a hard refresh (Ctrl F5 or Cmd Shift R).
  • Open your site and check the browser tab.
  • Try bookmarking the page or saving it to a mobile home screen to verify it appears correctly.

If the favicon doesn't show up, double-check:

  • The file path is correct.
  • The file is uploaded to the server.
  • The file format is supported.
  • There are no server errors (check browser DevTools Network tab).

Basically, just link your icon in the and make sure the file is accessible. It's not complicated, but small mistakes in path or format can cause it to fail.

The above is the detailed content of How to add a favicon to your website with HTML5. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to add a favicon to your website with HTML5 How to add a favicon to your website with HTML5 Aug 27, 2025 am 02:35 AM

To add a website favicon correctly, first prepare a 32×32 or 64×64 pixel .ico, .png or .svg format icon file and name it favicon.ico, etc., place it in the website root directory or a specified path, and then use a clear statement in the HTML tag. For example: It is recommended to support multiple formats and devices at the same time, such as adding PNG different size versions, SVG icons, and Apple touch icons. Finally, clear the cache and test whether it displays normally, to ensure that the path is correct and the file is accessible. The entire process requires attention to the file format, path and compatibility to avoid loading failure.

What is Forest Protocol (FOREST currency)? How about it? FOREST token economic model and market prospect analysis What is Forest Protocol (FOREST currency)? How about it? FOREST token economic model and market prospect analysis Sep 05, 2025 am 09:09 AM

Catalog ForestProtocol's birth background The innovative technology architecture of interactive tokens (Playable Tokens) CampaignOS: Turn tokens into "playable products" Launchpad and AMM: No curves, no migration, flywheels and fees: Convert usage and revenue into repurchase and destroy CampaignOS's role and value Launchpad and AMM mechanism $FOREST's token economic model Where the value of $FOREST comes from the latest price and market outlook roadmap: From template

What is the placeholder attribute's purpose in HTML5? What is the placeholder attribute's purpose in HTML5? Aug 31, 2025 am 06:58 AM

Theplaceholderattributeprovidesashorthintininputfieldsthatdisappearswhentypingbegins;1.Itisusedinandelementstoshowexampletextlike"Enteryouremail";2.Thehintisdisplayedonlywhenthefieldisemptyandstyledfaintlybybrowsers;3.Itdoesnotreplacetheele

What is the difference between article and section in HTML5? What is the difference between article and section in HTML5? Aug 22, 2025 am 08:29 AM

Useforself-contained,independentlydistributablecontentlikeblogpostsorcomments;2.Useforthematicgroupingsofcontentsuchaspagechaptersorrelatedcontentblocks;3.issemanticallyindependentandreusable,whileorganizescontentwithinalargercontext;4.Choosebasedonm

How does Content Security Policy (CSP) work with HTML5? How does Content Security Policy (CSP) work with HTML5? Aug 30, 2025 am 01:29 AM

CSPenhancesHTML5securitybydefiningtrustedcontentsourcestopreventXSS,clickjacking,andcodeinjection.1.Itrestrictsinlinescriptsandstylesbyblockingthemunless'unsafe-inline',nonces,orhashesareused.2.Itcontrolsexternalresourcesviadirectiveslikescript-src,i

How to use the HTML5 contenteditable attribute How to use the HTML5 contenteditable attribute Aug 23, 2025 am 09:55 AM

ThecontenteditableattributemakesHTMLelementseditablebyaddingcontenteditable="true"toelementslikediv,p,orh1–h6.2.UseJavaScripttoretrievecontentviainnerHTMLforformattedtextortextContentforplaintext.3.Listenforchangesusingtheinputeventtocaptur

How to use the HTML5 template tag How to use the HTML5 template tag Aug 31, 2025 am 08:23 AM

TheHTML5tagstoresinert,reusableHTMLcontentthatcanbeclonedwithJavaScript;itremainsunrendereduntilprogrammaticallyinserted,makingitidealfordynamicallygeneratingelementslikeproductcardswithoutreloadingorhardcoding,anditsupportsadvancedfeatureslikedataat

What is the importance of the alt attribute for images in HTML5? What is the importance of the alt attribute for images in HTML5? Aug 27, 2025 am 02:29 AM

Thealtattributeisessentialforaccessibility,SEO,anduserexperience;1.Itenablesscreenreaderstodescribeimagestovisuallyimpairedusers,ensuringcontentcomprehension;2.Itdisplaysfallbacktextwhenimagesfailtoload,maintainingcontext;3.ItimprovesSEObyhelpingsear

See all articles