Feel free to follow along! You may not have all the devices, operating systems or browsers I will be talking about, but you will at least be able to test one or two 😉
To get started create an HTML file with the following basic code:
<!DOCTYPE html> <html> <head> <title>HTML Icons</title> </head> <body> <h1>HTML icons!</h1> </body> </html>
Now you’re ready to go!
Doesn’t that look delicious!
If you take a look at the little icon on your tab right now (these are also known as favicons), it will just give us a boring default icon - nobody wants that!
Note that depending on what browser you’re using, the tabs and default icon might look slightly different. This and most of the other browser screenshots in this article are taken in Google Chrome.
So, let’s add our own one! Simply add this line of code inside your
<link rel="icon" type="image/png" sizes="64x64" href="https://codetheweb.blog/assets/img/posts/html-icons/icon64.png">
type attribute depends on the image we are using. In this case, we are using a
.png file, so we’ll set our
image/png. There are other
types you can use such as
Also, make sure that your icon is either
64px. You need to make sure that the actual image has those dimensions as well as the
sizes attribute - you can resize your images online. Note that other sizes also work, but they are not supported by all browsers. In this case, our image is
64px - I recommend that you use this size because it is the highest resolution out of the three.
If we add our website to the home screen on iOS, it will give us a very ugly and weirdly-sized screenshot by default:
Let’s add our own icon instead! To do so, add this line below your favicon line in your
<link rel="apple-touch-icon" sizes="180x180" href="https://codetheweb.blog/assets/img/posts/html-icons/icon180.png">
As you can see, this is very similar to how we declare our favicon, except that we use
apple-touch-icon as the
rel attribute instead. Make sure that your icon is always
Websites can also be added to the home screen using Google Chrome on Android. Luckily, we don’t need to specify icons just for Android! It will either use the favicon or an
apple-touch-icon if you have one.
In our HTML, we need to define this icon as well as three square icon sizes:
310px. Our rectangular icon needs to be
310px wide by
One important thing though: When making icons for Windows tiles, always have a transparent background.
Here is the HTML - add it below your Safari icon and favicon in the
<meta name="msapplication-square70x70logo" content="https://codetheweb.blog/assets/img/posts/html-icons/icon70.png"> <meta name="msapplication-square150x150logo" content="https://codetheweb.blog/assets/img/posts/html-icons/icon150.png"> <meta name="msapplication-wide310x150logo" content="https://codetheweb.blog/assets/img/posts/html-icons/icon310.png"> <meta name="msapplication-square310x310logo" content="https://codetheweb.blog/assets/img/posts/html-icons/icon-rect-310.png">
These are slightly different to the icon types we’ve discussed so far, because they use
<meta> tags instead of
But if the icons have a transparent background, won’t it look weird? Yes. The reason that they need to have a transparent background is so that Windows can put a color beneath them. Take this tile as an example: Here, the map icon would be the image (with a transparent background), and then Windows would put the pink/purple color beneath it. But how do we tell Windows which color? This is where the
msapplication-TileColor meta tag comes in handy. In this case our waffle icon background hex color is
#2e2e2e. With that in mind, add this line underneath our icons inside the
<meta name="msapplication-TileColor" content="#2e2e2e">
There is this awesome website called Real Favicon Generator which generates favicons, Safari icons, Windows icons and more for you. However, I recommend that you don’t use this until you are quite confident with doing it yourself - otherwise, you will never learn. That said, you can always look it up if you need. So it’s up to you.
Woo! That’s all there is for today. Hopefully, you learned something! If you did, I’d love it if you shared it or signed up to the newsletter to get new posts in your inbox. If you do either of these things, you are awesome and deserve a space-taco if that’s even a thing! 😎 🌮 🚀
I talked about icons for lots of different platforms today, and you don’t have to use all of them - although it’s a good idea. But for a start, you could just try getting used to favicons (the first part).
If you need help, have feedback or wanna say hi 👋 then I’d be stoked if you did so in the comments below.
Next time, I’ll be doing a special post on Quick-reference sites to help you along your coding journey. See you then!
Want more posts like this? Sign up to my newsletter.
I've worked hard on these tutorials and as of now do not make any money on them, so I'd really appreciate if you signed up ;)