<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ahmad Bilal</title>
    <description>The latest articles on DEV Community by Ahmad Bilal (@someab).</description>
    <link>https://dev.to/someab</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1684335%2F0e12780b-a0f3-4e71-81e6-2fe876921de3.jpg</url>
      <title>DEV Community: Ahmad Bilal</title>
      <link>https://dev.to/someab</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/someab"/>
    <language>en</language>
    <item>
      <title>How to add Favicons in Django (2024)</title>
      <dc:creator>Ahmad Bilal</dc:creator>
      <pubDate>Sun, 30 Jun 2024 09:31:17 +0000</pubDate>
      <link>https://dev.to/someab/how-to-add-favicons-in-django-2024-48da</link>
      <guid>https://dev.to/someab/how-to-add-favicons-in-django-2024-48da</guid>
      <description>&lt;h2&gt;
  
  
  What is a favicon?
&lt;/h2&gt;

&lt;p&gt;According to W3C: A favicon is a small image displayed next to the page title in the browser tab &lt;a href="https://www.w3schools.com/html/html_favicon.asp"&gt;More Info &amp;amp; Interactive Tool&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How having a favicon helps?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl5wl6xgsawmfg8mfl4lk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl5wl6xgsawmfg8mfl4lk.png" alt="Example Showing Truncated Tab Titles" width="555" height="105"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A modern real world scenario is suppose you have a lot of tabs open in your browser (firefox, chrome, safari, etc) while you are multi-tasking on a typical day. &lt;/p&gt;

&lt;p&gt;Notice (in the above given example) how the title shown on the tab becomes truncated because of lack of horizontal real estate. Because different websites have favicons that are usually unique to them, it is very easy for an end-user to visually tell them apart from each other. &lt;/p&gt;

&lt;p&gt;Similarly, they also provide important context in other scenarios like&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;While scrolling in 'Browser History'&lt;/li&gt;
&lt;li&gt;While viewing 'Search' results&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Favicons &amp;amp; their different file-formats/methods
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Felhqtdcguavybehm61l9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Felhqtdcguavybehm61l9.png" alt="Source: Wikipedia" width="800" height="305"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the image above, you can see the browser support for the .ico format started pretty early, while the latest addition to the club is the .svg format &lt;a href="https://en.wikipedia.org/wiki/Favicon#Image_file_format_support"&gt;More Info&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Redundant Formats: &lt;strong&gt;.gif, .apng, .jpeg, etc&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short, don't use these formats, unless you have a very specific need for any of them&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;New &amp;amp; Stable Formats: &lt;strong&gt;.ico, .png, .svg &amp;amp; manifest.json&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this tutorial, we will be focusing on these 3 formats/methods &amp;amp; they will be enough for you in 99% of use cases&lt;/p&gt;

&lt;h2&gt;
  
  
  ICO Format
&lt;/h2&gt;

&lt;p&gt;Created in the mid-1980s by Microsoft, this format is the defacto format for favicons. &lt;a href="https://en.wikipedia.org/wiki/ICO_(file_format)"&gt;More Info&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Pros:&lt;/strong&gt; Backward Compatibility with very old browsers. Ability to contain multiple images in one file container&lt;/em&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Can be slightly tricky for some people to edit/manipulate&lt;/em&gt; &lt;/p&gt;
&lt;h2&gt;
  
  
  PNG Format
&lt;/h2&gt;

&lt;p&gt;PNG is, by far, one of the most commonly used image formats out there. &lt;a href="https://en.wikipedia.org/wiki/ICO_(file_format)#PNG_format"&gt;More Info&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Pros:&lt;/strong&gt; It has the Widest Acceptance across Devices &amp;amp; Browsers combined, plus 'Transparency' is supported &lt;br&gt;
&lt;strong&gt;Cons:&lt;/strong&gt;It is a Raster Graphic Format, hence the associated issues &lt;a href="https://youtu.be/-Fs2t6P5AjY?si=JEKFMtnETKzZdeMI"&gt;More Info&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  SVG Format
&lt;/h2&gt;

&lt;p&gt;Because it is Vector based, the quality remains sharp at all screen sizes&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Pros:&lt;/strong&gt;Sharp Rendering, No Blurring, Automatic Variable Size&lt;/em&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Can break backward compatibility on some devices (rare now)&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Manifest (.json) Format
&lt;/h2&gt;

&lt;p&gt;A web application manifest, defined in the Web Application Manifest specification, is a JSON text file that provides information about a web application&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Pros:&lt;/strong&gt;Modularity&lt;/em&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;Cons:&lt;/strong&gt; Can be a bit overwhelming to maintain for beginners&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;So &lt;strong&gt;first place the .ico, .png, .svg, &amp;amp; .json file in your static folder&lt;/strong&gt;(remember to run the Django 'collectstatic' commnd after that), then in your &lt;strong&gt;base.html&lt;/strong&gt; (from which you will extend your other django html templates) add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;{% load static %} {# required to load static content #}
&lt;span class="cp"&gt;&amp;lt;!doctype html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;

{# ico format, Internet Explorer 9 or below compatible #}
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"shortcut icon"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"{% static 'path/to/myicon.ico' %}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

{# ico format, modern with combined sizes #}
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"icon"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"image/x-icon"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"{% static 'path/to/myicon.ico' %}"&lt;/span&gt; &lt;span class="na"&gt;sizes=&lt;/span&gt;&lt;span class="s"&gt;"16x16 32x32 64x64"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

{# png format with different sizes #}
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"icon"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"image/png"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"{% static 'path/to/myicon_x32.png' %}"&lt;/span&gt; &lt;span class="na"&gt;sizes=&lt;/span&gt;&lt;span class="s"&gt;"32x32"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"icon"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"image/png"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"{% static 'path/to/myicon_x192.png' %}"&lt;/span&gt; &lt;span class="na"&gt;sizes=&lt;/span&gt;&lt;span class="s"&gt;"192x192"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

{# png format for Apple touch compatibility #}
{# Size &lt;span class="err"&gt;&amp;amp;&lt;/span&gt; Name of the image file matters #}
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"apple-touch-icon"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"{% static 'path/to/apple-touch-icon.png' %}"&lt;/span&gt; &lt;span class="na"&gt;size=&lt;/span&gt;&lt;span class="s"&gt;"180x180"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

{# svg format, size doesn't matter since its a Vector Graphic Format #} 
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"icon"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"image/svg+xml"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"{% static 'path/to/myicon.svg' %}"&lt;/span&gt; &lt;span class="na"&gt;sizes=&lt;/span&gt;&lt;span class="s"&gt;"any"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

{# manifest format #}
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"manifest"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"{% static 'path/to/manifest.json' %}"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

{# manifest format, alternative #}
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"manifest"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"{% static 'path/to/app.webmanifest' %}"&lt;/span&gt; &lt;span class="na"&gt;crossorigin=&lt;/span&gt;&lt;span class="s"&gt;"use-credentials"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the manifest method, you can just create a .json file with the following contents&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "icons": [
    { 
      "src": "path/to/favicon-192.png",
      "type": "image/png",
      "sizes": "192x192"
    },
    {
      "src": "path/to/favicon-64.png",
      "type": "image/png",
      "sizes": "64x64"
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Closing Comments
&lt;/h2&gt;

&lt;p&gt;As a beginner, just using a single .png format favicon should be enough for you in most situations. Rather, time &amp;amp; effort should be invested into other aspects of your web app other then what favicons to use&lt;/p&gt;

&lt;h2&gt;
  
  
  Extra Reading
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/tags/tag_link.asp"&gt;More Info on the Html '' Tag &amp;amp; its attributes&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.apple.com/design/human-interface-guidelines/app-icons"&gt;Apple Guidelines for Icons&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/Manifest"&gt;More Info on Manifest Format&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learndjango.com/tutorials/django-favicon-tutorial"&gt;More Info on Django config&lt;/a&gt;&lt;/p&gt;

</description>
      <category>django</category>
      <category>favicon</category>
      <category>html</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
