DroidOS
DroidOS

Reputation: 8880

HTML5 with charset = utf-8

My understanding of HTML5 is tht when one has got

<meta http-equiv="content-type" content="text/html;charset=UTF-8" />

in the document header the only characters that need to be converted to entities are > < & ' and ".

  1. Is this correct?
  2. In some basic tests, in Chrome, I have found that I can stick in - for example - a literal < and get away with it. Is that just bad practice or are there more nuances to the entites rule?

Upvotes: 1

Views: 328

Answers (1)

metadings
metadings

Reputation: 3848

The chars < > & are special. They are required to be escaped, so the parser isn't confused and you are able to display them. That's independent of the charset.

Older charsets are not able to display things like ä ö ü ß, so you have to escape them. In UTF-8 you don't need to use the entities, because the encoding supports them native and they don't confuse with XML syntax.

' " are also special but only in attributes, where you want to ensure that a double quotation can be inside of a double quote notated attribute (the like with a single quote char inside of single quotes attribute).
It's like other languages where you can exchange to notation, for example '"' and "'". Now if you are building the value from a database, you don't have to swap quotes around, you can simply escape them using entities.

Upvotes: 2

Related Questions