Servers and browsers communicate with each other by sending bytes of data over the internet. If the server doesn't specify which character encoding format it's using when it sends an HTML file, the browser won't know what character each byte represents. The character encoding declaration specification solves this problem.
A late <meta charset> element (one that is not fully contained in the first 1024 bytes of the document) can significantly affect load performance as the browser will assume one character encoding, and if it discovers later that it made a wrong assumption, it will need to start parsing the HTML again from the beginning.
How to pass this insight
The insight considers the character encoding to be declared if it finds any of the following:
- A
<meta charset>element in the<head>of the document that is completely contained in the first 1024 bytes of the document - A
Content-TypeHTTP response header with acharsetdirective that matches a valid IANA name
Only one of these needs to be set to pass the insight.
Add a <meta charset> element to your HTML
Add a <meta charset> element within the first 1024 bytes of your HTML document. The element must be fully contained within the first 1024 bytes. The best practice is to make the <meta charset> element the first element in the <head> of your document.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
…
Add a Content-Type HTTP response header
Configure your server to add a Content-Type HTTP response header that includes a charset directive.
Content-Type: text/html; charset=UTF-8