Add Responsive Favicon's
Support mobile devices and tablets with a proper favicon
Tue, 01 Jan 2019
Favicons are the icons that you see in a web browsers address bar. Most of the time, the favicon is a slimed downed version of the company’s logo.
favicon example
Creating Favicons
I use a free service called Favicon Generator to make all of my favicons.
- Pick picture that you would like to use as your favicon. Favicon Generator supports JPG’s, PNG’s and SVG’s. The ideal image should be at least 260x260 and maintain a 1:1 aspect ratio. I’ve had good luck with images that fail to meet those requirements.
- Go to Favicon Generator
- Click “Select your Favicon picture”
- If your picture did not meet a 1:1 aspect ratio follow this stop, else you can skip. A window will pop up showing a preview of what it will look like after resizing. If you like it, click “Continue with Picture”.
- You are now shown a preview of your favicons. If you would like to edit the way they look on some devices you can do it here. Once you’re done, scroll to the bottom of the page and click “Generate your Favicons and HTML Code”.
- Once the icons are generated, you can download them from the link provided.
Code for Create React App
- Copy the contents of the folder you downloaded from the previous step to your public folder.
-
Add the following lines of code to your
public/index.html
file.<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"> <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"> <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"> <link rel="manifest" href="/site.webmanifest"> <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5"> <meta name="msapplication-TileColor" content="#da532c"> <meta name="theme-color" content="#ffffff">
- Test it out!
Code for GatsbyJS
- Copy the contents of the folder you downloaded from the previous step to your static folder. If it doesn’t exist, you can create it at the root of your project directory.
- Skip the next three steps if you already have a
html.js
file in your src folder. Copy thedefault-html.js
file from.cache/default-html.js
tosrc/
. - Rename the
default-html.js
tohtml.js
. - If you want to read up on what
html.js
, else continue on - GatsbyJS Html.js -
Add this code to the head section
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" /> <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" /> <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" /> <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" /> <link rel="manifest" href="/site.webmanifest" /> <meta name="msapplication-TileColor" content="#da532c" /> <meta name="theme-color" content="#ffffff" />
- Test it out!