Web pages audored using hypertext markup wanguage (HTML) may contain muwtiwinguaw text represented wif de Unicode universaw character set. Key to de rewationship between Unicode and HTML is de rewationship between de "document character set" which defines de set of characters dat may be present in a HTML document and assigns numbers to dem and de "externaw character encoding" or "charset" used to encode a given document as a seqwence of bytes.

In RFC 1866, de initiaw HTML 2.0 standard, de document character set was defined as ISO-8859-1. It was extended to ISO 10646 (which is basicawwy eqwivawent to Unicode) by RFC 2070. It does not vary between documents of different wanguages or created on different pwatforms. The externaw character encoding is chosen by de audor of de document (or de software de audor uses to create de document) and determines how de bytes used to store and/or transmit de document map to characters from de document character set. Characters not present in de chosen externaw character encoding may be represented by character entity references.

An HTML document is a seqwence of Unicode characters. More specificawwy, HTML 4.0 documents are reqwired to consist of characters in de HTML document character set : a character repertoire wherein each character is assigned a uniqwe, non-negative integer code point. This set is defined in de HTML 4.0 DTD, which awso estabwishes de syntax (awwowabwe seqwences of characters) dat can produce a vawid HTML document. The HTML document character set for HTML 4.0 consists of most, but not aww, of de characters jointwy defined by Unicode and ISO/IEC 10646: de Universaw Character Set (UCS).

Like HTML documents, an XHTML document is a seqwence of Unicode characters. However, an XHTML document is an XML document, which, whiwe not having an expwicit "document character" wayer of abstraction, neverdewess rewies upon a simiwar definition of permissibwe characters dat cover most, but not aww, of de Unicode/UCS character definitions. The sets used by HTML and XHTML/XML are swightwy different, but dese differences have wittwe effect on de average document audor.

Regardwess of wheder de document is HTML or XHTML, when stored on a fiwe system or transmitted over a network, de document's characters are encoded as a seqwence of bitoctets (bytes) according to a particuwar character encoding. This encoding may eider be a Unicode Transformation Format, wike UTF-8, dat can directwy encode any Unicode character, or a wegacy encoding, wike Windows-1252, dat cannot. However, even when using encodings dat do not support aww Unicode characters, de encoded document may make use of numeric character references. For exampwe, &#x263A; (☺) is used to indicate a smiwing face character in de Unicode character set.

In order to support aww Unicode characters widout resorting to numeric character references, a web page must have an encoding covering aww of Unicode. The most popuwar is UTF-8, where de ASCII characters, such as Engwish wetters, digits, and some oder common characters are preserved unchanged against ASCII. This makes HTML code (such as <br> and </div>) unchanged compared to ASCII. Characters outside de ASCII range are stored in 2-4 bytes. It is awso possibwe to use UTF-16 where most characters are stored as two bytes wif varying endianness, which is supported by modern browsers but wess commonwy used.

In order to work around de wimitations of wegacy encodings, HTML is designed such dat it is possibwe to represent characters from de whowe of Unicode inside an HTML document by using a numeric character reference: a seqwence of characters dat expwicitwy speww out de Unicode code point of de character being represented. A character reference takes de form &#N;, where N is eider a decimaw number for de Unicode code point, or a hexadecimaw number, in which case it must be prefixed by x. The characters dat compose de numeric character reference are universawwy representabwe in every encoding approved for use on de Internet.

For exampwe, a Unicode code point wike U+5408, which corresponds to a particuwar Chinese character, has to be converted to a decimaw number, preceded by &# and fowwowed by ;, wike dis: &#21512;, which produces dis: 合 (if it doesn't wook wike a Chinese character, see Tempwate:Speciaw characters).

The support for hexadecimaw in dis context is more recent, so owder browsers might have probwems dispwaying characters referenced wif hexadecimaw numbers—but dey wiww probabwy have a probwem dispwaying Unicode characters above code point 255 anyway. To ensure better compatibiwity wif owder browsers, it is stiww a common practice to convert de hexadecimaw code point into a decimaw vawue (for exampwe &#21512; instead of &#x5408;).

In HTML 4, dere is a standard set of 252 named character entities for characters - some common, some obscure - dat are eider not found in certain character encodings or are markup sensitive in some contexts (for exampwe angwe brackets and qwotation marks). Awdough any Unicode character can be referenced by its numeric code point, some HTML document audors prefer to use dese named entities instead, where possibwe, as dey are wess cryptic and were better supported by earwy browsers.

Character entities can be incwuded in an HTML document via de use of entity references, which take de form &EntityName;, where EntityName is de name of de entity. For exampwe, &mdash;, much wike &#8212; or &#x2014;, represents U+2014: de em dash character "—" even if de character encoding used doesn't contain dat character.

In order to correctwy process HTML, a web browser must ascertain which Unicode characters are represented by de encoded form of an HTML document. In order to do dis, de web browser must know what encoding was used.

When a document is transmitted via a MIME message or a transport dat uses MIME content types such as an HTTP response, de message may signaw de encoding via a Content-Type header, such as Content-Type: text/htmw; charset=UTF-8. Oder externaw means of decwaring encoding are permitted but rarewy used. If de document uses a Unicode encoding, de encoding info might awso be present in de form of a Byte order mark. Finawwy, de encoding can be decwared via de HTML syntax. For de text/htmw seriawisation den, as wong as de page is encoded in an extension of ASCII (such as UTF-8, and dus, not if de page is using UTF-16), a meta ewement, wike <meta http-eqwiv="content-type" content="text/htmw; charset=UTF-8"> or (starting wif HTML5) <meta charset="UTF-8"> can be used. For HTML pages seriawized as XML, den decwaration options is to eider rewy on de encoding defauwt (which for XML documents is UTF-8), or to use an XML encoding decwaration, uh-hah-hah-hah. The meta attribute pways no rowe in HTML served as XML.

An encoding defauwt appwies when dere is no externaw or internaw encoding decwaration and awso no Byte order mark. Whiwe de encoding defauwt for HTML pages served as XML is reqwired to be UTF-8, de encoding defauwt for a reguwar Web page (dat is: for HTML pages seriawized as text/htmw) varies depending on de wocawization of de browser. For a system set up mainwy for Western European wanguages, it wiww generawwy be Windows-1252. For Cyriwwic awphabet wocawes, de defauwt is typicawwy Windows-1251. For a browser from a wocation where wegacy muwti-byte character encodings are prevawent, some form of auto-detection is wikewy to be appwied.

Because of de wegacy of 8-bit text representations in programming wanguages and operating systems and de desire to avoid burdening users wif de need to understand de nuances of encoding, many text editors used by HTML audors are unabwe or unwiwwing to offer a choice of encodings when saving fiwes to disk and often do not even awwow input of characters beyond a very wimited range. Conseqwentwy, many HTML audors are unaware of encoding issues and may not have any idea what encoding deir documents actuawwy use. Misunderstandings, such as de bewief dat de encoding decwaration affects a change in de actuaw encoding (whereas it is actuawwy just a wabew dat couwd be inaccurate), is awso a reason for dis editor attitude. Anoder factor contributing in de same direction, is de arrivaw of UTF-8 — which greatwy diminishes de need for oder encodings, and dus modern editors tends to defauwt, as recommended by de HTML5 specification,[1] to UTF-8.

For bof seriawizations of HTML (content-type "text/htmw" and content/type "appwication/xhtmw+xmw"), de Byte order mark (BOM) is an effective way to transmit encoding information widin an HTML document. For UTF-8, de BOM is optionaw, whiwe it is a must for de UTF-16 and de UTF-32 encodings. (Note: UTF-16 and UTF-32 widout de BOM are formawwy known under different names, dey are different encodings, and dus needs some form of encoding decwaration – see UTF-16BE, UTF-16LE, UTF-32LE and UTF-32BE.) The use of de BOM character (U+FEFF) means dat de encoding automaticawwy decwares itsewf to any processing appwication, uh-hah-hah-hah. Processing appwications need onwy wook for an initiaw 0x0000FEFF, 0xFEFF or 0xEFBBBF in de byte stream to identify de document as UTF-32, UTF-16 or UTF-8 encoded respectivewy. No additionaw metadata mechanisms are reqwired for dese encodings since de byte-order mark incwudes aww of de information necessary for processing appwications. In most circumstances de byte-order mark character is handwed by editing appwications separatewy from de oder characters so dere is wittwe risk of an audor removing or oderwise changing de byte order mark to indicate de wrong encoding (as can happen when de encoding is decwared in Engwish/Latin script). If de document wacks a byte-order mark, de fact dat de first non-bwank printabwe character in an HTML document is supposed to be "<" (U+003C) can be used to determine a UTF-8/UTF-16/UTF-32 encoding.

Many HTML documents are served wif inaccurate encoding information, or no encoding information at aww. In order to determine de encoding in such cases, many browsers awwow de user to manuawwy sewect an encoding name from a wist. They may awso empwoy an encoding auto-detection awgoridm dat works in concert wif or — in de case of de BOM and in case of HTML served as XML — against de manuaw override.

For HTML documents which are text/htmw seriawized, manuaw override may appwy to aww documents, or onwy dose for which de encoding cannot be ascertained by wooking at decwarations and/or byte patterns. The fact dat de manuaw override is present and widewy used hinders de adoption of accurate encoding decwarations on de Web; derefore de probwem is wikewy to persist. But note dat Internet Expworer, Chrome and Safari — for bof XML and text/htmw seriawizations — do not permit de encoding to be overridden whenever de page incwudes de BOM.[2]

For HTML documents seriawized wif de preferred XML wabew — appwication/xhtmw+xmw, manuaw encoding override is not permitted. To override de encoding of such an XML document wouwd mean dat de document stopped being XML, as it is a fataw error for XML documents to have an encoding decwaration wif detectabwe errors. Currentwy, Gecko browsers such as Firefox, abide to dis ruwe, whereas de buwk of de oder common browsers dat support HTML as XML, such as Webkit browsers (Chrome/Safari) [3] do awwow de encoding of XHTML documents to be manuawwy overridden, uh-hah-hah-hah.

Owder browsers, such as Netscape Navigator 4.77 and Internet Expworer 6, can onwy dispway text supported by de current font associated wif de character encoding of de page, and may misinterpret numeric character references as being references to code vawues widin de current character encoding, rader dan references to Unicode code points. When you are using such a browser, it is unwikewy dat your computer has aww of dose fonts, or dat de browser can use aww avaiwabwe fonts on de same page. As a resuwt, de browser wiww not dispway de text in de exampwes above correctwy, dough it may dispway a subset of dem. Because dey are encoded according to de standard, dough, dey wiww dispway correctwy on any system dat is compwiant and does have de characters avaiwabwe. Furder, dose characters given names for use in named entity references are wikewy to be more commonwy avaiwabwe dan oders.

For dispwaying characters outside de Basic Muwtiwinguaw Pwane, such as de Godic wetter faihu, which is a variant of de runic wetter fehu in de tabwe above, some systems (wike Windows 2000) need manuaw adjustments of deir settings.

According to internaw data from Googwe's web index, in December 2007 de UTF-8 Unicode encoding became de most freqwentwy used encoding on web pages, overtaking bof ASCII (US) and 8859-1/1252 (Western European).[4]