Can someone explain this HTML5 code to me?
<meta charset="utf-8">
What is the purpose of this standard and why is it used?
Can someone explain this HTML5 code to me?
<meta charset="utf-8">
What is the purpose of this standard and why is it used?
According to HTML specification , the <meta>
, which should always be in <head>
, "represents several types of metadata that can not be represented with the elements base , < em> link , style or script " free translation . Examples of such metadata are content summary, keywords, search engine prompts, and more.
It can have a content
attribute, and should have a name
, http-equiv
or charset
attribute (and never more than one of those three). In case there is a charset
, it is used to indicate the character encoding format used in the document.
In addition to the 128 basic ASCII characters, a single graphic symbol can be encoded internally in different ways. This applies, for example, to all accented characters in Portuguese. If an HTML file is saved with the Latin 1 encoding (ISO 8859-1, or Windows 1252, which is similar), the ã
character uses only one byte to be stored. In UTF-8, the same character uses 2 bytes, with values different from the byte used in Latin 1. Therefore, if you have the browser display with one encoding and the document is being served with another, the special characters break. / p>
It is important to remember that the <meta>
element should not be the primary method to use to tell the browser which charset to use. The preferred method is for the server to send an HTTP header with this information. The use of <meta>
is a second line of defense against encoding problems - highly recommended, do not leave your HTML without this (see for instance the case mentioned by Miguel Angelo: HTML can be opened directly , and not sent by a server, and in that case there would be no header with indication of the charset used, other than the presence of that HTML element).
This is to indicate the encoding of the html file served.
In this case you are indicating the utf-8
encoding, which is a Unicode-defined pattern:
UTF-8 unicode is a coding format that has a variable character size, which can be from 1 to 4 bytes. The most common characters are mapped to 1-byte codes, others less common, such as most accented characters, have 2 bytes.
This tag is used to show the browser the type of encoding that will be used on your site
meta charset="utf-8"