# Meta Charset: Declare UTF-8 Character Encoding in HTML

> The meta charset tag declares the character encoding of an HTML page. Syntax, HTML standard rules, HTTP header precedence and what it does not do.

The meta charset tag tells the browser which character encoding a page uses. A character encoding maps the bytes of a file to letters and symbols. The HTML standard requires UTF-8, so put ` ` at the top of ` ` and save the file as UTF-8.

## Syntax

```html

Page title

```

The older form with `http-equiv` has the same effect:

```html

```

Use one of the two forms, not both. The [W3C guide to encoding declarations](https://www.w3.org/International/questions/qa-html-encoding-declarations) says that the choice does not matter, and that `UTF-8` and `utf-8` are the same.

## Rules in the HTML standard

The [HTML standard](https://html.spec.whatwg.org/multipage/semantics.html#charset) gives these rules for the declaration:

- The value must be `utf-8`, in uppercase or lowercase letters.
- The document must be encoded in UTF-8, whether it has a declaration or not.
- A document can have only one meta element with a `charset` attribute.
- A document must not have both the `charset` form and the `http-equiv` form.
- The whole element must be in the first 1024 bytes of the document.
- The declaration must not use character references or escapes.

The standard requires a declaration even if all characters are ASCII. The encoding is necessary for non-ASCII text that users type in forms and for URLs that scripts make. There are two exceptions: the file starts with a byte order mark, or the HTTP `Content-Type` header gives the encoding.

In XML documents, the `charset` attribute has no effect. Use the XML declaration there.

## HTTP header and byte order mark

A byte order mark (BOM) is a special byte sequence at the start of a file. The server can also give the encoding in the HTTP `Content-Type` header:

```
Content-Type: text/html; charset=utf-8
```

The W3C guide gives this order of precedence:

| Source of the encoding | Precedence |
|---|---|
| Byte order mark | Highest, wins over the HTTP header |
| HTTP `Content-Type` header | Wins over the meta tag |
| ` ` in the page | Used when the two above do not give an encoding |

If your server sends a charset in the header, make sure that it is the same as the meta tag. The W3C guide also recommends that you keep the meta tag when you use a BOM.

## Search engine support

Google lists both forms in its [supported meta tags](https://developers.google.com/search/docs/crawling-indexing/special-tags). Google says that they define the content type and the character set of the page, and it recommends UTF-8 where possible. In the `http-equiv` form, put quotes around the value of the `content` attribute. Google says that without quotes, the `charset` attribute can be read incorrectly.

Yandex lists the `Content-Type` meta tag in its [meta tag help](https://yandex.com/support/webmaster/en/controlling-robot/metatags). It says that this tag defines the type and encoding of a document.

## What the meta charset tag does not do

- It does not change the bytes of the file. The W3C guide says that you must also save the content as UTF-8. If the declaration and the real encoding are different, text can show as wrong characters.
- It does not set the language of the page. Use the [`lang` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/lang) on ` ` for that.
- It does not override an HTTP header or a byte order mark that gives a different encoding.

For other tags that go in ` `, see the [meta description](/html-tags/meta-description/) and the [meta viewport tag](/html-tags/meta-viewport/).

---

[View the canonical page](https://aichatwatch.com/html-tags/meta-charset/) · [Browse llms.txt](https://aichatwatch.com/llms.txt)
