ArticleslgStudy

science

Character encodings in HTML

Character encodings in HTML is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Character encodings in HTML rather than just read about it. In short: While Hypertext Markup Language (HTML) has been in use since 1991, HTML 4.0 from December 1997 was the first standardized version where international characters were given reasonably complete treatment. When an HTML document includes special characters outside the range of seven-bit ASCII, two goals are worth considering: the information's integrity, and universal browser display.

Key takeaways

  • Character encodings in HTML belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Character encodings in HTML to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Character encodings in HTML from memory before moving on to harder problems.

Reference excerpt

While Hypertext Markup Language (HTML) has been in use since 1991, HTML 4.0 from December 1997 was the first standardized version where international characters were given reasonably complete treatment. When an HTML document includes special characters outside the range of seven-bit ASCII, two goals are worth considering: the information's integrity, and universal browser display. In version 5.3 of the now retired W3C specification, and the current Living Standard published by WHATWG, the only valid encoding is UTF-8.

Specifying the document's character encoding There are two general ways to specify which character encoding is used in the document. First, the web server can include the character encoding or "charset" in the Hypertext Transfer Protocol (HTTP) Content-Type header, which would typically look like this:

This method gives the HTTP server a convenient way to alter document's encoding according to content negotiation; certain HTTP server software can do it, for example Apache with the module mod_charset_lite. Second, a declaration can be included within the document itself. For HTML it is possible to include this information inside the head element near the top of the document:

HTML5 also allows the following syntax to mean exactly the same:

XHTML documents have a third option: to express the character encoding via XML declaration, as follows:

With this second approach, because the character encoding cannot be known until the declaration is parsed, there is a problem knowing which character encoding is used in the document up to and including the declaration itself. If the character encoding is an ASCII extension then the content up to and including the declaration itself should be pure ASCII and this will work correctly. For character encodings that are not ASCII extensions (i.e. not a superset of ASCII), such as UTF-16BE and UTF-16LE, a processor of HTML, such as a web browser, should be able to parse the declaration in some cases through the use of heuristics. Although HTML written to the current Living Standard is required to be UTF-8, an encoding declaration, in any of the above forms, is nonetheless required. It must be a case-insensitive match for the string "utf-8" and the document must, in fact, be in UTF-8.

Encoding detection algorithm An "encoding sniffing algorithm" is defined in the specification to determine the character encoding of the document based on multiple sources of input, including:

Explicit user instruction An explicit meta tag within the first 1024 bytes of the document A byte order mark (BOM) within the first three bytes of the document The HTTP Content-Type or other transport layer information Analysis of the document bytes looking for specific sequences or ranges of byte values, and other tentative detection mechanisms. Characters outside of the printable ASCII range (32 to 126) may appear incorrectly if the document is served with an incorrect character encoding. This presents few problems for English-speaking users, but other languages regularly—in some cases, always—require characters outside that range. In Chinese, Japanese, and Korean (CJK) language environments where there are several different multi-byte encodings in use, auto-detection is also often employed. Finally, browsers usually permit the user to override incorrect charset label manually as well. UTF-8 has been the most common character encoding on the Web since 2008, in part because, as an encoding of Unicode, it allows use of the same encoding for all languages. As of January 2026, UTF-8 is used by 98.9% of web sites surveyed by W3Techs. UTF-16 or UTF-32, other encodings of Unicode, are less widely used because they can be harder to handle in programming languages that assume a byte-oriented ASCII superset encoding, and they are less efficient for text with a high frequency of ASCII characters, which is usually the case for HTML documents. Successful viewing of a page is not necessarily an indication that its encoding is specified correctly. If the page's creator and reader are both assuming some platform-specific character encoding, and the server does not send any identifying information, then the reader will nonetheless see the page as the creator intended, but other readers on different platforms or with different native languages will not see the page as intended.

Permitted encodings Version 5.3 of the retired W3C standard and the current (as of 2026) WHATWG Living Standard both require UTF-8. No other encoding is considered valid. Nonetheless, implementations must use the encoding sniffing algorithm to determine which encoding to apply to the document, in accordance with the robustness principle. The WHATWG Encoding Standard, referenced by both standards, specifies a list of encodings which browsers must support. The HTML standards forbid support of other encodings. The Encoding Standard further stipulates that new formats, new protocols (even when existing formats are used) and authors of new documents are required to use UTF-8 exclusively. Besides UTF-8, the following encodings are explicitly listed in the HTML standard itself, with reference to the Encoding Standard:

The following additional encodings are listed in the Encoding Standard, and support for them is therefore also required:

The following encodings are listed as explicit examples of forbidden encodings:

The standard also defines a "replacement" decoder, which maps all content labelled as certain encodings to the replacement character (�), refusing to process it at all. This is intended to prevent attacks (e.g. cross site scripting) which may exploit a difference between the client and server in what encodings are supported in order to mask malicious content. Although the same security concern applies to ISO-2022-JP and UTF-16, which also allow sequences of ASCII bytes to be interpreted differently, this approach was not seen as feasible for them since they are comparatively more frequently used in deployed content. The following encodings receive this treatment:

Character references

In addition to native character encodings, characters can also be encoded as character references, which can be numeric character references (decimal or hexadecimal) or character entity references. Character entity references are also sometimes referred to as named entities, or HTML entities for HTML. HTML's usage of character references derives from SGML.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Character encodings in HTML

Start with the simplest possible case. Write down what Character encodings in HTML claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Character encodings in HTML before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Character encodings in HTML ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Character encodings in HTML

In research
Character encodings in HTML appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Character encodings in HTML in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Character encodings in HTML is common in secondary-school and first-year university syllabi. It links to neighbouring topics HTML, World Wide Web Consortium standards, so understanding it makes those chapters shorter.
In everyday life
Look for Character encodings in HTML outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Character encodings in HTML” →

How to study Character encodings in HTML in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Character encodings in HTML means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Character encodings in HTML out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Character encodings in HTML in simple terms?

While Hypertext Markup Language (HTML) has been in use since 1991, HTML 4.0 from December 1997 was the first standardized version where international characters were given reasonably complete treatment. When an HTML document includes special characters outside the range of seven-bit ASCII, two goal…

Why does Character encodings in HTML matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Character encodings in HTML?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Character encodings in HTML.

Tags

  • HTML
  • World Wide Web Consortium standards

Keep exploring