often displayed in the browser tab, bookmarks, or address bar. They enhance user experience and brand recognition. Let’s explore HTML Favicons with detailed explanations and five code examples.
The simplest way to add a favicon to your website is by using the
<link>
tag in the
<head>
section of your HTML document.
<!DOCTYPE html>
<html>
<head>
<title>Basic Favicon</title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This website uses a basic favicon.</p>
</body>
</html>
Explanation:
rel="icon"
specifies that this is a favicon.
href="favicon.ico"
points to the favicon file.
type="image/x-icon"
defines the MIME type for the favicon.
Output:
A small icon (favicon.ico) appears in the browser tab for the website.
Modern browsers support PNG format for favicons, allowing for transparent backgrounds and better image quality.
<!DOCTYPE html>
<html>
<head>
<title>PNG Favicon Example</title>
<link rel="icon" href="favicon.png" type="image/png">
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This website uses a PNG favicon.</p>
</body>
</html>
ensures that the browser interprets the favicon correctly.
.ico
files.
Output:
A favicon in
.png
format appears in the browser tab.
To support various devices, include multiple favicon sizes in your HTML.
<!DOCTYPE html>
<html>
<head>
<title>Multiple Favicon Sizes</title>
<link rel="icon" sizes="16x16" href="favicon-16x16.png" type="image/png">
<link rel="icon" sizes="32x32" href="favicon-32x32.png" type="image/png">
<link rel="icon" sizes="48x48" href="favicon-48x48.png" type="image/png">
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This website uses favicons of multiple sizes.</p>
</body>
</html>
sizes
attribute defines the size of the favicon.
Output:
The browser selects the best favicon size based on the user's device.
For iOS devices, Apple uses a specific touch icon displayed on the home screen when a user saves a website.
<!DOCTYPE html>
<html>
<head>
<title>Apple Touch Icon</title>
<link rel="apple-touch-icon" href="apple-touch-icon.png">
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This website supports Apple Touch Icons.</p>
</body>
</html>
specifies the icon for Apple devices.
Output:
When saved to the home screen on an iPhone or iPad, the Apple touch icon is displayed.
Favicons can be dynamically updated using JavaScript for interactive or dynamic experiences.
<!DOCTYPE html>
<html>
<head>
<title>Dynamic Favicon</title>
<link id="dynamic-favicon" rel="icon" href="favicon1.ico" type="image/x-icon">
<script>
document.addEventListener('DOMContentLoaded', () => {
setTimeout(() =& gt; {
const favicon = document.getElementById('dynamic-favicon');
favicon.href = 'favicon2.ico'; // Change to a different favicon
}, 5000); // Change after 5 seconds
});
</script>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This website dynamically updates its favicon.</p>
</body>
</html>
setTimeout
function changes the
href
attribute of the
<link>
tag dynamically.
Output:
The favicon changes from
favicon1.ico
tofavicon2.ico
after 5 seconds.
|
|
|
| |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
| |||||||||||
|
|
|
| |||||||||||
Multiple Sizes
|
|
|
| |||||||||||
|
|
|
| |||||||||||
|
|
|
|
Newsletter
Subscribe to our newsletter for weekly updates and promotions.
Wiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWiki E-Learning
E-LearningComputer Science and EngineeringMathematicsNatural SciencesSocial SciencesBusiness and ManagementHumanitiesHealth and MedicineEngineeringWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWikiCode
Programming LanguagesWeb DevelopmentMobile App DevelopmentData Science and Machine LearningDatabase ManagementDevOps and Cloud ComputingSoftware EngineeringCybersecurityGame DevelopmentWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki News
World NewsPolitics NewsBusiness NewsTechnology NewsHealth NewsScience NewsSports NewsEntertainment NewsEducation NewsWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterWiki Tools
JPEG/PNG Size ReductionPDF Size CompressionPDF Password RemoverSign PDFPower Point to PDFPDF to Power PointJPEG to PDF ConverterPDF to JPEG ConverterWord to PDF ConverterCompany
About usCareersPressCompany
About usCareersPressCompany
About usCareersPressLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesCompany
About usCareersPressCompany
About usCareersPressCompany
About usCareersPressLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesLegal
TermsPrivacyContactAds PoliciesAds Policies