13

I'm trying to add an html entity (→ →) using css when a link is hovered with the following css:

#menu1 a:hover:after {
  content: "→";
}

But the output is just → instead of →. The same problem happens when using the decimal (8594) or the entity (rarr).

How do I include an HTML entity with css?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Christopher
  • 2,103
  • 4
  • 22
  • 32
  • possible duplicate of [Adding HTML entities using CSS content](http://stackoverflow.com/questions/190396/adding-html-entities-using-css-content) – sachleen Aug 05 '12 at 05:26
  • I'd consider adding a more meaningful tag. Specifically `entity` as this entity entry isn't meaningful to this question (unless I'm mistaken). Otherwise interesting question I hadn't even considered this through CSS. – Jared Aug 05 '12 at 05:28

3 Answers3

20
#menu1 a:hover:after {
  content:"\2192 ";
}​

Working example: http://jsfiddle.net/wCzUf/
More details - Can you use HTML entities in the CSS “content” property?
List of HTML entities - http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

Community
  • 1
  • 1
Māris Kiseļovs
  • 16,957
  • 5
  • 41
  • 48
  • I wrote [amp-what.com](http://www.amp-what.com) to help sort through the list of entities. On the right, there are button to choose how to display the results: html, css, unicode, etc. – ndp Jul 19 '14 at 14:33
2

That depends on how you include the CSS in your HTML file. Inside an inline stylesheet, the entity should work.

If you have an external stylesheet, you can't use HTML entities. Just put in the character itself ("→"), properly encoded with the .css file's charset. Alternatively, you can use a Unicode escape sequence, in your case "\2192" (the hex value of 8594).

Ruud
  • 3,118
  • 3
  • 39
  • 51
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • 1
    Inside an inline style, entity works in case of `application/xhtml+xml` and doesn't work in case of `text/html` content type. Note that `Content-Type` HTTP header has precedence over `http-equiv` meta tag. – ruvim Jul 18 '15 at 22:22
1

This was already answered before in another question. As per the solution, you need to use escaped Unicode in CSS content property.

#menu1 a:hover:after {
  content: "\002192";  
}
Community
  • 1
  • 1
Uzair Sajid
  • 2,135
  • 2
  • 21
  • 28