7. Unicode: A Universal Character Set
Unicode is a standard that assigns code points to characters used by writing systems, symbols, and emoji across many languages.
Examples include:
- English letters: A, B, C
- Odia text: ଓଡ଼ିଆ
- Hindi text: हिंदी
- Arabic text: العربية
- Japanese text: 日本語
- Mathematical symbols: ∑, √, ∞
- Emoji: 😀, 🚀, 🎉
Unicode provides a consistent way to identify these characters, but a font and a suitable rendering environment are still needed to display them correctly.
What Is a Unicode Code Point?
A Unicode code point is written in a form such as U+0041. The code point U+0041 identifies the capital Latin letter A.
Other examples include:
U+00A9— ©U+20AC— €U+2713— ✓U+1F600— 😀
A code point identifies a character in the Unicode standard. It is not the same thing as a byte in a file or network stream.
Characters, Code Points and Bytes
These terms are related but different:
- Character: A unit of text as understood by a writing system or application. A visible character may consist of multiple Unicode code points.
- Code point: A numeric value assigned to a Unicode character or code point sequence component.
- Byte: An 8-bit unit used to store or transmit encoded data.
- Encoding: A method for representing text as bytes.
For example, the visible character é can be represented by the single code point U+00E9. It can also be represented as the sequence U+0065 followed by U+0301, which combines the letter e with a combining acute accent.
These sequences can look the same while having different underlying code points. This can matter when comparing strings, counting characters, searching, or processing text.
8. UTF-8: Encoding Text for the Web
UTF-8 is a Unicode encoding that represents Unicode code points using one to four bytes. It is widely used for HTML documents, APIs, source code, and web content.
Declare the Character Encoding
For an HTML document, declare UTF-8 using a meta element near the beginning of the head:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Unicode Example</title>
</head>
<body>
<h1>Welcome to Codementrix</h1>
<p>Odia: ଓଡ଼ିଆ</p>
<p>Hindi: हिंदी</p>
<p>Symbol: © € ✓ 😀</p>
</body>
</html>The <meta charset="UTF-8"> declaration tells the browser which character encoding to use when interpreting the document, subject to the web platform's encoding rules.
Keep the charset declaration near the beginning of the document. The HTML standard requires it to be entirely contained within the first 1024 bytes of the document when using this declaration.