Misplaced Pages

Character encodings in HTML

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.

Specials is a short Unicode block of characters allocated at the very end of the Basic Multilingual Plane , at U+FFF0–FFFF, containing these code points :

#190809

60-458: 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. There are two general ways to specify which character encoding

120-500: A Document type declaration (informally, a "doctype"). In browsers, the doctype helps to define the rendering mode—particularly whether to use quirks mode . The original purpose of the doctype was to enable the parsing and validation of HTML documents by SGML tools based on the Document type definition (DTD). The DTD to which the DOCTYPE refers contains a machine-readable grammar specifying

180-431: 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

240-486: A web browser . It defines the content and structure of web content . It is often assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaScript, a programming language. Web browsers receive HTML documents from a web server or from local storage and render the documents into multimedia web pages. HTML describes the structure of a web page semantically and originally included cues for its appearance. HTML elements are

300-491: A ' tofu '. There is no Unicode code point for this symbol. Thus the replacement character is now only seen for encoding errors. Some software programs translate invalid UTF-8 bytes to matching characters in Windows-1252 (since that is the most common source of these errors), so that the replacement character is never seen. The following Unicode-related documents record the purpose and process of defining specific characters in

360-649: A character by its Universal Character Set / Unicode code point , and uses the format or 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

420-407: A contractor at CERN , proposed and prototyped ENQUIRE , a system for CERN researchers to use and share documents. In 1989, Berners-Lee wrote a memo proposing an Internet -based hypertext system. Berners-Lee specified HTML and wrote the browser and server software in late 1990. That year, Berners-Lee and CERN data systems engineer Robert Cailliau collaborated on a joint request for funding, but

480-430: 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

540-1013: 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. 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: All other character entity references have to be defined before they can be used. For example, use of é (which gives é, Latin lower-case E with acute accent, U+00E9 in Unicode) in an XML document will generate an error unless

600-437: 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

660-447: A pair is the start tag , and the second is the end tag (they are also called opening tags and closing tags ). Another important component is the HTML document type declaration , which triggers standards mode rendering. The following is an example of the classic "Hello, World!" program : The text between < html > and </ html > describes the web page, and

SECTION 10

#1732869349191

720-721: A processor of HTML, such as a web browser, should be able to parse the declaration in some cases through the use of heuristics. As of HTML5 the recommended charset is UTF-8 . An "encoding sniffing algorithm" is defined in the specification to determine the character encoding of the document based on multiple sources of input, including: 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

780-425: A start tag) and do not use an end tag. Many tags, particularly the closing end tag for the very commonly used paragraph element < p > , are optional. An HTML browser or other agent can infer the closure for the end of an element from the context and the structural rules defined by the HTML standard. These rules are complex and not widely understood by most HTML authors. The general form of an HTML element

840-590: A user can give input/s like: Comments: Comments can help in the understanding of the markup and do not display in the webpage. There are several types of markup elements used in HTML: Most of the attributes of an element are name–value pairs , separated by = and written within the start tag of an element after the element's name. The value may be enclosed in single or double quotes, although values consisting of certain characters can be left unquoted in HTML (but not XHTML). Leaving attribute values unquoted

900-538: 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

960-448: 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

1020-464: Is considered unsafe. In contrast with name-value pair attributes, there are some attributes that affect the element simply by their presence in the start tag of the element, like the ismap attribute for the img element. There are several common attributes that may appear in many elements : The abbreviation element, abbr , can be used to demonstrate some of these attributes: This example displays as HTML ; in most browsers, pointing

1080-456: Is for HTML5. If a declaration is not included, various browsers will revert to " quirks mode " for rendering. HTML documents imply a structure of nested HTML elements . These are indicated in the document by HTML tags , enclosed in angle brackets thus: < p > . In the simple, general case, the extent of an element is indicated by a pair of tags: a "start tag" < p > and "end tag" </ p > . The text content of

1140-401: Is therefore: < tag attribute1 = "value1" attribute2 = "value2" > ''content'' </ tag > . Some HTML elements are defined as empty elements and take the form < tag attribute1 = "value1" attribute2 = "value2" > . Empty elements may enclose no content, for instance, the < br /> tag or

1200-552: 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,

1260-570: The Internet Engineering Task Force (IETF) with the mid-1993 publication of the first proposal for an HTML specification, the "Hypertext Markup Language (HTML)" Internet Draft by Berners-Lee and Dan Connolly , which included an SGML Document type definition to define the syntax. The draft expired after six months, but was notable for its acknowledgment of the NCSA Mosaic browser's custom tag for embedding in-line images, reflecting

SECTION 20

#1732869349191

1320-552: The Specials table. It is used to indicate problems when a system is unable to render a stream of data to correct symbols. As an example, a text file encoded in ISO 8859-1 containing the German word für contains the bytes 0x66 0xFC 0x72 . If this file is opened with a text editor that assumes the input is UTF-8 , the first and third bytes are valid UTF-8 encodings of ASCII , but

1380-434: The de facto web standard for some time. HTML markup consists of several key components, including those called tags (and their attributes ), character-based data types , character references and entity references . HTML tags most commonly come in pairs like < h1 > and </ h1 > , although some represent empty elements and so are unpaired, for example < img > . The first tag in such

1440-419: 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

1500-668: The DTD in order to properly parse the document and to perform validation. In modern browsers, a valid doctype activates standards mode as opposed to quirks mode . Replacement character U+FFFE <noncharacter-FFFE> and U+FFFF <noncharacter-FFFF> are noncharacters , meaning they are reserved but do not cause ill-formed Unicode text. Versions of the Unicode standard from 3.1.0 to 6.3.0 claimed that these characters should never be interchanged, leading some applications to use them to guess text encoding by interpreting

1560-452: The IETF's philosophy of basing standards on successful prototypes. Similarly, Dave Raggett 's competing Internet Draft, "HTML+ (Hypertext Markup Format)", from late 1993, suggested standardizing already-implemented features like tables and fill-out forms. After the HTML and HTML+ drafts expired in early 1994, the IETF created an HTML Working Group. In 1995, this working group completed "HTML 2.0",

1620-540: The XML syntax for HTML and is no longer being developed as a separate standard. On 28 May 2019, the W3C announced that WHATWG would be the sole publisher of the HTML and DOM standards. The W3C and WHATWG had been publishing competing standards since 2012. While the W3C standard was identical to the WHATWG in 2007 the standards have since progressively diverged due to different design decisions. The WHATWG "Living Standard" had been

1680-473: The attribute value itself. If document authors overlook the need to escape such characters, some browsers can be very forgiving and try to use context to guess their intent. The result is still invalid markup, which makes the document less accessible to other browsers and to other user agents that may try to parse the document for search and indexing purposes for example. Escaping also allows for characters that are not easily typed, or that are not available in

1740-463: The beginning of a Unicode text to signal its endianness : a program reading such a text and encountering 0xFFFE would then know that it should switch the byte order for all the following characters. Its block name in Unicode 1.0 was Special . The replacement character � (often displayed as a black rhombus with a white question mark) is a symbol found in the Unicode standard at code point U+FFFD in

1800-566: The browser, and these characteristics can be altered or enhanced by the web page designer's additional use of CSS . Many of the text elements are mentioned in the 1988 ISO technical report TR 9537 Techniques for using SGML , which describes the features of early text formatting languages such as that used by the RUNOFF command developed in the early 1960s for the CTSS (Compatible Time-Sharing System) operating system. These formatting commands were derived from

1860-486: The building blocks of HTML pages. With HTML constructs, images and other objects such as interactive forms may be embedded into the rendered page. HTML provides a means to create structured documents by denoting structural semantics for text such as headings, paragraphs, lists, links , quotes, and other items. HTML elements are delineated by tags , written using angle brackets . Tags such as < img > and < input > directly introduce content into

Character encodings in HTML - Misplaced Pages Continue

1920-433: The characters < and & (when written as &lt; and &amp; , respectively) to be interpreted as character data, rather than markup. For example, a literal < normally indicates the start of a tag, and & normally indicates the start of a character entity reference or numeric character reference; writing it as &amp; or &#x26; or &#38; allows & to be included in

1980-441: The characters of the world's writing systems. HTML defines several data types for element content, such as script data and stylesheet data, and a plethora of types for attribute values, including IDs, names, URIs , numbers, units of length, languages, media descriptors, colors, character encodings, dates and times, and so on. All of these data types are specializations of character data. HTML documents are required to start with

2040-447: The commands used by typesetters to manually format documents. However, the SGML concept of generalized markup is based on elements (nested annotated ranges with attributes) rather than merely print effects, with separate structure and markup. HTML has been progressively moved in this direction with CSS. Berners-Lee considered HTML to be an application of SGML. It was formally defined as such by

2100-535: The content of an element or in the value of an attribute. The double-quote character ( " ), when not used to quote an attribute value, must also be escaped as &quot; or &#x22; or &#34; when it appears within the attribute value itself. Equivalently, the single-quote character ( ' ), when not used to quote an attribute value, must also be escaped as &#x27; or &#39; (or as &apos; in HTML5 or XHTML documents ) when it appears within

2160-664: The cursor at the abbreviation should display the title text "Hypertext Markup Language." Most elements take the language-related attribute dir to specify text direction, such as with "rtl" for right-to-left text in, for example, Arabic , Persian or Hebrew . As of version 4.0, HTML defines a set of 252 character entity references and a set of 1,114,050 numeric character references , both of which allow individual characters to be written via simple markup, rather than literally. A literal character and its markup counterpart are considered equivalent and are rendered identically. The ability to " escape " characters in this way allows for

2220-428: 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 ,

2280-589: The document's character encoding , to be represented within the element and attribute content. For example, the acute-accented e ( é ), a character typically found only on Western European and South American keyboards, can be written in any HTML document as the entity reference &eacute; or as the numeric references &#xE9; or &#233; , using characters that are available on all keyboards and are supported in all character encodings. Unicode character encodings such as UTF-8 are compatible with all modern browsers and allow direct access to almost all

2340-445: The element, if any, is placed between these tags. Tags may also enclose further tag markup between the start and end, including a mixture of tags and text. This indicates further (nested) elements, as children of the parent element. The start tag may also include the element's attributes within the tag. These indicate other information, such as identifiers for sections within the document, identifiers used to bind style information to

2400-411: 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. HTML Hypertext Markup Language ( HTML ) is the standard markup language for documents designed to be displayed in

2460-404: The file is re-opened using ISO 8859-1, it will display "f�r" (this is called mojibake ). Since the replacement is the same for all errors it is impossible to recover the original character. A design that is better (but harder to implement) is to preserve the original bytes, including any errors, and only convert to the replacement when displaying the text. This will allow the text editor to save

Character encodings in HTML - Misplaced Pages Continue

2520-506: The first HTML specification intended to be treated as a standard against which future implementations should be based. Further development under the auspices of the IETF was stalled by competing interests. Since 1996, the HTML specifications have been maintained, with input from commercial software vendors, by the World Wide Web Consortium (W3C). In 2000, HTML became an international standard ( ISO / IEC 15445:2000). HTML 4.01

2580-554: 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

2640-453: 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

2700-412: The head, for example: HTML headings are defined with the < h1 > to < h6 > tags with H1 being the highest (or most important) level and H6 the least: The effects are: CSS can substantially change the rendering. Paragraphs: < br /> . The difference between < br /> and < p > is that < br /> breaks a line without altering

2760-425: The hyperlink tag, these were strongly influenced by SGMLguid , an in-house Standard Generalized Markup Language (SGML)-based documentation format at CERN. Eleven of these elements still exist in HTML 4. HTML is a markup language that web browsers use to interpret and compose text, images, and other material into visible or audible web pages. Default characteristics for every item of HTML markup are defined in

2820-402: The inline < img > tag. The name of an HTML element is the name used in the tags. The end tag's name is preceded by a slash character, / , and that in empty elements the end tag is neither required nor allowed. If attributes are not mentioned, default values are used in each case. Header of the HTML document: < head > ... </ head > . The title is included in

2880-462: The look and layout of content. The World Wide Web Consortium (W3C), former maintainer of the HTML and current maintainer of the CSS standards, has encouraged the use of CSS over explicit presentational HTML since 1997. A form of HTML, known as HTML5 , is used to display video and audio, primarily using the < canvas > element, together with JavaScript. In 1980, physicist Tim Berners-Lee ,

2940-422: The original byte sequence, while still showing an error indication to the user. At one time the replacement character was often used when there was no glyph available in a font for that character, as in font substitution . However, most modern text rendering systems instead use a font's .notdef character, which in most cases is an empty box, or "?" or "X" in a box (this browser displays 􏿮), sometimes called

3000-413: The page. Other tags such as < p > and </ p > surround and provide information about document text and may include sub-element tags. Browsers do not display the HTML tags but use them to interpret the content of the page. HTML can embed programs written in a scripting language such as JavaScript , which affects the behavior and content of web pages. The inclusion of CSS defines

3060-434: The permitted and prohibited content for a document conforming to such a DTD. Browsers, on the other hand, do not implement HTML as an application of SGML and as consequence do not read the DTD. HTML5 does not define a DTD; therefore, in HTML5 the doctype declaration is simpler and shorter: An example of an HTML 4 doctype This declaration references the DTD for the "strict" version of HTML 4.01. SGML-based validators read

SECTION 50

#1732869349191

3120-489: The presence of either as a sign that the text is not Unicode. However, Corrigendum #9 later specified that noncharacters are not illegal and so this method of checking text encoding is incorrect. An example of an internal usage of U+FFFE is the CLDR algorithm ; this extended Unicode algorithm maps the noncharacter to a minimal, unique primary weight. Unicode's U+FEFF ZERO WIDTH NO-BREAK SPACE character can be inserted at

3180-412: The presentation of the document, and for some tags such as the < img > used to embed images, the reference to the image resource in the format like this: < img src = "example.com/example.jpg" > Some elements, such as the line break < br /> do not permit any embedded content, either text or further tags. These require only a single empty tag (akin to

3240-486: The project was not formally adopted by CERN. In his personal notes of 1990, Berners-Lee listed "some of the many areas in which hypertext is used"; an encyclopedia is the first entry. The first publicly available description of HTML was a document called "HTML Tags", first mentioned on the Internet by Tim Berners-Lee in late 1991. It describes 18 elements comprising the initial, relatively simple design of HTML. Except for

3300-657: 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. 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. 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,

3360-459: The second byte ( 0xFC ) is not valid in UTF-8. The text editor could replace this byte with the replacement character to produce a valid string of Unicode code points for display, so the user sees "f�r". A poorly implemented text editor might write out the replacement character when the user saves the file; the data in the file will then become 0x66 0xEF 0xBF 0xBD 0x72 . If

3420-468: The semantic structure of the page, whereas < p > sections the page into paragraphs . The element < br /> is an empty element in that, although it may have attributes, it can take no content and it may not have an end tag. This is a link in HTML. To create a link the < a > tag is used. The href attribute holds the URL address of the link. There are many possible ways

3480-517: The text between < body > and </ body > is the visible page content. The markup text < title > This is a title </ title > defines the browser page title shown on browser tabs and window titles and the tag < div > defines a division of the page used for easy styling. Between < head > and </ head > , a < meta > element can be used to define webpage metadata. The Document Type Declaration <!DOCTYPE html>

3540-583: Was not seen as feasible for them since they are comparatively more frequently used in deployed content. The following encodings receive this treatment: 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 . A numeric character reference in HTML refers to

3600-496: Was published in late 1999, with further errata published through 2001. In 2004, development began on HTML5 in the Web Hypertext Application Technology Working Group (WHATWG), which became a joint deliverable with the W3C in 2008, and was completed and standardized on 28 October 2014. XHTML is a separate language that began as a reformulation of HTML 4.01 using XML 1.0. It is now referred to as

#190809