HTML: Character Sets and Encoding
In HTML, you can declare the Character Set for the file. Here's example of setting it to be UTF-8 (Unicode):
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
If you are using HTML5, you can just say:
<meta charset="utf-8" />
[see Unicode Basics: Character Set, Encoding, UTF-8]
Once you declared your character set, you can have characters from that character set in your HTML file.
UTF-8 (Unicode) contains all the world's language's characters. Here is a sample of characters from Unicode:
“ ” € © † é → ♥ ≠ 😂
[see Unicode Characters ∑ ♥ 😄]
Another way to show special characters in your file is by so-called “character entity”.
For example, the bullet symbol • is Unicode character number 8226. In HTML, you can write it as
The number 8226 in hexadecimal is 2022. Sometimes you only know the hexadecimal number of a character. You can write it using hexadecimal like this
For some commonly used characters, HTML provides “named entity” for them. For example, the bullet character can be written as
For a complete list of named entities, see: HTML/XML Entity List.
HTML/HTTP's Charset is About Encoding, Not Character Set
HTTP's definition of charset (and the charset meta tag in HTML) is actually about character encoding.
Here's a excerpt from [RFC 2616 At http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.4 ]:
3.4 Character Sets
HTTP uses the same definition of the term “character set” as that described for MIME:
The term “character set” is used in this document to refer to a method used with one or more tables to convert a sequence of octets into a sequence of characters. Note that unconditional conversion in the other direction is not required, in that not all characters may be available in a given character set and a character set may provide more than one sequence of octets to represent a particular character. This definition is intended to allow various kinds of character encoding, from simple single-table mappings such as US-ASCII to complex table switching methods such as those that use ISO-2022's techniques. However, the definition associated with a MIME character set name MUST fully specify the mapping to be performed from octets to characters. In particular, use of external profiling information to determine the exact mapping is not permitted.
Note: This use of the term “character set” is more commonly referred to as a “character encoding.” However, since HTTP and MIME share the same registry, it is important that the terminology also be shared.
If you don't understand what is Character Set and Encoding, see: Unicode Basics: Character Set, Encoding, UTF-8.
What's HTML4 or HTML5's Default Encoding?
By spec, there's no default encoding.
A encoding must came from one of http header, meta tag in html file. If none found, the browser must guess.
- The default character set for HTML 4 is Unicode, but you still need to declare the encoding. [W3C: Internationalization: Document Character Set At http://www.w3.org/International/questions/qa-doc-charset ]
- How User Agent should determine the char encoding. [HTML 4.01 Specification: 5 HTML Document Representation At http://www.w3.org/TR/html401/charset.html#idx-character_encoding-6 ]
- Unicode Basics: Character Set, Encoding, UTF-8, Codepoint
- HTML: Character Sets and Encoding
- Python: Unicode Tutorial 🐍
- Python: Convert File Encoding
- Python: Convert File Encoding for All Files in a Dir
- Perl: Unicode Tutorial 🐪
- Perl: Convert File Encoding
- Ruby: Unicode Tutorial 💎
- Java: Convert File Encoding
- Linux: Convert File Encoding with iconv
If you have a question, put $5 at patreon and message me.