Skip to content

How to declare the character encoding

Best practices1 min readFixes check charset

Declaring UTF-8 in the first 1024 bytes stops browsers from guessing and prevents garbled characters.

Step by step, with screenshots: HTML validation errors: which ones matter and which are noise →

Check your own site

Runs this check and the other 186, free, in about 45 seconds.

What a passing site looks like

  • Character encoding is declared earlywarning · −1 ptseffort S

Character encoding is not declared early enough

Why it matters. Browsers need to know the encoding before they read the text. When it is missing or declared late, accented letters such as č, ć and š can appear as garbage and the page re-renders.

How to fix it.
  1. Put <meta charset="utf-8"> as the first element inside <head>, within the first 1024 bytes of the document.
  2. Or send it in the response header: Content-Type: text/html; charset=utf-8.

Filed under Best practices. Copy is generated from the same catalogue that scores every report, so what you read here is what the report says.