Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unicode via CSS :before

I am using Font Awesome on my webpage and I want to display an icon inside the :before pseudo element.

According to the documentation/cheatsheet, I have to type  to get this font, but it isn't working. I believe that is normal because HTML entities aren't supported in :before.
So I googled a bit and found out, that if you want to display HTML entities in :before, you have to use the escaped hex reference.
So I was searching for the hex reference to  but I found nothing. I believe that is because these are "private use" values, whatever that means.

Is there any way to get it working in :before?

like image 799
Sven Avatar asked Jan 12 '13 15:01

Sven


People also ask

Can you use Unicode in CSS?

To add a Unicode character to the CSS content property, you can do either of the following: Add a Unicode character directly, or; Use the Character's Hexadecimal Unicode Code Point Value.

How do you add icons before CSS?

The CSS3 pseudo-element ::before will place the icon before the link text. In this example, the ID selector for the menu's home link is #menu-link-1 which you can see by right-clicking the link and choosing Inspect in the browser menu. You can also use the ::after pseudo-element to place an icon after the link text.

What is the definition of Unicode in CSS?

The unicode-range CSS descriptor sets the specific range of characters to be used from a font defined by @font-face and made available for use on the current page. If the page doesn't use any character in this range, the font is not downloaded; if it uses at least one, the whole font is downloaded.


1 Answers

In CSS, FontAwesome unicode works only when the correct font family is declared (version 4 or less):

font-family: "FontAwesome"; content: "\f066"; 

Update - Version 5 has different names:

Free

font-family: "Font Awesome 5 Free" 

Pro

font-family: "Font Awesome 5 Pro" 

Brands

font-family: "Font Awesome 5 Brands" 

See this related answer: https://stackoverflow.com/a/48004111/2575724

As per comment (BuddyZ) some more info here https://fontawesome.com/how-to-use/on-the-desktop/setup/getting-started

like image 157
stefan Avatar answered Oct 12 '22 11:10

stefan