Why Café Turns into Café — Web Fundamentals

A computer keeps letters as numbers, and a dictionary (an encoding) says which number stands for which letter. If saving and reading use different…

Rara orders a banner that says Café. What comes out of the printer is Café. Nobody made a typo. The cause: the computer that saved the text and the computer that read it used different dictionaries.

Letters are kept as numbers

A computer doesn't keep letters, only numbers. A dictionary, called an encoding, says which number stands for which letter. The dictionary the web uses today is called UTF-8. In UTF-8, the letters A to Z need one number each, é needs two, Japanese characters three, an emoji four.

An old dictionary reads one number as one letter. So when UTF-8 text is read with an old dictionary, the two numbers of é are read as two strange letters: é. The letters A to Z have the same numbers in both dictionaries. That is why only letters with marks, such as é, break.

Write the dictionary in the HTML

Name the page's dictionary near the top of <head>, so that the browser doesn't have to guess it:

<meta charset="utf-8">

Save the HTML file as UTF-8 too. Editors today usually do so already.

TL;DR: A computer keeps letters as numbers, and a dictionary (an encoding) says which number stands for which letter. If saving and reading use different dictionaries, the text breaks. Use the UTF-8 dictionary, and write <meta charset="utf-8">.

⚡ Letters are kept as numbers

Meaning: A computer doesn't keep letters, only numbers. A dictionary, called an encoding, says which number stands for which letter. The dictionary the web uses today is called UTF-8: A to Z need one number each, é needs two, Japanese characters three, an emoji four.

⚡ Two different dictionaries

Guess first: in UTF-8, é is kept as two numbers. An old dictionary reads one number as one letter. Café is saved in UTF-8, then read with an old dictionary. What shows?

Café. The old dictionary reads the two numbers of é as two strange letters: é.

Meaning: If saving and reading use different dictionaries, the text breaks. The letters A to Z have the same numbers in both dictionaries. That is why only letters with marks, such as é, break.

⚡ Write the dictionary in the HTML

Write:

<meta charset="utf-8">

Meaning: This line names the page's dictionary, UTF-8, so the browser doesn't have to guess. Put it near the top of <head>. Save the HTML file as UTF-8 too (editors today usually do so already).

What you will learn