<tessa harmon />

Software developer at Skookum, co-organizer of Charlotte Front End Developers, Charlotte native, plant eater, gin drinker, polka dot lover, and all around high contrast gal.

CSS Tip: Unicode characters in pseudo-selector content

Today I needed to create a menu element with arrows indicating an expanded or collapsed state. Because I like to avoid images as much as possible, I decided to implement this using unicode characters.

I went over to Copy Paste Character, grabbed the arrows I wanted, and tried inserting them like so:

li:before {
  content: "&#9656;";
}
li.expanded:before {
    content: "&#9662;";
}

This just resulted in the string “&#9656;” being prepended literally to my li.

The secret is that the character is in decimal form and you must convert it to hexadecimal using a handy converter

Then, simply use the hexadecimal formatted code prepended by a \ and you’re golden.

The code becomes:

li:before {
  content: "\25B8";
}
li.expanded:before {
    content: "\25BE";
}