The HTML charset attribute
Quick answer
The HTML charset attribute declares the character encoding of the HTML document. It is used on the <meta> element.
Overview
The charset attribute declares the document character encoding. It is used on the <meta> element.
It belongs to the document head: metadata, stylesheet and script loading, encoding and resource hints. These attributes shape how the page is interpreted and how efficiently its resources load.
Syntax
<meta charset="utf-8">
Values
| Value |
|---|
A character-encoding label, always utf-8 for modern documents. |
Best practices
- Declare the character encoding with <meta charset="utf-8"> first in the <head>.
- Load scripts with defer (or as modules) so they do not block parsing.
- Protect third-party resources with integrity and crossorigin (Subresource Integrity).
- Use resource hints like preload deliberately, paired with the right as value.
Frequently asked questions
What does the charset attribute do?
Declares the document character encoding.
Where do head attributes apply?
What is the difference between async and defer?
Which elements use the charset attribute?
It is an element-specific attribute, used on the
<meta> element.