Content with code points (Entity) or Unicode characters

Asked

Viewed 56 times

4

On the website w3schools has the reference of all characters - specials, symbols, alphanumerics. I did not understand the purpose of having this representation of characters. In the example below the output is the same, only changes the entity.

  1. When should we use CSS entity and/or when using the character?
  2. There’s a difference between writing one way or another?

\00A9 => ©
©     => ©

\0041 => A
A     => A

.copy1:before{content:'\00A9'; margin-right:3px}
.copy2:before{content:'©'; margin-right:3px}
.copy3:before{content:'\0041'; margin-right:3px}
.copy4:before{content:'A'; margin-right:3px}
<div class="copy1"></div>
<div class="copy2"></div>
<div class="copy3"></div>
<div class="copy4"></div>

  • 3

    I can’t say, but one possible advantage is that using entities would be to take advantage of CSS in different documents/HTML pages with different encodings, for example, using a CSS \00C3 that would be Ã, it would work well on both a UTF-8 page and a windows-1252 page... Now something like div:after { content: 'Ã'; } will surely have problems depending on the encoding that saved the document .css

1 answer

4


w3schools seems to have invented this name "css entities", inspired by html entities. That’s a list of code points Unicode, which can be used "escapes" with \. But you can also use the character directly as you showed it. A current specification says it’s worth this:

string token diagram - as inline svg on the spec

So it’s okay to use Unicode characters directly as the value of content, as long as your file is saved and served with the correct encoding - in the UTF-8 case, but characters in other encodings also work if everything is being saved and served correctly.

  • 2

    +1 I really imagined that there was something wrong with this name, personally I always found w3schools to be a bad survey reference (if you are reading this later don’t confuse w3schools != W3.org)

  • @Guilherme Nascimento worse than he was even looking for about it, it was by chance that I got to him. As I use the common characters in content, just opened the question. I will add the correct name to the title.

Browser other questions tagged

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