Skip to main content

The HTML charset Attribute

To show a page correctly, the browser must know which character set to use. You set it in the <meta> tag. The HTML specification encourages using UTF-8, which covers almost all characters and symbols in the world.

UTF-8 charset

Setting the character set to UTF-8.

index.html
<meta charset="UTF-8">

The ASCII Character Set

ASCII was the first character encoding standard for the web. It defined 128 Latin characters: the English letters a-z and A-Z, the numbers 0-9, and some special characters like ! $ + - ( ) @ < > . # ?.


The ANSI Character Set

ANSI (Windows-1252) was the first Windows character set. It is identical to ASCII for the first 127 characters, adds special characters from 128 to 159, and is identical to UTF-8 from 160 to 255.

ANSI charset

Setting the character set to Windows-1252.

index.html
<meta charset="Windows-1252">

The ISO-8859-1 Character Set

ISO-8859-1 was the default character set for HTML 4. It supports 256 characters: identical to ASCII for the first 127, unused from 128 to 159, and identical to ANSI and UTF-8 from 160 to 255.

HTML 4 way

Declaring ISO-8859-1 the HTML 4 way.

index.html
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">

HTML 5 way

Declaring ISO-8859-1 the HTML 5 way.

index.html
<meta charset="ISO-8859-1">

The UTF-8 Character Set

UTF-8 is identical to ASCII for values 0 to 127, unused from 128 to 159, identical to ANSI and ISO-8859-1 from 160 to 255, and then continues from 256 up to many thousands of characters. It is declared with <meta charset="UTF-8">.


HTML UTF-8 Characters

UTF-8 includes many character groups, such as Basic Latin, the Latin Extended sets, IPA Extensions, spacing modifiers, diacritical marks, general punctuation, superscripts and subscripts, and Braille.