Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For new HTML, use UTF-8: save the document as UTF-8, serve it with Content-Type: text/html; charset=utf-8, and put <meta charset="utf-8"> near the start of the document. These signals must describe the bytes the browser actually receives; changing a label alone cannot repair text saved in another encoding.

What web character encoding does

A document is transmitted as bytes, but people expect to read characters. A character encoding tells software how to interpret those bytes as text. If the bytes and the encoding information disagree, text can appear as mojibake: garbled characters where accented letters, punctuation, or writing from another script should be.

Unicode provides a common character set, and UTF-8 is its standard encoding for the modern web. The WHATWG Encoding Standard calls UTF-8 the most appropriate encoding for interchange of Unicode. The HTML Standard requires UTF-8, using the utf-8 label, for conforming HTML. Legacy encodings remain relevant when supporting existing content, not as a preferred choice for new HTML.

Which encoding should you use?

Use UTF-8 for new pages, templates, and other web content unless a specific legacy system requires a different encoding. UTF-8 covers Unicode characters, including text such as “café — 東京 — العربية — 😀.” Windows-1252 and Shift_JIS are compatibility cases: if an existing page genuinely uses one of them, its bytes and declared encoding must continue to agree until the page is deliberately converted.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not choose an encoding based on how a page looks in one browser or on one machine. The reliable choice is determined by the actual bytes and a consistent declaration, not by a visual guess.

Where to declare UTF-8

For a page delivered over HTTP, send the charset in the response header. Also include an early declaration in the HTML itself. The header is available before the browser parses the body; the in-document declaration remains useful when inspecting the source and in contexts where the HTTP header is unavailable.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

HTTP response header

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

This is the preferred transport-level declaration for an HTML page served over HTTP. Configure the server or application to send it with the response, and ensure that the document bytes are actually UTF-8.

HTML document declaration

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Example</title>
</head>

Place the declaration near the beginning of the document, within its first 512 bytes. A template preamble or other content inserted before it can push the declaration too far down.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Older equivalent syntax

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

This legacy-compatible form is documented as equivalent for text/html. Its content value must include text/html; charset=utf-8. For new pages, the shorter <meta charset="utf-8"> form is simpler.

How browsers determine an encoding

Browsers consider signals that may be available at different stages, including HTTP metadata, a byte-order mark (BOM), and an in-document declaration. The WHATWG encoding-sniffing process determines an encoding and a confidence. Because the signals can conflict, avoid relying on browser fallback or on one declaration to override an incorrect one elsewhere.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

A UTF-8 BOM can identify the encoding and may take precedence during detection, but it is not a substitute for consistent configuration. W3C internationalization guidance recommends a visible declaration in the document so developers, testers, and translation teams can inspect the encoding. The practical setup is to keep the response header, document declaration, and bytes aligned.

How the common approaches compare

Approach Useful role Availability to the browser Main limitation
HTTP Content-Type charset Preferred encoding signal for an HTML response served over HTTP Available before the body is parsed Does not convert bytes that were saved or generated in another encoding
<meta charset="utf-8"> Visible declaration within the HTML document Available when the parser reaches it; place it within the first 512 bytes Cannot correct mismatched bytes, and can conflict with transport metadata
UTF-8 BOM Can help identify UTF-8 during encoding detection Present at the beginning of the byte stream Does not replace a visible document declaration or aligned response settings
Windows-1252 or Shift_JIS Compatibility with existing content genuinely stored in that encoding Depends on the applicable declaration and detection signals Not the conforming encoding choice for new HTML; relabeling without conversion corrupts interpretation

Diagnose garbled or corrupted text

Check the bytes and each point where text is stored, served, imported, or converted. A matching label is necessary, but it cannot make incorrectly encoded bytes correct.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Inspect the HTTP response in browser developer tools or run curl -I https://example.com/ against the page. Confirm that the response includes Content-Type: text/html; charset=utf-8. Replace the example address with your page’s URL.
  2. Check the source file’s actual encoding in an editor that reports it. If the file is not UTF-8, convert it to UTF-8 before changing the header or meta declaration; do not merely relabel the existing bytes.
  3. Verify that <meta charset="utf-8"> occurs within the first 512 bytes and agrees with the response header. Look for content inserted before it by templates or build steps.
  4. Trace other boundaries that can alter text: a BOM, server defaults, framework settings, database connection encoding, CSV import settings, and API transcoding. Align each relevant setting with the actual data encoding.
  5. Test with non-ASCII text such as “café — 東京 — العربية — 😀.” Compare the characters after each storage, transfer, import, and conversion step to locate where they change.

Invalid UTF-8 byte sequences are conformance errors that checkers should report. Treat such a report as evidence to inspect the source bytes and the steps that produced them, rather than as a reason to change the declared charset blindly.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When a legacy encoding must remain

If an existing page truly uses Windows-1252 or Shift_JIS, keep its real encoding and label consistent while it remains in service. A controlled conversion means converting the content bytes to UTF-8 and then updating the declarations and any dependent systems together. Changing only the label can make previously readable characters display incorrectly. The WHATWG standard defines legacy encodings to support existing content, while recommending UTF-8 for new protocols and formats.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.