fluxtech-me / frontik

Frontend Development Libraries
https://frontik.js.org
MIT License
10 stars 0 forks source link

Icon Font #19

Closed alexkharatyan closed 1 year ago

alexkharatyan commented 1 year ago

Description

Icon fonts are fonts that contain symbols and glyphs instead of letters or numbers. They’re popular for web designers since you can style them with CSS the same way as regular text. Also, since they’re vectors they’re easily scalable. They’re small, so they load quickly and (bonus!) they’re supported in all browsers.

Usually, icon fonts are only one color and they’re made to follow a grid, like 16px by 16px or 32x32. Any CSS3 effect looks pretty good on a retina display. Icon fonts are super easy to manipulate with CSS3. It’s extremely simple to have a text render a different size for different viewport sizes, but it’s much more difficult to resize images.

It’s also simple to change their color or add a shadow to an icon font's shape. There are a few downfalls to using icon fonts. For one, while you can change their color, you can't use more than one color. Simple, clean, monochromatic designs are popular right now, so that's not a huge issue, but it's still something to be aware of. The other issue is accessibility. While it's pretty simple to make the font icons accessible by putting them in the aria class, it's something that should be remembered. You can get icon fonts from a bunch of different places. You're to use these fonts on your site through the CSS declaration @font-face.

There are popular ones:

  1. Font Awesome It is free and open source. It was originally designed to work with Bootstrap, but it works well with all frameworks. To use Font Awesome icons, you’ll have to use @fontface and put them inside a <span> or <i> element and then assign them classes.
    <span class="fa fa-sun"></span>

    The output will be ☼

Something that's pretty great about Font Awesome is that since it's completely open source, there's a lot of support and constant updating. There are a bunch of different ways that you can get the Font Awesome icons on your site.

  1. IcoMoon IcoMoon offers both free and premium fonts. The free ones are open-source, and the premium fonts are paid. IcoMoon also has a web app that makes it possible for you to generate your own font by choosing only the icons that you want. You can even add your own icons to this app that will be included in the font that's produced through their web app. After you've chosen your icons, IcoMoon will give you an HTML file that shows you exactly how to use your font icon!

Entypo is also included as one of the fonts to choose from on IcoMoon. IcoMoon is a fantastic tool to be able to include only the icons that you want on your site. If you're including fewer icons, your page will load faster.

Pro Tip: Importing your own vectors You can import your own SVG images or SVG fonts to the IcoMoon app. If you import an SVG font, the glyphs in the font will get extracted and imported.

Before generating the font, IcoMoon gives you the ability to edit all information and structure every item:

docs-glyph

Pro Tip: Using Inline SVGs When you download your icon pack from the SVG tab in the IcoMoon app, it comes with a demo.html file that contains SVG icon definitions on top of the document, below and inside SVG's element. These icons can be referenced and used as inline SVGs like so:

<svg class="icon-home">
  <use xlink:href="#icon-home"></use>
</svg>

In the example above, we are embedding symbol definitions in the HTML itself. This works fine in all modern browsers as well as IE 9+.

It is also possible to link to an external SVG containing the definitions:

<svg class="icon-home">
  <use xlink:href="symbol-defs.svg#icon-home"></use>
</svg>

There are also other useful tools:

  1. IconFont
  2. Fontastic
  3. Fontello
  4. Flaticon

Additional

We should be aware of some pros & cons of Icon Fonts

  1. No good fallback - Flash of Unstyled Content (FOUC)

The thing that you have to watch out for is there’s no good fallback. So, if the web font doesn’t load, there’s just nothing there. Anyway, the IcoMoon gives the ability to cover that with glyphs that have supported by all browsers.

  1. Accessibility

Icon fonts are notoriously bad for accessibility and can lead to some frustrating experiences for those who rely on assistive technologies.

  1. Difficult to Style/Position Icon fonts are fonts first and icons second. This means that your icons follow text-based CSS rules, such as font-size, letter-spacing, line-height, etc. This can make positioning icons more difficult and less consistent. Additionally, icon font glyphs are monochromatic, meaning any stylistic changes you make affect the entire glyph.