Check 27.03 · Development and accessibility by language

Use UTF-8

Declare and serve UTF-8 everywhere: meta tag, Content-Type header, files, utf8mb4 database, on Apache, Nginx, IIS, Cloudflare, AWS, WordPress or Laravel.

Priority
Important
Difficulty
Intermediate
Estimated time
30 min to 1 day
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

UTF-8 is the character encoding that lets you write every language in the same page: French accents, German ß, Cyrillic, Arabic, Chinese, emoji. The task is to use it end to end, with no link in the chain in another encoding: source files, database, connection between the application and the database, the Content-Type HTTP header and the <meta charset="utf-8"> tag. Once it is done, no character is displayed as é or �, in any language.

Why it matters

A text is just a sequence of bytes. To display it, the browser has to know which encoding to read it with. In order of priority, it relies on the byte order mark (BOM) at the start of the file, the Content-Type HTTP header, then the <meta charset> tag, which must fit entirely within the first 1,024 bytes of the document. Without a declaration, it guesses, and regularly gets it wrong.

The classic error is a single link in another encoding. A latin1 database read by a UTF-8 application, a CSV file exported from Excel in Windows-1252, an old template saved in ISO-8859-1: “é” becomes “é”, or an unknown character becomes “�”. These broken characters then end up in titles, search result snippets, structured data and the pages that generative engine bots fetch.

On a multilingual site, the problem multiplies. A regional encoding such as Windows-1252 covers French but not Polish, Russian or Greek. Only a Unicode encoding, and in practice UTF-8, lets you serve every language with the same technical stack. The W3C recommends always using UTF-8.

What it improves

  • Display No more broken characters in content, titles, meta descriptions and URLs.
  • Snippets in results and AI answers The text picked up by search engines and assistants is readable. A broken title stays broken in the result.
  • Languages added without a rebuild A UTF-8 database and templates accept any new language.
  • Data Emoji and some ideographs, encoded on four bytes, are stored instead of being truncated.
  • Lighthouse audit The warning about a missing or late encoding declaration disappears.
  • Rankings No direct effect; the effect comes through the quality of the text displayed.

How to check

HTTP header and meta tag:

curl -sI https://example.com/ | grep -i '^content-type'
curl -s https://example.com/ | head -c 1024 | grep -i -o '<meta[^>]*charset[^>]*>'

Expected result:

content-type: text/html; charset=UTF-8
<meta charset="utf-8">

If the second command returns nothing, the tag is missing or placed after the 1,024th byte. Also test a CSS file, a JavaScript file, the sitemap and a JSON feed.

Search for broken characters on a page:

curl -s https://example.com/de/ | grep -c -E 'é|è|à |ü|ö|’|“|ç'
curl -s https://example.com/de/ | grep -c $'\xEF\xBF\xBD'

Both counters must be 0. The first command looks for the sequences typical of UTF-8 text read back as Windows-1252; the second, for the replacement character �.

Across the whole site:

  • Screaming Frog: Configuration > Custom > Search, one “Contains” rule per sequence (é, ’, �), then a full crawl.
  • Lighthouse: the best practices audit on the charset declaration checks for the meta tag within the first 1,024 bytes, the Content-Type header or the presence of a BOM.
  • Local files: file -I template.html on macOS, file -i template.html on Linux, shows the detected encoding.
  • MySQL or MariaDB database:
SELECT table_name, table_collation
FROM information_schema.tables
WHERE table_schema = 'my_database';

Every table must be in utf8mb4_….

How to implement

Before you start

Five links to align:

Link Target value
Source files (templates, translations, CSS, JS) Saved as UTF-8, without a BOM for PHP files
Database utf8mb4 character set, utf8mb4_unicode_ci or utf8mb4_0900_ai_ci collation
Application-to-database connection utf8mb4
HTTP header Content-Type: text/html; charset=UTF-8
HTML <meta charset="utf-8"> right after <head>

In the template:

<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>…</title>

The charset tag comes before the <title>, scripts and styles, so it stays within the first 1,024 bytes.

For MySQL, prefer utf8mb4 to utf8: utf8 is an alias of utf8mb3, limited to three bytes per character, which rejects emoji and some rare characters. Back up before any conversion:

ALTER DATABASE my_database CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE articles CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

If the data is already broken (é stored in the database), the conversion does not repair it: first identify the original encoding, re-export with the appropriate mysqldump --default-character-set=…, then re-import as utf8mb4. Test on a copy.

To convert an old file: iconv -f WINDOWS-1252 -t UTF-8 old.html > new.html.

Warning: in PHP, strlen() and substr() count bytes, not characters. Truncating “Été” with substr() can cut a character in half and produce a � in a title or meta description. Use mb_strlen() and mb_substr(), or Str::limit() in Laravel.

Apache

Versions Apache 2.4.

In the virtual host or .htaccess:

AddDefaultCharset UTF-8

<IfModule mod_mime.c>
    AddCharset UTF-8 .css .js .mjs .json .xml .txt .svg .webmanifest
</IfModule>

AddDefaultCharset only adds the character set to text/html and text/plain responses; AddCharset covers the other extensions. A PHP application that sends its own Content-Type keeps control. sudo apachectl configtest && sudo systemctl reload apache2.

Nginx

Versions Nginx 1.24 and later.

In the server block:

charset utf-8;
charset_types text/css text/plain text/xml application/javascript application/json application/xml application/rss+xml image/svg+xml application/manifest+json;

charset_types comes on top of text/html, which is always processed, and replaces the default list. sudo nginx -t && sudo systemctl reload nginx.

LiteSpeed

Versions LiteSpeed Web Server 6.x. OpenLiteSpeed only reads the rewrite rules in .htaccess.

LiteSpeed Web Server reads the AddDefaultCharset and AddCharset directives from a .htaccess file: the block from the Apache section applies as is. Then purge LSCache. On OpenLiteSpeed, these directives are ignored in .htaccess: set the default character set in the WebAdmin console, at virtual host or context level, then restart the server.

IIS

Versions IIS 10 (Windows Server 2016 to 2025).

For static files, declare the character set in the MIME types of web.config:

<configuration>
  <system.webServer>
    <staticContent>
      <remove fileExtension=".html" />
      <mimeMap fileExtension=".html" mimeType="text/html; charset=utf-8" />
      <remove fileExtension=".css" />
      <mimeMap fileExtension=".css" mimeType="text/css; charset=utf-8" />
      <remove fileExtension=".js" />
      <mimeMap fileExtension=".js" mimeType="text/javascript; charset=utf-8" />
    </staticContent>
  </system.webServer>
</configuration>

For ASP.NET, responseEncoding defaults to UTF-8; check that no <globalization> element overrides it.

Cloudflare

Versions Cloudflare dashboard, all plans, November 2026.

Cloudflare passes on the origin's Content-Type header unchanged. So fix it at the origin (previous sections), then purge the cache: Caching > Configuration, “Purge Everything”. Responses generated by Cloudflare itself (custom error pages, Workers) must declare their own Content-Type with charset=utf-8.

AWS

Versions AWS console and AWS CLI v2 (S3, CloudFront, Application Load Balancer), November 2026.

S3 serves the Content-Type stored in each object's metadata. Set it at upload time:

aws s3 sync ./dist s3://my-bucket --exclude "*" --include "*.html" --content-type "text/html; charset=utf-8"
aws s3 sync ./dist s3://my-bucket --exclude "*" --include "*.css" --content-type "text/css; charset=utf-8"
aws s3 sync ./dist s3://my-bucket --exclude "*" --include "*.js" --content-type "text/javascript; charset=utf-8"

CloudFront relays the origin's header: after the fix, create a /* invalidation in the CloudFront console.

Application Load Balancer does not touch the header: the fix is made on the instances' server.

Plesk

Versions Plesk Obsidian 18.0.

Websites & Domains > your domain > Hosting & DNS > Apache & nginx Settings. Paste the charset utf-8; line and the charset_types line from the Nginx section into “Additional nginx directives”, or the Apache block into “Additional directives for HTTP” and “Additional directives for HTTPS”. For PHP, Hosting & DNS > PHP: check that default_charset is set to UTF-8. For the database, open phpMyAdmin from Databases, Operations tab of each table, collation field.

cPanel

Versions cPanel & WHM 134 and later, Jupiter theme.

Paste the block from the Apache section into public_html/.htaccess (File Manager). Software > MultiPHP INI Editor, or Software > Select PHP Version on CloudLinux servers: default_charset = "UTF-8". For the database, open phpMyAdmin from the Databases section.

Shared hosting

With most hosts, Apache already sends UTF-8 for HTML generated by PHP, whose default_charset directive has defaulted to UTF-8 since PHP 5.6. Problems mostly come from old latin1 databases and static files without a character set. Paste the block from the Apache section into .htaccess and check the table collation in phpMyAdmin.

WordPress

Versions WordPress 6.8 to 7.1; utf8mb4 has been supported since WordPress 4.2.

WordPress sends charset=UTF-8 and the <meta charset> tag via bloginfo( 'charset' ) in the theme header. Check in wp-config.php:

define( 'DB_CHARSET', 'utf8mb4' );
define( 'DB_COLLATE', '' );

Recent installations use utf8mb4; an old installation still on utf8 can be converted after a backup. Broken characters that appear after a migration almost always come from an SQL export re-imported with the wrong character set: redo the import with utf8mb4.

Shopify

Versions Shopify admin, all plans, November 2026.

Shopify serves stores in UTF-8, and themes declare <meta charset="utf-8">. The trap is importing: product CSV files must be encoded in UTF-8. In Excel, save in the “CSV UTF-8” format; a standard CSV exported on Windows produces broken accents in the product pages.

Laravel

Versions Laravel 11 to 13. Laravel 10 sets the same values in config/database.php, without an environment variable.

Laravel's HTML responses carry Content-Type: text/html; charset=UTF-8. The MySQL connection is configured in config/database.php:

'mysql' => [
    'charset' => env('DB_CHARSET', 'utf8mb4'),
    'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
],

The default template contains <meta charset="utf-8">. To truncate text, use Str::limit(), which counts characters. On MySQL 5.6 or an old InnoDB configuration, the “Specified key was too long” error during migration comes from the index length in utf8mb4: call Schema::defaultStringLength(191) in AppServiceProvider::boot().

Next.js

Versions Next.js 15 and 16 (App Router).

With the App Router, Next.js always adds the <meta charset="utf-8"> tag, even with no metadata declared, and the server responds in UTF-8. Focus your checks on the JSON translation files (UTF-8 by definition) and the static files in the public/ folder served by another host.

Common mistakes

  • Meta tag too low in the <head>: placed after scripts or long comments, it falls outside the first 1,024 bytes and is no longer taken into account.
  • Contradictory declarations: HTTP header in ISO-8859-1 and meta tag in UTF-8. The header wins.
  • utf8 instead of utf8mb4 in MySQL: emoji and some rare characters are rejected or truncated.
  • CSV exported from Excel without choosing the UTF-8 format: product or translation imports with broken accents.
  • BOM in an included PHP file: three bytes sent before the headers, “headers already sent” error.
  • Byte-level truncation: substr() cuts a multi-byte character and leaves a � in titles.
  • Converting data that is already broken: ALTER TABLE … CONVERT on text containing é keeps é.

Frequently asked questions

Why does my site display é instead of é?

This symptom means text saved in UTF-8 is being read as Windows-1252 or ISO-8859-1. The “é”, encoded on two bytes in UTF-8, is then displayed as two characters. The cause is almost always a link in the chain using another encoding: HTTP header, database connection or file import. Align every link on UTF-8; if the text is already broken in the database, it must be re-imported correctly.

Should you use utf8 or utf8mb4 in MySQL?

Use utf8mb4. In MySQL, utf8 is an alias of utf8mb3, which only stores characters encoded on three bytes at most: emoji and some rare ideographs are then rejected or truncated. Utf8mb4 covers all of Unicode. Choose a utf8mb4_unicode_ci or utf8mb4_0900_ai_ci collation depending on your version, and also set the application's connection to utf8mb4, otherwise the conversion remains incomplete.

Is the meta charset tag enough?

It is enough for the browser if no HTTP header contradicts it and if it fits within the first 1,024 bytes of the document. Send the Content-Type header with charset=UTF-8 anyway: it takes precedence over the tag and covers CSS, JavaScript or JSON files, which have no such tag. In any case, the most common problem is not a missing declaration, but a database or an imported file in another encoding.

Does UTF-8 have an effect on SEO?

Not directly: encoding is not a ranking factor. Its effect comes through what visitors and search engines see. Inconsistent encoding produces titles, descriptions and content with broken characters, which are displayed as they are in search results and in the snippets picked up by AI assistants. On a multilingual site, UTF-8 is also the only simple way to serve every language.

Updated on

Topic checklist (PDF)

And now?

In the “Development and accessibility by language” topic

  1. Set html lang on each page
  2. Mark passages in another language
  3. Use UTF-8
  4. Handle accents and non-Latin scripts
  5. Handle dir=rtl if needed
  6. Check fonts for each language
  7. Test for text overflow
  8. Test performance for each version
  9. Test SSR/SSG for all languages
  10. Test multilingual dynamic routes
  11. Check per-language cache handling
  12. Check the CDN and language variants
  13. Serve the right content at the requested URL
  14. Test without cookies
  15. Test without Accept-Language
  16. Test keyboard navigation of the language switcher