Why do we need the meta content type tag in HTML head?

后端 未结 3 916
南方客
南方客 2020-12-24 15:10

Why do we need to include the meta content type tag in HTML head like this?


    

        
3条回答
  •  青春惊慌失措
    2020-12-24 15:41

    Whenever the webpage is been opened locally (from disk file system), the text/html part will instruct the webbrowser of which type the document is so that it knows how to parse it and the charset=UTF-8 will instruct the webbrowser which character encoding should be used to display the characters on the webpage so that it won't use the platform default encoding (which may not necessarily be the right one which would thus potentially end up as mojibake).

    Important detail is that this HTML meta header isn't been used when the page is served over the web by HTTP. Instead, the Content-Type one in the HTTP response header will be used. So if this lacks the charset=UTF-8 part while the content is actually decoded as UTF-8, then it will likely go mojibake. You can determine the Content-Type header with for example Firebug, in the Net panel.

    alt text

提交回复
热议问题