Use Font Awesome Icon as CSS Content
Inject Font Awesome icons into your HTML layouts using CSS pseudo-elements ::before
or ::after
, by giving them the right font-family
, font-weight
, and assigning the icon's Unicode to content
. For instance:
For a solid camera icon:
And in your HTML:
Note: Feel free change the Unicode \f030
to the icon you want. You can find these in the Font Awesome cheatsheet.
Handling interactions
To make your icons interactive, for instance, changing when hovered over, add a specific hover selector:
Position and space
To properly align and space your icons, set the icons' display to inline-block
and define the padding and width:
Sans "<i>" and working with SCSS
Say farewell to <i>
tags for icons, and embrace cleaner markup with CSS classes. And if you're more into SCSS, handling Font Awesome icons is simpler:
In your HTML, just use:
Going the extra mile with icons
Solid or regular? Pick your style
Using the font-weight
property, customize the style of Font Awesome icons. Want regular icons? Go for 400. Prefer them solid? 900 it is.
Keep icons from nudging
To keep your icons in line when content changes, apply a fixed width:
Dialing up your CSS game
Responsive icon sizing
Want your icons to adapt to font size changes seamlessly? Here's how you do it:
Accessible Icons
Making your layout enjoyable for everyone, even for screen reader users, is important:
Splash of color
Dress up your icons by assigning them fit-for-design colors:
Vertical alignment
Avoid misalignment of icons with text. Use the vertical-align
property to keep everything in check:
Was this article helpful?