Character encodings in HTML

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.

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:[1]

Content-Type: text/html; charset=utf-8

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.[2]

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:[3]

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

HTML5 also allows the following syntax to mean exactly the same:[3]

<meta charset="utf-8">

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

<?xml version="1.0" encoding="utf-8"?>

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.

Encoding detection algorithm

As of HTML5 the recommended charset is UTF-8.[3] An "encoding sniffing algorithm" is defined in the specification to determine the character encoding of the document based on multiple sources of input, including:

  1. Explicit user instruction
  2. An explicit meta tag within the first 1024 bytes of the document
  3. A byte order mark (BOM) within the first three bytes of the document
  4. The HTTP Content-Type or other transport layer information
  5. Analysis of the document bytes looking for specific sequences or ranges of byte values,[5] and other tentative detection mechanisms.

Characters outside of the printable ASCII range (32 to 126) usually appear incorrectly. 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.

It is increasingly common for multilingual websites and websites in non-Western languages to use UTF-8, which allows use of the same encoding for all languages. UTF-16 or UTF-32, which can be used for all languages as well, 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

The WHATWG Encoding Standard, referenced by recent HTML standards (the current WHATWG HTML Living Standard, as well as the formerly competing W3C HTML 5.0 and 5.1) specifies a list of encodings which browsers must support. The HTML standards forbid support of other encodings.[6][7][8] 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.[9]

Besides UTF-8, the following encodings are explicitly listed in the HTML standard itself, with reference to the Encoding Standard:[8]

  1. ^ Also specified for TIS-620, ISO-8859-11 and related labels.[9]
  2. ^ Also specified for ASCII, ISO-8859-1 and related labels.[9]
  3. ^ Also specified for ISO-8859-9 and related labels.[9]
  4. ^ Specified with 0xA3A0 as a duplicate encoding of the ideographic space (U+3000) for compatibility reasons, and as such excluding U+E5E5 (a private use character).[10][11] Also, specified with 0x80 accepted as an alternative encoding of the euro sign (U+20AC; see Windows-936).[12] Otherwise, follows the mappings from the 2005 standard.[11]
  5. ^ Hong Kong Supplementary Character Set variant,[13] although most of the HKSCS extensions (those with lead bytes less than 0xA1) are not included by the encoder, only by the decoder.[14]
  6. ^ The specification includes IBM and NEC extensions,[15] and is more precisely Windows-31J.[13]
  7. ^ The specification uses the same index as used for Shift JIS (insofar as is within reach), i.e. includes NEC extensions. Half-width kana is converted to fullwidth by the encoder,[16] but accepted using an escape sequence (ESC 0x28 0x49) by the decoder.[17] Shift Out and Shift In (0x0E and 0x0F) are excluded entirely to prevent attacks.[17][18]
  8. ^ Actually Unified Hangul Code (Windows-949), which is a superset which covers the entire Hangul Syllables block.[13][19]
  9. ^ Specified for decoding only; form submissions from UTF-16-coded documents are to be encoded in UTF-8.[20]
  10. ^ For compatibility with deployed content, also specified for the plain UTF-16 label,[21] although a byte order mark (BOM), if present, takes priority over any label.[22] Specified for decoding only; form submissions from UTF-16-coded documents are to be encoded in UTF-8.[20]
  11. ^ Maps 0x00 through 0x7F to U+0000 through U+007F, and 0x80 through 0xFF to U+F780 through U+F7FF (a Private Use Area range), such that the low 8 bits of the code point always match the original byte.[23]

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

  1. ^ Uses the same encoder and decoder as ISO-8859-8, but is not subject to the visual-order behaviour which is used for documents labelled as ISO-8859-8.[24]
  2. ^ Titled KOI8-U and specified for both KOI8-U and KOI8-RU labels;[9] follows KOI8-RU in positions 0xAE and 0xBE (i.e. includes Ў/ў)[25][26] but KOI8-U in positions 0x93–9F.[25]
  3. ^ Also specified for GB2312 and related labels. Handled the same as GB 18030 for decoding purposes.[27] For encoding purposes, labelling as GBK (or GB 2312) excludes four-byte codes, and favours the one-byte 0x80 representation for U+20AC.[10]
  4. ^ The specification uses the same index as used for Shift JIS (insofar as is within reach of the EUC code set 1), i.e. includes NEC extensions. JIS X 0212 is included for decoding only.[28]

The following encodings are listed as explicit examples of forbidden encodings:[8]

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.[29] 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.[30] The following encodings receive this treatment:[31]

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.

HTML character references

A numeric character reference in HTML refers to a character by its Universal Character Set/Unicode code point, and uses the format

&#nnnn;

or

&#xhhhh;

where nnnn is the code point in decimal form, and hhhh is the code point in hexadecimal form. The x must be lowercase in XML documents. The nnnn or hhhh may be any number of digits and may include leading zeros. The hhhh may mix uppercase and lowercase, though uppercase is the usual style.

Not all web browsers or email clients used by receivers of HTML documents, or text editors used by authors of HTML documents, will be able to render all HTML characters. Most modern software is able to display most or all of the characters for the user's language, and will draw a box or other clear indicator for characters they cannot render.

For codes from 0 to 127, the original 7-bit ASCII standard set, most of these characters can be used without a character reference. Codes from 160 to 255 can all be created using character entity names. Only a few higher-numbered codes can be created using entity names, but all can be created by decimal number character reference.

Character entity references can also have the format &name; where name is a case-sensitive alphanumeric string. For example, "λ" can also be encoded as &lambda; in an HTML document. The character entity references &lt;, &gt;, &quot; and &amp; are predefined in HTML and SGML, because <, >, " and & are already used to delimit markup. This notably did not include XML's &apos; (') entity prior to HTML5. For a list of all named HTML character entity references along with the versions in which they were introduced, see List of XML and HTML character entity references.

Unnecessary use of HTML character references may significantly reduce HTML readability. If the character encoding for a web page is chosen appropriately, then HTML character references are usually only required for markup delimiting characters as mentioned above, and for a few special characters (or none at all if a native Unicode encoding like UTF-8 is used). Incorrect HTML entity escaping may also open up security vulnerabilities for injection attacks such as cross-site scripting. If HTML attributes are left unquoted, certain characters, most importantly whitespace, such as space and tab, must be escaped using entities. Other languages related to HTML have their own methods of escaping characters.

XML character references

Unlike traditional HTML with its large range of character entity references, in XML there are only five predefined character entity references. These are used to escape characters that are markup sensitive in certain contexts:[32]

&amp; & ampersand U+0026
&lt; < less-than sign U+003C
&gt; > greater-than sign U+003E
&quot; " quotation mark U+0022
&apos; ' apostrophe U+0027

All other character entity references have to be defined before they can be used. For example, use of &eacute; (which gives é, Latin lower-case E with acute accent, U+00E9 in Unicode) in an XML document will generate an error unless the entity has already been defined. XML also requires that the x in hexadecimal numeric references be in lowercase: for example &#xA1b rather than &#XA1b. XHTML, which is an XML application, supports the HTML entity set, along with XML's predefined entities.

See also

References

  1. ^ Fielding, R.; Reschke, J. (June 2014), "Content-Type", in Fielding, R; Reschke, J (eds.), Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content, IETF, doi:10.17487/RFC7231, S2CID 14399078, retrieved 30 July 2014
  2. ^ "Apache Module mod_charset_lite".
  3. ^ a b c "Specifying the document's character encoding", HTML5, World Wide Web Consortium, 14 December 2017, retrieved 28 May 2018
  4. ^ Bray, T.; Paoli, J.; Sperberg-McQueen, C.; Maler, E.; Yergeau, F. (26 November 2008), "Prolog and Document Type Declaration", XML, W3C, retrieved 8 March 2010
  5. ^ "HTML5 prescan a byte stream to determine its encoding".
  6. ^ "8.2.2.3. Character encodings". HTML 5.1 Standard. W3C.
  7. ^ "8.2.2.3. Character encodings". HTML 5 Standard. W3C.
  8. ^ a b c "12.2.3.3 Character encodings". HTML Living Standard. WHATWG.
  9. ^ a b c d e f van Kesteren, Anne. "4.2: Names and labels". Encoding Standard. WHATWG.
  10. ^ a b van Kesteren, Anne. "10.2.2. gb18030 encoder". Encoding Standard. WHATWG.
  11. ^ a b van Kesteren, Anne. "5. Indexes (§ index gb18030)". Encoding Standard. WHATWG.
  12. ^ van Kesteren, Anne. "10.2.1. gb18030 decoder". Encoding Standard. WHATWG.
  13. ^ a b c Mozilla Foundation. "Notable Differences from IANA Naming". Crate encoding_rs. docs.rs.
  14. ^ van Kesteren, Anne. "5. Indexes (§ index Big5 pointer)". Encoding Standard. WHATWG.
  15. ^ van Kesteren, Anne. "5. Indexes (§ Index jis0208)". Encoding Standard. WHATWG.
  16. ^ van Kesteren, Anne. "5. Indexes (§ Index ISO-2022-JP katakana)". Encoding Standard. WHATWG.
  17. ^ a b van Kesteren, Anne. "12.2.1. ISO-2022-JP decoder". Encoding Standard. WHATWG.
  18. ^ van Kesteren, Anne. "12.2.2. ISO-2022-JP encoder". Encoding Standard. WHATWG.
  19. ^ van Kesteren, Anne. "5. Indexes (§ index EUC-KR)". Encoding Standard. WHATWG.
  20. ^ a b van Kesteren, Anne. "4.3. Output encodings". Encoding Standard. WHATWG.
  21. ^ van Kesteren, Anne. "14.4. UTF-16LE". Encoding Standard. WHATWG.
  22. ^ van Kesteren, Anne. "6. Hooks for standards (§ decode)". Encoding Standard. WHATWG.
  23. ^ van Kesteren, Anne. "14.5. x-user-defined". Encoding Standard. WHATWG.
  24. ^ van Kesteren, Anne. "9. Legacy single-byte encodings (§ Note)". Encoding Standard. WHATWG.
  25. ^ a b van Kesteren, Anne. "index KOI8-U visualization". Encoding Standard. WHATWG.
  26. ^ "Bug 17053: Support KOI8-RU mapping for KOI8-U". W3C Bugzilla. 19 August 2015.
  27. ^ van Kesteren, Anne. "10.1. GBK". Encoding Standard. WHATWG.
  28. ^ van Kesteren, Anne. "5. Indexes (§ Index jis0212)". Encoding Standard. WHATWG.
  29. ^ van Kesteren, Anne. "14.1: replacement". Encoding Standard. WHATWG.
  30. ^ van Kesteren, Anne. "2: Security background". Encoding Standard. WHATWG.
  31. ^ van Kesteren, Anne. "4.2: Names and labels (§ replacement)". Encoding Standard. WHATWG.
  32. ^ Bray, T.; Paoli, J.; Sperberg-McQueen, C.; Maler, E.; Yergeau, F. (26 November 2008), "Character and Entity References", XML, W3C, retrieved 8 March 2010

Read other articles:

Franz Xaver GruberPotret oleh Sebastian Stief (Hallein,1846), Silent Night Museum, HalleinLahir25 November 1787Hochburg-Ach, Austria Hulu, Monarki HabsburgMeninggal7 Juni 1863 (aged 75)Hallein, Salzburg, Kekaisaran AustriaPekerjaanTeacherchurch organistcomposerKaryaStille Nacht (Malam Kudus) Franz Xaver Gruber (25 November 1787 – 7 Juni 1863) adalah seorang guru SD Austria dan pemain orgen di gereja yang bersama dengan Josef Mohr menulis lagu Silent Night (Stille Nacht dalam ...

 

 

Grumman Gulfstream II ( G-II ) adalah sebuah jet bisnis sayap rendah (low wing) Amerika mesin kembar yang dirancang dan dibangun oleh Grumman dan kemudian berturut-turut, Grumman Amerika dan akhirnya Gulfstream Amerika . Nomor model Grumman adalah G-1159 dan penunjukan militer AS adalah C-11 Gulfstream II . Telah digantikan oleh Gulfstream III . Gulfstream II pertama terbang pada tanggal 2 Oktober 1966. Referensi Pranala luar Media terkait Grumman Gulfstream II di Wikimedia Commons lbsPesawa...

 

 

artikel ini perlu dirapikan agar memenuhi standar Wikipedia. Tidak ada alasan yang diberikan. Silakan kembangkan artikel ini semampu Anda. Merapikan artikel dapat dilakukan dengan wikifikasi atau membagi artikel ke paragraf-paragraf. Jika sudah dirapikan, silakan hapus templat ini. (Pelajari cara dan kapan saatnya untuk menghapus pesan templat ini) Halaman ini berisi artikel tentang partai politik di Amerika Serikat. Untuk parpol di Indonesia, lihat Partai Demokrat. Partai Demokrat Democratic...

1949–1989 socialist republic in Central Europe This article is about the Communist state. For the republic of 1918-1919, see First Hungarian Republic. This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Hungarian People's Republic – news · newspapers · books · scholar · JSTOR (November 2023) (Learn how and whe...

 

 

President James Monroe. Following is a list of all Article III United States federal judges appointed by President James Monroe during his presidency.[1] In total Monroe appointed 22 Article III federal judges, including 1 Justice to the Supreme Court of the United States and 21 judges to the United States district courts. Monroe appointed Smith Thompson to the Supreme Court. Willard Hall was appointed by Monroe to the District of Delaware, and continued serving on the court for fort...

 

 

Municipality in Brandenburg, GermanyWerben WjerbnoMunicipalityLocation of Werben within Spree-Neiße district Werben Show map of GermanyWerben Show map of BrandenburgCoordinates: 51°49′N 14°14′E / 51.817°N 14.233°E / 51.817; 14.233CountryGermanyStateBrandenburgDistrictSpree-Neiße Municipal assoc.Burg (Spreewald)Subdivisions2 OrtsteileGovernment • Mayor (2019–24) Joachim Dieke[1]Area • Total24.94 km2 (9.63 sq ...

ميتيلينيوي   تقسيم إداري البلد اليونان  [1] إحداثيات 37°43′36″N 26°54′32″E / 37.72666667°N 26.90888889°E / 37.72666667; 26.90888889   السكان التعداد السكاني 1778 (resident population of Greece) (2021)2356 (resident population of Greece) (2001)2576 (resident population of Greece) (1991)1982 (resident population of Greece) (2011)  الرمز الجغرافي 256865  ...

 

 

Bandar Udara TallinnTallinna lennujaamIATA: TLLICAO: EETNInformasiJenisPublicPengelolaTallinn Airport LtdMelayaniTallinn, EstoniaMaskapai penghubungairBalticSmartLynx Airlines EstoniaKetinggian dpl mdplKoordinat59°24′48″N 024°49′57″E / 59.41333°N 24.83250°E / 59.41333; 24.83250Koordinat: 59°24′48″N 024°49′57″E / 59.41333°N 24.83250°E / 59.41333; 24.83250Situs webtallinn-airport.eePetaEETNLokasi di EropaTampilkan...

 

 

Cet article est une ébauche concernant un acteur américain. Vous pouvez partager vos connaissances en l’améliorant (comment ?) selon les conventions filmographiques. Pour les articles homonymes, voir Hughes. Barnard HughesBarnard HughesBiographieNaissance 16 juillet 1915Comté de WestchesterDécès 11 juillet 2006 (à 90 ans)New York (États-Unis)Nationalité américaineFormation Manhattan CollegeLa Salle Academy (en)Activités ActeurPériode d'activité à partir de 1939Conjo...

Hardline nationalist political movement in Russia Club of Angry Patriots Клуб рассерженных патриотовAbbreviationKRPLeaderIgor StrelkovChairmanPavel GubarevFoundersIgor StrelkovPavel GubarevMaxim KalashnikovViktor AlksnisYevgeny MikhailovMikhail AkselFounded1 April 2023 (2023-04-01)IdeologyRussian nationalism[1]MilitarismJingoismColours  Black  Gold  WhiteSloganEverything for the front, everything for Victory, glory to Russia!(Russ...

 

 

Glenn MurcuttGlenn Murcutt pada 2004Lahir25 Juli 1936 (umur 87)London, InggrisKebangsaanAustraliaPekerjaanArsitekPenghargaanRAIA Gold Medal (1992)Penghargaan Pritzker (2002)American Institute of Architects Gold Medal (2009)GedungMarie Short House (1975), Fredericks House (1982), Ball-Eastaway House (1983), Magney House (1984), Marika-Alderton House (1994), Arthur and Yvonne Boyd Education Centre (1999) Glenn Marcus Murcutt AO (lahir 25 Juli 1936) adalah seorang arsitek Australia kelahir...

 

 

Performing arts center in San Francisco, California San Francisco War Memorial and Performing Arts CenterBeaux-Arts style War Memorial Veterans Building and courtyard park, seen from Van Ness Avenue.San Francisco War Memorial and Performing Arts CenterLocation within San Francisco CountyShow map of San Francisco CountySan Francisco War Memorial and Performing Arts CenterSan Francisco War Memorial and Performing Arts Center (California)Show map of CaliforniaSan Francisco War Memorial and Perfo...

إمام المسلمين وسلطان العربصاحب الجلالة المعظم عبد العزيز آل سُعُود إمام ومؤسس الدولة السعودية الثالثةمَلِك الحِجاز وَسُلْطان نَجْد وَمُلْحَقاتِهْامَلِك الْمَمْلَكَة العَرَبيَّة السَّعُودِيَّة الحاكم الرابع عشر من آل سعود رسم لأول صورة رسمية جرى نشرها في وكالات الأنب...

 

 

В Википедии есть статьи о других людях с фамилией Малютин. Сергей Васильевич Малютин Автопортрет 1918 года Дата рождения 22 сентября (4 октября) 1859[1] Место рождения Москва, Российская империя[2] Дата смерти 6 декабря 1937(1937-12-06)[2][3][…] (78 лет) Место смерти Мо�...

 

 

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (مارس 2020) في الهندسة الإسقاطية، النقاط الدائرية في اللانهاية أو النقاط الحلقية هي نوعان من النقاط في اللانهاية على المستوى المركب الإسقاطي يحتويهما استعقاد كل دائرة ح...

Disambiguazione – Se stai cercando altri significati, vedi Arese (disambigua). Nel seguente testo sull'argomento Lombardia è presente una sospetta violazione di copyright. Motivo: grosso inserimento formalmente corretto privo di fonti e non wikif È sconsigliato wikificare o ampliare il testo attuale, che potrebbe essere cancellato. Puoi invece riformulare il testo con parole tue o partecipare alla discussione. Segui i suggerimenti del progetto di riferimento.Avvisa l'autore: {{Avvis...

 

 

  提示:此条目页的主题不是黃妍。 黃洛妍2024年1月26日,香港女歌手黃洛妍於伊利沙伯體育館為懲教署「更生先鋒計劃」項目《重新啟航GO GO GOAL!》擔任表演嘉賓期間,於後台拍攝。女歌手罗马拼音Wong Lok Yin英文名Janees Wong昵称黃老師、Jan Jan国籍 中华人民共和国(香港)出生 (1997-06-26) 1997年6月26日(26歲) 英屬香港职业歌手、小提琴演奏家语言粵語、英語、國語�...

 

 

Pour les articles homonymes, voir Duncan. John Charles DuncanBiographieNaissance 8 février 1882Knightstown (en)Décès 10 septembre 1967 (à 85 ans)Chula VistaSépulture Cimetière de Crown Hill (en)Nationalité américaineFormation Université HarvardActivités Astronome, écrivainAutres informationsA travaillé pour Université HarvardMembre de Académie américaine des arts et des sciencesmodifier - modifier le code - modifier Wikidata John Charles Duncan (1882 - 1967) est un astron...

Woodworking tool for creating shaped profiles End-on shot of 15 different moulding planes. A highly detailed description of each plane is present on the image page itselfIn woodworking, a moulding plane (molding plane in US spelling) is a specialised plane used for making the complex shapes found in wooden mouldings. [1] Traditionally, moulding planes were blocks of wear resistant hardwood, often beech or maple, which were worked to the shape of the intended moulding. The blade, or ir...

 

 

Charleville-Mézières Charleville-Mézières Vị trí trong vùng Champagne-Ardenne Charleville-Mézières Hành chính Quốc gia Pháp Vùng Grand Est Tỉnh Ardennes Quận Charleville-Mézières Liên xã Cœur d'Ardennes Xã (thị) trưởng Claudine Ledoux(2008-2013) Thống kê Độ cao 133–323 m (436–1.060 ft)(bình quân 148 m (486 ft)[chuyển đổi: tùy chọn không hợp lệ]) Diện tích đất1 31,44 km2 (12,14 dặm vuông A...