A Information to Higher and Sharper UI Icons with Internet Fonts

by | Feb 5, 2024 | Etcetera | 0 comments

Are you using bitmap footage like PNGs and GIFs for icons in your internet web page? If so, you are going to have noticed they can be reasonably hefty in duration, in particular within the match that they’re detailed or a large number of. This now not best will building up the file duration on the other hand can also slow down your internet web page, as it requires a few HTTP requests for every icon.

While CSS sprites offer a workaround, they don’t utterly transparent up the issue of large file sizes. Every other downside of bitmap icons is their lack of flexibility and scalability. Enlarging the ones icons or viewing them on high-resolution presentations, like Apple’s retina display, frequently results in a blurry glance.

If the ones issues sound familiar, it’s time to imagine switching to icon fonts for a additional atmosphere pleasant and scalable solution.

Exploring the Advantages of Icon Fonts

An icon font is in large part a number of icons packaged correct right into a web font, which can also be merely built-in correct right into a internet web page using the @font-face rule. As highlighted by the use of Chris at CSS-Guidelines, icon fonts ship quite a lot of key advantages over standard image icons:

  • Being vector-based, icon fonts are resolution-independent, ensuring sharp and clear display on various computer screen resolutions, in conjunction with high-resolution presentations like retina shows.
  • Icon fonts are scalable, allowing for duration adjustments without any loss in top of the range or clarity.
  • As they’re fonts, you’ll have the ability to merely keep watch over their color, transparency, text-shadow, and duration using CSS.
  • They can be animated with CSS3, together with a dynamic element to your internet web page.
  • Using @font-face for icon fonts is extensively supported, even in older browsers like Internet Explorer 4 (with .eot).
  • Using icon fonts results in fewer HTTP requests and a smaller general file duration.
See also  5 Steps to Create an Exceptional Advertising and marketing Plan [Free Templates]

Proper right here’s a list of a couple of easiest unfastened icon fonts available:

Always ensure that to test and adhere to the licensing words previous to embedding any icon font on your internet web page, as a sign of recognize for the creator’s effort and artwork.

Imposing the @font-face Rule

As mentioned earlier, icon fonts are embedded in web pages using the @font-face rule inside of CSS. This rule allows us to stipulate a brand spanking new font-family. Let’s take the ‘Web Symbols’ font for instance:

 @font-face{ 
 font-family: 'WebSymbolsRegular';
 src: url('fonts/websymbols-regular-webfont.eot');
 src: url('fonts/websymbols-regular-webfont.eot?#iefix') format('embedded-opentype'),
 url('fonts/websymbols-regular-webfont.woff') format('woff'),
 url('fonts/websymbols-regular-webfont.ttf') format('truetype'),
 url('fonts/websymbols-regular-webfont.svg#WebSymbolsRegular') format('svg');
 }

Inside the HTML document, to turn the icons, we simply use characters that correspond to every icon. Slightly than applying the font-family globally, we will objective explicit sides by the use of together with a singular class, like this:

 
  • h
  • i
  • j
  • A
  • I

Then, once more throughout the CSS, we define this new font-family for the class we added:

.icon-font {
    font-family: WebSymbolsRegular;
    font-size: 12pt;
}

Demo @font-face

Integrating Icons with Pseudo-elements

Pseudo-elements offer some other creative method to incorporate icons. Imagine the following HTML markup as our place to begin:

	 
  • Solution
  • Solution All
  • Forward
  • Attachment
  • Image

Inside the CSS, we will fortify this file by the use of using pseudo-elements to turn icons previous to every products:

ul.icon-font.pseudo li:previous to {
    font-family: WebSymbolsRegular;
    margin-right: 5px;
}

ul.icon-font.pseudo li:nth-child(1):previous to {
    content material subject material: "h";
}

ul.icon-font.pseudo li:nth-child(2):previous to {
    content material subject material: "i";
}

ul.icon-font.pseudo li:nth-child(3):previous to {
    content material subject material: "j";
}

ul.icon-font.pseudo li:nth-child(4):previous to {
    content material subject material: "A";
}

ul.icon-font.pseudo li:nth-child(5):previous to {
    content material subject material: "I";
}

Demo Pseudo-element

See also  How to Add a Button to Your Divi Header

Non-public Use Unicode

There’s a scenario where as an alternative of embedding icons into standard characters (A, B, C, D, and so on.), they’re embedded in Unicode Personal Use Spaces to avoid any clashing among characters. The program is used by tools like FontAwesome, where the character codes are included throughout the stylesheet like so:

.icon-glass:previous to {
    content material subject material: "f0c6";
}
 

To immediately insert the icon into HTML, the code f0c6 gained’t render as it’s now not a valid HTML-encoded character.

HTML requires a numerical reference markup to render explicit characters. It requires prefixing the hexadecimal amount (representing the character) with an ampersand (&), a hash (#), and an x. As an example, f0c6 becomes in HTML. In FontAwesome, this code shows a paper clip icon, like this:

paper clippaper clip

Demo Unicode

Font Subsetting

When your icon collection accommodates unused characters, you’ll have the ability to eliminate them by the use of subsetting the font, which moreover reduces the font file duration. A to hand device for that’s FontSquirrel’s @font-face generator.

Seek advice from the generator, add your font, and make a selection An expert. Then make a selection Custom designed Subsetting for additonal possible choices.

font subsetfont subset

As an example, using the Sociolico font for social media icons on our internet web page, we best need the icons for Dribble, Facebook, and Twitter, represented by the use of d, f, and t. The ones characters are entered throughout the Single Characters field as confirmed:

See also  Get a Loose Well being Heart Format Pack for Divi
font subsetfont subset

Now, you’ll have the ability to download the font, which in this case, has been reduced to a trifling 3Kb to 5Kb in duration. Practice that best the characters d, f,, and t will render as icons; any other characters will appear as secure letters.

Final Thought

While this custom excludes the possibility of together with extraordinarily detailed effects like this, it supplies a flexible, scalable, retina-ready solution with minimal file duration. If your design can bear the absence of over the top part, this icon-serving manner could be very in reality helpful.

For those determined to find further, underneath are some helpful references, at the side of our demo and provide code available for download.

See demo
Obtain supply codes

Practice: This publish used to be as soon as first revealed on the 5th of Dec, 2012.

The publish A Information to Higher and Sharper UI Icons with Internet Fonts gave the impression first on Hongkiat.

WordPress Website Development

Supply: https://www.hongkiat.com/blog/webfont-icons/

[ continue ]

WordPress Maintenance Plans | WordPress Hosting

read more

0 Comments

Submit a Comment

DON'T LET YOUR WEBSITE GET DESTROYED BY HACKERS!

Get your FREE copy of our Cyber Security for WordPress® whitepaper.

You'll also get exclusive access to discounts that are only found at the bottom of our WP CyberSec whitepaper.

You have Successfully Subscribed!