Fix guides · UX & conversion
How to fix a missing doctype or character encoding
Two lines at the very top of every page tell browsers how to render it and how to read its characters. Without them, layouts break and text can turn into gibberish.
- Time to fix
- 5–10 minutes
- Skill needed
- Copy and paste
- Who notices
- Every visitor
Why it matters
<!DOCTYPE html> tells the browser to use standards mode. Without it, browsers fall back to "quirks mode", which imitates very old browsers and can break modern layouts.
The character encoding (almost always UTF-8) tells the browser how to turn bytes into letters. If it's missing or late, accented letters, symbols and non-Latin scripts can display as garbled characters.
“Specifying a doctype prevents the browser from switching to quirks mode, which can cause your page to render in unexpected ways.”
Before you start
- The doctype must be the very first line of the HTML, before anything else, including comments and whitespace from templates.
- Put <meta charset="utf-8"> first inside <head>; Lighthouse requires it within the first 1024 bytes. A charset in the Content-Type header also counts.
Fix it on your platform
Shopify
- Open layout/theme.liquid in Edit code and check it starts with <!doctype html> and that <meta charset="utf-8"> is the first tag in <head>. Check other layout files too (such as password.liquid).
WordPress
- Check the top of your theme's header.php (or the block theme's output). A plugin or functions.php that prints something before the doctype can also push it down; look for stray output or whitespace.
Webflow Managed by the platform
- Webflow writes the doctype and charset. If they're flagged, check head custom code for content that breaks the <head>, or contact Webflow support.
Wix Managed by the platform
- Wix writes the doctype and charset. If they're flagged, contact Wix support.
Squarespace Managed by the platform
- Squarespace writes the doctype and charset. If they're flagged, check header code injection, or contact Squarespace support.
Next.js Managed by the platform
- Next.js always outputs <!DOCTYPE html> and <meta charset="utf-8">. If they're flagged, check for a custom server or proxy that alters the HTML.
Any other site
- Start every page like this.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
…Check that it's fixed
- View the page source: the first line should be <!DOCTYPE html>, and <meta charset="utf-8"> should be near the top of <head>.
- Re-run your StudioLNC audit: the issue should be gone.
Find every issue like this on your site
Free audit of performance, accessibility, SEO and security, with fixes for your platform.