- Icons Tutorial
- Font Awesome 5 Icons
- Example
- Font Awesome 4 Icons
- Example
- Bootstrap 3 Icons
- Example
- Google Icons
- Example
- 4 Easy Ways to Add Icons In HTML CSS (Simple Examples)
- TLDR – QUICK SLIDES
- TABLE OF CONTENTS
- DOWNLOAD & NOTES
- QUICK NOTES
- EXAMPLE CODE DOWNLOAD
- ADDING HTML CSS ICONS
- METHOD 1) HTML SYMBOLS
- METHOD 2) ICON IMAGES
- 2A) FLAT IMAGE ICON
- 2B) IMAGE FONT SET
- METHOD 3) ICON FONT SET
- METHOD 4) ICON LIBRARIES
- 4A) FONT AWESOME
- 4B) MATERIAL ICONS
- EXTRA BITS & LINKS
- WHICH IS THE BEST METHOD?
- LINKS & REFERENCES
- INFOGRAPHIC CHEAT SHEET
- THE END
- HTML Favicon
- How To Add a Favicon in HTML
- Example
- This is a Heading
- Favicon File Format Support
- Chapter Summary
- HTML Link Tag
Icons Tutorial
To insert an icon, add the name of the icon class to any inline HTML element.
The and elements are widely used to add icons.
All the icons in the icon libraries below, are scalable vector icons that can be customized with CSS (size, color, shadow, etc.)
Font Awesome 5 Icons
To use the Free Font Awesome 5 icons, go to fontawesome.com and sign in to get a code to use in your web pages.
Read more about how to get started with Font Awesome in our Font Awesome 5 chapter.
Note: No downloading or installation is required!
Example
Font Awesome 4 Icons
To use the Font Awesome 4 icons, add the following line inside the section of your HTML page:
Note: No downloading or installation is required!
Example
Bootstrap 3 Icons
To use the Bootstrap 3 glyphicons, add the following line inside the section of your HTML page:
Note: No downloading or installation is required!
Example
Note: Glyphicons are not supported in Bootstrap 4.
For more information about Bootstrap 3 and Glyphicons, visit our Bootstrap 3 Tutorial.
Google Icons
To use the Google icons, add the following line inside the section of your HTML page:
Note: No downloading or installation is required!
Example
cloud
favorite
attachment
computer
traffic
For a complete list of ALL icons (font awesome, bootstrap and google), visit the Icon Reference.
4 Easy Ways to Add Icons In HTML CSS (Simple Examples)
Welcome to a beginner’s tutorial on how to add icons in HTML and CSS. Need to add some icons to your website? Make the contents a little easier to navigate?
There are various ways to add icons in HTML and CSS:
- The easiest way is to use HTML symbols, simply copy-and-paste the respective HTML entity code. For example, ★ represents a star symbol.
- Download icons images from websites such as FlatIcon, and use them as-it-is. E.G.
- Use a set of font icons, such as Webdings. E.G.
ABC
- Lastly, load and use icon libraries such as Font Awesome and Material Icons.
But just how are these done exactly? Let us walk through some examples in this guide – Read on to find out!
ⓘ I have included a zip file with all the example source code at the start of this tutorial, so you don’t have to copy-paste everything… Or if you just want to dive straight in.
TLDR – QUICK SLIDES
TABLE OF CONTENTS
DOWNLOAD & NOTES
Firstly, here is the download link to the example code as promised.
QUICK NOTES
If you spot a bug, feel free to comment below. I try to answer short questions too, but it is one person versus the entire world… If you need answers urgently, please check out my list of websites to get help with programming.
EXAMPLE CODE DOWNLOAD
Click here to download the source code, I have released it under the MIT license, so feel free to build on top of it or use it in your own project.
ADDING HTML CSS ICONS
All right, let us now get into the various methods on how to add icons in HTML and CSS.
METHOD 1) HTML SYMBOLS
★ STAR! ☂ Weather report. ☃ Do you want to build a snowman? ☻ Happy face.
What kind of sorcery is this? Well, these are HTML symbols, and there are a ton of these – Everything from arrows, to symbols, to currencies, to smilies, and more. The best part is that they are baked straight into native HTML, and we don’t need to load 3rd party frameworks for these to work.
The usage is very simple, just define &#NUMBER; and it will “translate” into the respective HTML symbol. I will leave a link to the complete reference in the extras section below. Also, these symbols are treated just like text, we can control the size using font-size , even apply font-weight and text-decoration on it.
METHOD 2) ICON IMAGES
2A) FLAT IMAGE ICON
So call me maybe?
So call me maybe?
This should be “Captain Obvious”, just insert an image icon. Do a search for “free icons” or “free clipart”, they are all over the Internet.
2B) IMAGE FONT SET
Following up on the above image icon method, it is inefficient to use one icon per image. This is the smarter way where we combine all the icons into one single image, but it requires a little bit of CSS to work.
.ico < display: inline-block; width: 32px; height: 30px; background-image: url('icon-set.png'); background-repeat: no-repeat; >.ico-screen < background-position: 0 0; >.ico-phone < background-position: -32px 0; >.ico-pc < background-position: -64px 0; >.ico-tablet < background-position: 0 -31px; >.ico-camera Screen Phone PC Tablet Camera
That’s right. All we are doing here is to use the icon set as the background image, then “map” them using background-position .
METHOD 3) ICON FONT SET
@font-face < font-family: Heydings; src: url(heydings_icons.ttf); >.icon
Fonts usually contain alphabets, but there are some interesting ones that are sets of icons instead – All we have to do is to find these sets of icons, include them using CSS @font-face , then use it just as usual.
I will leave links to free font websites in the extras section below, just do a font search for “icons”, and there will be plenty more. But please do take care that not all fonts are “fully free”… Some are free for personal use, but not for commercial use.
METHOD 4) ICON LIBRARIES
4A) FONT AWESOME
- Load the Font Awesome library from the CDN. There are a lot of versions… If unsure, just load all.min.css which contains everything.
- To insert an icon, use the tag, and give it a CSS class=»fa fa-ICON» – Check out the Font Awesome Gallery for the full list of available icons.
Of course, if you somehow need even more icons, there are also paid plans on Font Awesome.
4B) MATERIAL ICONS
Material Icons is another set of popular free icons, which you may find very familiar… Because it’s by Google. Check out their page on Google Fonts for the full list of icons.
EXTRA BITS & LINKS
That’s all for this tutorial, and here is a small section on some extras and links that may be useful to you.
WHICH IS THE BEST METHOD?
- I personally prefer HTML symbols when it comes to small projects, as it is the most lightweight option. But take note that some symbols will not show up properly on the older browsers, you will not want to use this if backward compatibility is an issue.
- Images are the safest and will always work, but they add to the loading time bloat.
- Font Awesome and Google Material Icons are also pretty safe options but they bloat the loading time as well.
- Loading fonts are kind of meh.
LINKS & REFERENCES
INFOGRAPHIC CHEAT SHEET
THE END
Thank you for reading, and we have come to the end of this guide. I hope that it has helped you with your project, and if you want to share anything with this guide, please feel free to comment below. Good luck and happy coding!
HTML Favicon
A favicon is a small image displayed next to the page title in the browser tab.
How To Add a Favicon in HTML
You can use any image you like as your favicon. You can also create your own favicon on sites like https://www.favicon.cc.
Tip: A favicon is a small image, so it should be a simple image with high contrast.
A favicon image is displayed to the left of the page title in the browser tab, like this:
To add a favicon to your website, either save your favicon image to the root directory of your webserver, or create a folder in the root directory called images, and save your favicon image in this folder. A common name for a favicon image is «favicon.ico».
Next, add a element to your «index.html» file, after the element, like this:
Example
This is a Heading
This is a paragraph.
Now, save the «index.html» file and reload it in your browser. Your browser tab should now display your favicon image to the left of the page title.
Favicon File Format Support
The following table shows the file format support for a favicon image:
Browser | ICO | PNG | GIF | JPEG | SVG |
---|---|---|---|---|---|
Edge | Yes | Yes | Yes | Yes | Yes |
Chrome | Yes | Yes | Yes | Yes | Yes |
Firefox | Yes | Yes | Yes | Yes | Yes |
Opera | Yes | Yes | Yes | Yes | Yes |
Safari | Yes | Yes | Yes | Yes | Yes |
Chapter Summary
HTML Link Tag
For a complete list of all available HTML tags, visit our HTML Tag Reference.