HTML Charset

Beginner
12 min read
Updated: Nov 2026
6 examples
UTF-8

Definition and Usage

An HTML charset (character encoding) tells the browser how to read the bytes in your .html file as letters, numbers, and symbols. Without a clear declaration, accents, emoji, and other languages can appear as garbage text.

What do you put in the HTML document?

In the <head>, add <meta charset="UTF-8"> as early as possible. In HTML5, UTF-8 is the encoding you should declare.

Why does position matter?

The charset declaration must appear within the first 1024 bytes of the document so the browser can decode the rest of the file correctly—including the title and body text.

Charset vs Unicode vs entities

Unicode is the character catalog; UTF-8 is how those characters are stored as bytes; entities (like &amp;) are escape codes inside markup. See also Unicode and HTML entities.

One required line.

Every modern HTML page should include <meta charset="UTF-8"> near the top of <head>.

Meta tag and file must match.

Declaring UTF-8 is not enough if your editor saved the file as ANSI / Windows-1252. Save as UTF-8 too.

Tutorial vs attribute page.

This page teaches encoding for whole HTML documents. The charset attribute reference covers the attribute itself in more isolation.

HTML Syntax

Declare encoding in <head> (HTML5 form first):

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>My page</title>
</head>
<body>
  <p>Café · こんにちは · Hello 🌍</p>
</body>
</html>
HTML
<!-- Older equivalent (prefer meta charset in new pages) -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

Core HTML Concepts

Ideas that show up on every UTF-8 page:

ConceptRole in HTML
<meta charset>Declares the document encoding inside <head>
UTF-8Required / recommended encoding for HTML5 documents
First 1024 bytesCharset meta must appear early enough for the browser to find it
File encodingHow your editor saves the .html file on disk
langLanguage of the page (pairs with encoding for accessibility)
MojibakeGarbled characters from an encoding mismatch

Common encodings (comparison)

EncodingGood forUse today?
ASCIIBasic English letters and digitsToo limited alone
ISO-8859-1 / Windows-1252Western European text (legacy)Avoid for new sites
UTF-8Almost all languages + emojiYes — default choice

Quick reference

TaskHTML / action
Declare UTF-8 (HTML5)<meta charset="UTF-8">
Legacy form<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Save the fileUTF-8 in your editor (not ANSI)
Language<html lang="en"> — see Language Codes
Markup-safe charactersHTML entities for <, &, etc.

How to Set Charset on an HTML Page

Follow this checklist for every new document:

  1. Start with <!DOCTYPE html> and <html lang="…">.
  2. Open <head> and add <meta charset="UTF-8"> first (or very near the top).
  3. Add <title> and other meta tags after charset.
  4. Save the file as UTF-8 in your editor.
  5. If the site is on a server, prefer a UTF-8 Content-Type header as well.
GoalDo this
Show accents / emojiUTF-8 meta + UTF-8 saved file
Mix languagesUTF-8 page + sensible lang values
Write < in textUse &lt; (encoding alone is not enough)
Fix é / © garbageAlign declaration, file save format, and server header

Live Preview

Sample UTF-8 text as it should appear when charset and file encoding agree. Compare with a typical mojibake look when decoding is wrong.

Toggle to see why declaring and saving UTF-8 matters.

Preview

Café · naïve · こんにちは · Hello 🌍 · €19

<meta charset="UTF-8"> + file saved as UTF-8

HTML Examples

Six patterns: declare charset, accents, emoji, multilingual text, entities with UTF-8, and a full document.

Example 1 — UTF-8 meta Tag

HTML
<head>
  <meta charset="UTF-8">
  <title>UTF-8 page</title>
</head>
Try It Yourself

How It Works

  1. meta charset sits at the top of head.
  2. UTF-8 is the value HTML5 expects.
  3. title and other tags follow after the declaration.
  4. One line guides the browser for the whole document.

Example 2 — Accented Characters

HTML
<h1>Café &amp; naïve</h1>
<p>El niño comió jalapeños. Ça va bien!</p>
Try It Yourself

How It Works

  1. Accented Latin letters need more than plain ASCII.
  2. UTF-8 stores them correctly in the file.
  3. &amp; is still used for a literal ampersand in markup.
  4. Wrong encoding often shows é or question marks instead.

Example 3 — Emoji and Symbols

HTML
<h1>Hello 🌍</h1>
<p>Price: €19 · Rating: ★★★★☆ · Check ✓</p>
Try It Yourself

How It Works

  1. Emoji and € are outside ASCII.
  2. UTF-8 (or entities) is required to show them.
  3. Type them directly in a UTF-8 saved file.
  4. Fonts still affect which glyphs look complete.

Example 4 — Multilingual Page

HTML
<head>
  <meta charset="UTF-8">
</head>
<body>
  <h1>Multilingual UTF-8</h1>
  <p>English: Hello</p>
  <p>Japanese: こんにちは</p>
  <p>Arabic: مرحبا</p>
  <p>Hindi: नमस्ते</p>
</body>
Try It Yourself

How It Works

  1. One UTF-8 page can mix many scripts.
  2. charset makes decoding consistent.
  3. lang on html (or sections) helps accessibility—see Language Codes.
  4. Direction for Arabic may need dir="rtl" where appropriate.

Example 5 — UTF-8 with HTML Entities

HTML
<head>
  <meta charset="UTF-8">
</head>
<body>
  <h1>Entities &amp; UTF-8</h1>
  <p>Copyright: &copy; 2026</p>
  <p>Less than: &lt;tag&gt;</p>
  <p>Numeric ref: &#233; = é</p>
</body>
Try It Yourself

How It Works

  1. UTF-8 lets you type many characters directly.
  2. Entities remain required for <, &, and helpful for some symbols.
  3. charset still belongs in head even when you use entities.
  4. See the HTML Entities hub for more references.

Example 6 — Complete Document

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Global Website</title>
</head>
<body>
  <header><h1>Welcome / Bienvenue / 欢迎</h1></header>
  <main>
    <p>UTF-8 lets one page display text from many languages.</p>
  </main>
</body>
</html>
Try It Yourself

How It Works

  1. DOCTYPE + lang + charset start a solid HTML5 page.
  2. viewport helps mobile layout (separate from encoding).
  3. International text works when UTF-8 is declared and saved.
  4. Try It opens the full editable document.

Edge Cases & Pitfalls

Most charset bugs are declaration/file mismatches or a meta tag placed too late.

mismatch

Declare UTF-8, save as ANSI

Classic mojibake. Always save the .html file as UTF-8 in the editor.

late

Charset after a long title or scripts

Keep meta charset within the first 1024 bytes—usually the first line in head.

legacy

Starting new sites on ISO-8859-1

Use UTF-8 for new HTML5 projects. Legacy encodings limit languages and emoji.

guess

Omitting charset entirely

Browsers may guess wrong. Always declare UTF-8 explicitly.

server

HTTP header disagrees with the page

Prefer aligning the server Content-Type charset with UTF-8 as well.

syntax

Relying on UTF-8 for < and &

Those characters still need entities (&lt;, &amp;) inside HTML text.

Browser Support

meta charset and UTF-8 HTML documents are Baseline and supported everywhere modern browsers run. Always declare encoding early in head.

✓ Baseline · Widely available

UTF-8 in HTML

Character encoding declarations via meta charset work across all current browsers.

100% meta charset
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
HTML charset Universal

Bottom line: Put meta charset="UTF-8" first in head, save the file as UTF-8, and your text stays readable worldwide.

Key Takeaways

  • <meta charset="UTF-8"> belongs near the top of every HTML head.
  • Save the file as UTF-8 so the declaration matches the bytes on disk.
  • UTF-8 covers languages and emoji; ASCII alone does not.
  • Entities still escape < and & inside markup.

One line: Put <meta charset="UTF-8"> first in head, save the file as UTF-8, and your HTML can show the world’s text correctly.

Frequently Asked Questions

Charset (character encoding) tells the browser how to turn the bytes in your HTML file into letters, numbers, and symbols. UTF-8 is the standard for modern HTML pages.
Put <meta charset="UTF-8"> inside <head>, as early as possible (within the first 1024 bytes). HTML5 uses this short form instead of the older http-equiv Content-Type line.
UTF-8 covers virtually all languages and emoji, stays compatible with plain ASCII English, and is the only encoding HTML5 documents should declare.
Mojibake is garbled text (for example é instead of é) from a mismatch between the encoding you declared and how the file was saved, or from a missing charset declaration.
Unicode is the catalog of characters (code points). UTF-8 is one way to store those characters as bytes. HTML pages almost always use UTF-8 to represent Unicode text.
You can type most characters directly in a UTF-8 file. Entities are still needed for characters that are special in HTML syntax, such as < (&lt;) and & (&amp;).

Practice in the editor

Open a Try It demo and confirm accents, emoji, and multilingual text with UTF-8.

Open Try It editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful