visit
Let’s talk about how to add icons to a website from Figma.
Checking the HTML layouts created by layout artists and developers, I often encounter issues with adding icons to a website, which can result in an awkward appearance. Icons are sometimes added as PNG images or replaced with similar ones from Font Awesome. Trust me, navigating this situation can be quite challenging.
<!-- throught img tag -->
<img src="image/icons/icons-refresh.svg" alt="">
<!-- svg code -->
<svg width="23" height="23" viewBox="0 0 23 23" fill="none" xmlns="//www.w3.org/2000/svg">
<path d="m 421.316,734.84 c -325.7222,0 -421.31990625,100.48 -421.31990625,379.19 v 346.8 c 0,278.74 95.59770625,379.22 421.31990625,379.22 H 1192.67 V 1630.99 H 421.316 c -142.597,0 -176.632,-42.15 -176.632,-170.16 v -74.55 H 1186.21 V 1190.21 H 244.684 v -77.78 c 0,-132.899 32.421,-168.539 176.632,-168.539 H 1192.67 V 734.84 H 421.316" fill="white"/>
</svg>
<!-- css -->
<span class="icons-refresh"></span>
<style>
.icon-refresh {
display: inline-block;
position: relative;
height: 16px;
width: 16px;
background-position: center;
background-size: 100%;
background-image: url('image/icons-refresh.svg');
background-repeat: no-repeat;
}
</style>
<a>
tag.
There is another small drawback: we cannot set the icon size through the font-size property (i.e. we do not inherit the font size). Thus, you have to waste your time on setting width and height.
Perhaps the only benefit is that the option is quite simple and saves a little time for small projects.
This can also be referred to as Icon texture.
This option also involves exporting icons to svg or png format but in one file, where all the icons will be of the same size. This is a rather old method, but you need to know about it. I know for sure that VKontakte used this method for a very long time. After the redesign, they abandoned this method in favor of SVG + JS.
For example, social media icons:
Writing the code for the Facebook and Instagram icons:
<span class="icons icons_facebook"></span>
<span class="icons icons_instagram"></span>
<style>
.icons {
display: inline-block;
position: relative;
width: 42px;
height: 42px;
background-image: url('imgs/socials-pack.svg');
background-size: 290px;
background-repeat: no-repeat;
}
.icons_instagram {
background-position: 240px 0;
}
</style>
Here you need to ask your designer where the icons are taken from.
Let’s make a brief excursion away from the main topic: you should always ask your designer about what icons you need, where the images come from, where to get the font, etc. It often happens that icons are taken from some service that allows you to add icons through styles or scripts.
<script src="//code.iconify.design/2/2.1.1/iconify.min.js"></script>
<span class="iconify" data-icon="ci:refresh-01"></span>
Here I’m going to start with the pros:
Perhaps the only drawback is that we connect a third-party service/library, which causes a lot of extra code. However, it’s the little things, especially if the project is on a deadline. This option should be used if there are more than 5 icons in the layout and their colors do not change anywhere.
What we do:
Our code:
<link rel="stylesheet" href="fonts/icomoon/style.css">
<i class="icons-refresh"></i>
<button class="button">Button with icon</button>
<style>
.button:before {
font-family: 'icomoon', sans-serif;
content: '\e90a';
}
</style>
I would like to highlight the following pros:
The cons are: