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?

2
  • possible duplicate of Adding HTML entities using CSS content Commented Aug 5, 2012 at 5: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. Commented Aug 5, 2012 at 5:28

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

1 Comment

I wrote 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.
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).

1 Comment

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.
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";  
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.