[Insights](/insights/) / [Engineering Playbooks](/insights/engineering_playbooks/)

# How to generate an Icon webfont \[automated setup\]

Stop relying on heavy icon libraries — generate your own custom SVG webfont (TTF, WOFF, EOT) in minutes and ship lighter, faster apps. Follow this step-by-step npm guide and start optimizing your icons today.

![Ivan Borshchov](https://static.devforth.io/adminusers/avatars/2026/48db9847-d461-40cd-b344-f2bd7b0d98ca-avatar_ivan@devforth.io_f4ce9df9-8363-4314-9345-28753c76a386.jpeg)

Ivan Borshchov

CEO & System Architect @ Devforth

Oct 24, 2020

![How to generate an Icon webfont \[automated setup\]](https://static.devforth.io/posts/logo-svg/2026/40fb0050-0d32-45e9-93e3-0ed04de6092d-logo-preview-new.svg)

![How to generate an Icon webfont \[automated setup\]](https://static.devforth.io/posts/logo-svg/2026/40fb0050-0d32-45e9-93e3-0ed04de6092d-logo-preview-new.svg)

All well-known web icon sets are shipped in the format of fonts. For example, it is Fontawesome Webfont which ships in woff2 / eot / ttf formats.

Here I will show how to craft such icon Webfont from your custom svg icons. Delivering icons with Webfont allows loading them in the most efficient way and ensure text remains visible during webfont load.

This method works for any npm-based project (e.g. SPAs like React, Vue.js etc). Idea is next:

1.  Collect some SVG files into one folder in the project, for example, exported from Figma or vector graphics editor
2.  Create a npm script that will generate ttf / woff / eot fonts + CSS file which will import and connect them
3.  Then you will need just connect/import CSS file into your app
4.  Every time when you change or add an icon, you need only rerun npm script

Some times ago before 2017 there was a great package called `webfonts-generator` which generated webfont using another library `svgicons2svgfont@5.x.x`. But maintainer stopped work on `webfonts-generator`, when `svgicons2svgfont` got several great updates and fixes (up to `9.x.x`) – most important fix of the messed look of icons after webfont generation. So we've found a new fork `@vusion/webfonts-generator` using [this method](https://hinty.io/brucehardywald/what-should-you-do-when-opensource-package-is-not-maintained-anymore/) and we will explain how to integrate it into your app.

First, install it into your app:

```bash
npm i @vusion/webfonts-generator
```

Now create script `generate_font.js` which will run the generator:

```javascript
const webfontsGenerator = require('@vusion/webfonts-generator');
const fs = require('fs');

fs.readdir('res/font', function(err, items) {
  if (err) {
    console.log('cant read res directory');
  }
  const files = items.filter((i) => i.toLowerCase().endsWith('.svg')).map(
    (i) => 'res/font/'+i);

  webfontsGenerator({
    files: files,
    dest: 'css/icons',
    fontName: 'ptroiconfont',

    // https://github.com/nfroidure/svgicons2svgfont options
    normalize: true,

    cssTemplate: 'res/font/font-css.hbs',
    templateOptions: {
      classPrefix: 'my-icon-',
      baseSelector: '.my-icon'
    },
    types: ['svg', 'ttf', 'woff', 'eot']
  }, function (error) {
    if (error) {
      console.log('Fail!', error);
    } else {
      console.log('Done!');
    }
  })
})
```

Now place icons to `res/font/` folder.

Also, create a file `res/font/font-css.hbs` (This is a template for CSS file which will hold needed styles):

```css
@font-face {
	font-family: "{{fontName}}";
	src: {{{src}}};
	font-weight: normal;
    font-style: normal;
}

{{baseSelector}} {
}

{{baseSelector}}:before {
	font-family: {{fontName}} !important;
	font-style: normal !important;
	font-weight: normal !important;
	font-variant: normal !important;
	text-transform: none !important;
	speak: none;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

{{#each codepoints}}
.{{../classPrefix}}{{@key}}:before {
	content: "\\{{this}}";
}
{{/each}}
```

Add script to `package.json` scripts section:

```javascript
"scripts": {
    "buildfont": "node generate_font.js"
},
```

And run it now and every time when you will change icons:

```bash
npm run buildfont
```

Include generated css file into your app and make sure it loads font files correctly (using Devtools ➡ Network).

To use icons in HTML or your SPA templates (Vue.js, React), add this:

```html
<i class="my-icon my-icon-apply"></i>
```

## [](#troubleshooting)Troubleshooting

### [](#you-dont-see-icon-details-in-fornt)You don't see icon details in fornt

First of all, you might know that underlying `svgicons2svgfont` library does not support stroke at all: [Empty glyph when icon is made of strokes](https://github.com/nfroidure/svgicons2svgfont/issues/60) (Though many browsers also can't render it).

In this case, just import SVG icon in Figma (free) and click Outline stroke:

![Outline stroke](https://static.devforth.io/posts/images/2026/b5579fc9-b415-47ac-885b-a58be61fe314-image_1772102700489.png)

Outline stroke

Then export back from Figma

### [](#paths-are-filled-when-should-not)Paths are filled when should not

Another typical issue.

The reason – not supported reverse directions for paths. You will understand what is it, but the first example:

![Paths are filled in vector font](https://static.devforth.io/posts/images/2026/c71952de-a2ce-4814-80ca-f1ba6e112832-image_1772102729536.png)

Paths are filled in vector font

The cause of this issue: the algorithm to use to determine the inside part of a shape. The algorythom defined by `fill-rule` attribute of path tag inside of svg. The default value which is compatible to most of rendering and converter programs (including webfonts generators) is `nonzero`. However there is another value `evenodd` which rarely supported. You might confirm the issue by opening your SVG file in text editor:

![fill-rule=evenodd](https://static.devforth.io/posts/images/2026/d0077fa6-ba56-44c7-a5aa-14b2bc408b41-image_1772102784633.png)

fill-rule=evenodd

> ⛔ Don't think you can just delete the attribute from SVG source and it should fix it. It **will not work**. The attribute produced by drawing tool (Inkspape, AI, figma, etc) used only help SVG renders and converters to draw pathes (which defined in `d` attribute of `path` tag), but if you just remove attribute, path direction in `d` will be same. Anyway this attribute is ignored by `svgicons2svgfont` at all. See: [It seems that fill-rule="evenodd" does not works correctly](https://github.com/nfroidure/svgicons2svgfont/issues/62)

> 🤷‍♂️ Why it is not working? Tooling which we are using is an open source and created by a great guys who spend a time on creating tools for their need and share them with us for free! Most time they don't receive a revenue but spend a lot of time on creting tools, so the tool itself should be enough to satisfy minimal working flow. So you need just change direction of path by yourself, same like with strokes.

So, let's fix it!

First, install [Fill Rule Editor plugin](https://www.figma.com/community/plugin/771155994770327940/Fill-Rule-Editor) into your free Figma.

Drag and drop or paste SVG icon which looks odd in font and open plugin:

![Fill Rule Editor](https://static.devforth.io/posts/images/2026/b0e6ac84-3442-4af5-b3fa-16a1a8384ad9-image_1772102813500.png)

Fill Rule Editor

Now select pathes (click on gray area of any), we see that in Even-Odd rule it looks right:

![Even-Odd fix 1](https://static.devforth.io/posts/images/2026/ad6280cd-9083-4ac4-941e-9c5bd2dd3173-image_1772102832362.png)

Even-Odd fix 1

Now click on orange area to switch rule, we see it screwed up:

![Even-Odd fix 2](https://static.devforth.io/posts/images/2026/905f0e09-cd2f-4fcd-9ddf-3aa7ba67a681-image_1772102849217.png)

Even-Odd fix 2

This mode is default so supported by most of tools. And now to fix it, click on internal or external outline:

![Even-Odd fix 3](https://static.devforth.io/posts/images/2026/20e8c30e-730b-44bc-8b40-6fb132400752-image_1772102873056.png)

Even-Odd fix 3

> 🤔Reversing path direction tooling exists in Inkskape, AI and other vector graphic software, but this Figma plugin is much simpler and it is free, so we suggest to use it

[

Back to insights

](/insights)

[](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdevforth.io%2Finsights%2Fhow-to-generate-an-icon-webfont-automated-setup)[](https://bsky.app/intent/compose?text=How%20to%20generate%20an%20Icon%20webfont%20%5Bautomated%20setup%5D%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Fhow-to-generate-an-icon-webfont-automated-setup)[](https://x.com/intent/tweet?text=How%20to%20generate%20an%20Icon%20webfont%20%5Bautomated%20setup%5D%20by%20%40ivanborshchov%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Fhow-to-generate-an-icon-webfont-automated-setup)

[

Summarize with AI

](/lab/chat/?prompt=Extract%20main%20points%20from%20post%3A%20https%3A%2F%2Fdevforth.io%2Finsights%2Fhow-to-generate-an-icon-webfont-automated-setup)

Table of Contents

-   [Troubleshooting](#troubleshooting)
    -   [You don't see icon details in fornt](#you-dont-see-icon-details-in-fornt)
    -   [Paths are filled when should not](#paths-are-filled-when-should-not)

[](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdevforth.io%2Finsights%2Fhow-to-generate-an-icon-webfont-automated-setup)[](https://bsky.app/intent/compose?text=How%20to%20generate%20an%20Icon%20webfont%20%5Bautomated%20setup%5D%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Fhow-to-generate-an-icon-webfont-automated-setup)[](https://x.com/intent/tweet?text=How%20to%20generate%20an%20Icon%20webfont%20%5Bautomated%20setup%5D%20by%20%40ivanborshchov%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Fhow-to-generate-an-icon-webfont-automated-setup)
