How to use escape character in CSS?

Asked

Viewed 378 times

7

I’m trying to insert a special character into :before of my links so that they stay in the following way:

This is the link

The problem is that this character is written in hexadecimal and when I try to put it in content:'➔' instead of displaying the figure displays its hexadecimal value and looks like this:

➔ Esse é o link

Is there any CSS escape character?

1 answer

10


You can simply use the literal character (as noted by Emerson Rocha Luiz, the CSS file - and possibly also HTML - must be saved with the UTF-8 encoding):

a:before { content: "➔"; }

Or the character Unicode code in hexadecimal format, escaped with \. You were using code 10132 in decimal, which is 2794 in hexadecimal:

a:before { content: "\2794"; }

Demo

  • Thanks @bfavaretto, this second example that you suggested became top, is that I did not want to use the literal character rs. How do you get the Unicode character code?

  • 1

    The code you are using in HTML is in decimal, just convert to hexa. There are also tables and character lists with their codes, such as http://www.fileformat.info/info/unicode/char/a.htm

  • 1

    An important addition is to mention file encoding. From what I remember it must be saved in UTF-8 or another that supports the characters, or it will get messy.

  • Thanks @Emersonrochaluiz, updated.

  • No need to quote name in the post Ahahaha. It was just for the same. Nowadays almost everything is UTF8, but I’ve had problems with it and it was complicated until I saw that it was just that.

  • 1

    @Emersonrochaluiz I have this habit of quoting :) I also use everything in UTF-8 a few years ago, but maybe the author of the question doesn’t even use it.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.