Icon Fonts

in Front-end | May 16, 2019
Icon fonts

Hi, developer!

In this article I will tell you how to create and use an icon font with gulp. We use gulp-iconfont and gulp-iconfont-css.

Install plugins and prescribe dependencies

npm install gulp-iconfont@4.0.0 gulp-iconfont-css -g
npm link gulp-iconfont gulp-iconfont-css


var iconfont = require('gulp-iconfont'),
    iconfontCss = require('gulp-iconfont-css'),
    fontName = 'somename';

The fontName parameter is required; this is the name of our font.

Write the task


gulp.task('iconfont', function(){
        path: 'assets/sass/templates/_icons_template.scss',
        fontName: fontName,
        targetPath: '../../sass/_icons.scss',
        fontPath: '../fonts/icons/'
        fontName: fontName

And now more detailed:


Let’s take all the icons (the path is specified relative to gulpfile). Next, inside the task, we prescribe a template for the scss file, which the icons will be used with:

path: 'assets/sass/templates/_icons_template.scss'

The template is available at https://github.com/glivera-team/glivera-team-template/blob/master/assets/sass/templates/_icons_template.scss

fontName: fontName is the name of the font that was previously unveiled.

fontPath: ‘../fonts/icons/’ is the font path.

targetPath is the path to the scss file.

Create a font

We run the task having previously checked all the paths (since you may have a different folder location). If everything went right, the font specified in the fontPath parameter is in the svg format, and the targetPath now contains the scss file that needs to be imported into the sass of your project. It consists of three main parts:

Font connection

@font-face {
  font-family: "somename";
  src: url('../fonts/icons/somename.eot');
  src: url('../fonts/icons/somename.eot?#iefix') format('eot'),
  url('../fonts/icons/somename.woff') format('woff'),
  url('../fonts/icons/somename.ttf') format('truetype'),
  url('../fonts/icons/somename.svg#somename') format('svg');

The general declaration of silent classes, assigning font properties to them

%last_selector {
     &:before {
        font-family: "iconsmoon";
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        font-style: normal;
        font-variant: normal;
        font-weight: normal;
        // speak: none; // only necessary if not using the private unicode range (firstGlyph option)
        text-decoration: none;
        text-transform: none;

Each quiet class has its own icon!

%icon-achievement:before {
%icon-add:before {
%icon-android:before {

Edit the font on iconmoon

In order to make the font easier to use, edit it on iconmoon. In our case, we are loading not individual icons, but the entire font (the same one that was generated by gulp).

After loading, a list of icons will appear. Each icon needs to be processed in a visual editor. Click on the edit icon and then on the icon.

An icon processing window will open. Initiate the grid (if it is turned off) and set the size to 16. The size of the icon is displayed in the upper left corner.

Next, you need to bring the icon to 16×16 size. To do this, you need to “play” with the grid size and the size of the icon. Here is my method (I simply intuitively came to it):

The current size is 17.3, separating the fractional part from it – 3.

Transfer the grid to mode 20 and increase the icon by the number found before (3). Next, we transfer the grid back to 16 – it should be an integer number, which we render to 16.

In the result, we get the 16X16 icon.

Next, we place the icon in the centre and leave one empty set of cells on the sides.

The icon is ready for use. Sometimes it is impossible to make an icon 16×16 due to a violation of the pixel grid. In this case, it is better to make the icon wider.


Download the font from iconmoon, to do this, select all the icons (select all in the set menu) and click generate font:

Next, in the settings, write the name of the font (which we came up with earlier)

After that, download the archive, copy the font files (folder fonts) in the project. Also, save the file selection.json, you may need it to edit the font. Now the font can be used in the project. For example, we want to add the achievement icon to an element (let’s name it .test_selector)

.test_selector {
     @extend %icon-achievement;

The icon is added!

Now, to change its colour or size, just write these properties in the before of the element:

.test_selector {
  @extend %icon-achievement;
  font-size: 20px;
  position: relative;
  &:before {
     color: #acb2ff;
     font-size: 50px;
     position: absolute;
     top: -25px;
     left: -50px;

The icon is added:

That’s all.