简体   繁体   中英

Why is encoding of HTML special characters neccessarry?

I'm sure the answer is trivial (or some historic, legacy reason) but I'm wondering why do we need to encode HTML special characters like €, ä in html if browser can display them as they are. Of course characters like <, >, ', " must be encoded/escaped as they represent starting of html tags.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
  </head>
  <body>
    &lt; <!-- this must be encoded as < represents a start of a html tag-->
    € <!-- why does this symbol needs to be html encoded, as browser with utf-8 charset displays it ok -->  
    파일 선택 <!-- not html encoded, as is -->
    ä -> &#228;
  </body>
</html>

EDIT

Related questions:

why do we need to encode HTML special characters like €, ä in html

You don't, I'm not sure what makes you think you have to. It's just an option, if you prefer writing these in escaped HTML format.

Note that you do need to specify the encoding of your HTML page itself somehow, which you've done with the <meta> tag in your example. That is what determines what these "extended" characters mean, in this case UTF8 characters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM