The charset attribute on a <meta> element declares the document’s character encoding — how bytes become text. In HTML5, the only valid value is a case-insensitive match for utf-8.
Put it early in <head> (within the first 1024 bytes). Pair the page with lang as needed. For form submissions, see accept-charset. The old http-equiv Content-Type pragma is a legacy alternative.
Baseline · Widely available.
On <meta>, charset is not deprecated. Use <meta charset="UTF-8"> on every HTML page.
Obsolete elsewhere.
Do not put charset on <script>, <a>, or <link>. Those uses are obsolete — scripts inherit the document encoding; linked resources should use HTTP Content-Type.
Syntax
HTML Syntax
syntax.html
<meta charset="utf-8">
UTF-8, utf-8, and Utf-8 are all valid — the match is case-insensitive.
Values
Attribute Values
What belongs on modern pages:
Value
Description
Try it
UTF-8
Only valid HTML5 document encoding (ASCII case-insensitive)
meta charset = page; accept-charset = form submit encoding.
How It Works
meta charset decodes the HTML document as UTF-8.
accept-charset documents UTF-8 for the form payload.
Both should be UTF-8 on modern sites.
Server must also expect UTF-8 for names like José.
Edge Cases & Pitfalls
Mojibake almost always means a mismatch between file bytes, HTTP headers, and meta charset.
UTF-8 only
Do not invent other encodings
HTML5 requires utf-8. Save editors and databases as UTF-8 as well.
1024 bytes
Too late in the file
If the declaration sits after the first 1024 bytes, the browser may already have guessed wrong.
obsolete
No charset on script / link / a
Obsolete. Omit it on scripts; use HTTP Content-Type for linked resources.
HTTP
HTTP header can override
A Content-Type: …; charset=… response header takes precedence. Keep server and meta in agreement (UTF-8).
legacy
http-equiv Content-Type
Still works historically, but prefer the shorter <meta charset="UTF-8">.
Compatibility
Browser Support
charset on <meta> is an HTML attribute for document encoding. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
charset
Universally supported on meta. Always use UTF-8. Obsolete on script, a, and link — do not use those forms.
99%Global support (approx.)
Google ChromeAll
Full support
Mozilla FirefoxAll
Full support
Apple SafariAll
Full support
Microsoft EdgeAll
Full support
OperaAll
Full support
Samsung InternetAll modern
Full support
Internet ExplorerAll (use UTF-8)
Supported
meta charsetWidely supported
Bottom line: Put
near the top of every HTML document. Keep server Content-Type charset in sync.
Remember
Key Takeaways
Role: declare how the browser decodes the HTML document.
Value: only UTF-8 (case-insensitive) in HTML5.
Placement: early in <head>, within the first 1024 bytes.
Not on script/link/a — those charset uses are obsolete.
One line: every page needs <meta charset="UTF-8"> near the top of <head>.
Frequently Asked Questions
On a meta element, charset declares the character encoding used to decode the HTML document. In HTML5 the only valid value is UTF-8 (case-insensitive).
In the head, entirely within the first 1024 bytes of the document — ideally as one of the first tags after the opening head.
Yes for HTML documents. The value must be an ASCII case-insensitive match for "utf-8". Save your files as UTF-8 too.
meta charset tells the browser how to read the page. accept-charset on a form states the encoding for submitted form data (also UTF-8 in current HTML).
No. charset on script is obsolete/redundant (scripts inherit the document encoding). charset on a and link is obsolete — use HTTP Content-Type instead.
Use document.characterSet (legacy alias: document.charset) to read the document’s character encoding.