Character encodings in HTML
HTML has been in use since 1991, but HTML 4.0 (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.
Contents |
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.
Character entity references have the format &name;
where "name" is a case-sensitive alphanumeric string. For example, the character 'λ' can be encoded as λ
in an HTML 4 document. Characters <, >, " and & are used to delimit tags, attribute values, and character references. Character entity references <
, >
, "
and &
, which are predefined in HTML, XML, and SGML, can be used instead for literal representations of the characters.
Numeric character references can be in decimal format, &#DD;
, where DD
is a variable-width string of decimal digits. Similarly there is a hexadecimal format, &#xHHHH;
, where HHHH
is a variable-width string of hexadecimal digits, though many consider it good practice to never use fewer than four hex digits, and never use an odd number of hex digits (due to the correspondence of two hex digits to one byte). Unlike named entities, hexadecimal character references are case-insensitive in HTML. For example, λ can also be represented as λ
, λ
or λ
.
Numeric references always refer to Universal Character Set code points, regardless of the page's encoding. Using numeric references that refer to UCS control code ranges is forbidden, with the exception of the linefeed, tab, and carriage return characters. That is, characters in the hexadecimal ranges 00–08, 0B–0C, 0E–1F, 7F, and 80–9F cannot be used in an HTML document, not even by reference —so "™", for example, is not allowed. However, for backward compatibility with early HTML authors and browsers that ignored this restriction, raw characters and numeric character references in the 80–9F range are interpreted by some browsers as representing the characters mapped to bytes 80–9F in the Windows-1252 encoding.
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 a few special characters (or not at all if a native Unicode encoding like UTF-8 is used).
HTML character entity references
For a list of all named HTML character entity references, see List of XML and HTML character entity references (approximately 250 entries).
See also
Content that violates any copyright will be deleted. Encyclopedic content must be verifiable. You irrevocably agree to release your contributions under the terms of the GFDL*. Edit summary (Briefly describe the changes you have made):
External links
- Character entity references in HTML 4
- Character Entities for XHTML
- HTML and XHTML character entities with images for each
Please note:
* If you don't want your writing to be edited mercilessly or redistributed for profit by others, do not submit it. * Only public domain resources can be copied without permission—this does not include most web pages or images. * See our policies and guidelines for more information on editing.
1. ^ GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts.