# UTF-8

> The UTF-8 is a character encoding that represents every Unicode character with one to four bytes.

## What is UTF-8 encoding?

The encoding that stores Unicode characters in one to four bytes and is compatible with ASCII. It is the standard encoding of the web: pages, APIs and files should use it to avoid garbled text.

- Topic: Internationalization
- Type: format

## Example

Wrong:

```html
<head>
  <title>Café</title>
  <meta charset="utf-8">
</head>
```

Right:

```html
<head>
  <meta charset="utf-8">
  <title>Café</title>
</head>
```

The charset declaration must be within the first 1024 bytes, so it goes first in `<head>`, before any text.

## Common mistakes

- Reading a file in another encoding and getting broken characters.

## Key points

- HTML pages declare `<meta charset="utf-8">` at the very top of `<head>`.
- API responses with text set 'charset=utf-8' in the `Content-Type` header.

## Interview questions

### Why do I see 'Ã©' instead of 'é' on my page?

UTF-8 bytes were decoded as another encoding, often Latin-1. Make the file, the `Content-Type` header and the database all use UTF-8.

### What is the difference between UTF-8 and UTF-16?

Both encode all of Unicode. UTF-8 uses one to four bytes and matches ASCII; UTF-16 uses two or four bytes and is what JavaScript strings use inside.

### Do I need a BOM in UTF-8 files?

No. A byte order mark is not needed for UTF-8 and can break scripts, JSON parsers and concatenated files.

## Related cards

- [Unicode](https://wonderium.dev/web/unicode.md)
- [`<meta>`](https://wonderium.dev/html/meta.md)
- [HTTP Header](https://wonderium.dev/web/http-header.md)

---

- Level: [Web Platform](https://wonderium.dev/web.md)
- HTML version: https://wonderium.dev/web/utf-8
- Last updated: 2026-11-25
