HTML Codering (Caractergeset)

为了正确显示 HTML 页面,Web 浏览器必须知道要使用哪个字符集。

从 ASCII 到 UTF-8

ASCII 是第一个字符编码标准。ASCII 定义了 128 种可以在互联网上使用的字符:数字(0-9)、英文字母(A-Z)和一些特殊字符,比如:! $ + - ( ) @ < >。

ISO-8859-1 是 HTML 4 的默认字符集。此字符集支持 256 个不同的字符代码。HTML 4 同时支持 UTF-8。

ANSI(Windows-1252)是原始的 Windows 字符集。 ANSI 与 ISO-8859-1 相同,不同之处在于 ANSI 具有 32 个额外的字符。

HTML5 规范鼓励 Web 开发人员使用 UTF-8 字符集,该字符集涵盖了世界上几乎所有的字符和符号!

HTML charset 属性

为了正确显示 HTML 页面,Web 浏览器必须了解页面中使用的字符集。

这在 <meta> 标签中指定:

<meta charset="UTF-8">

亲自试一试

字符集之间的差异

下表展示了上述字符集之间的区别:

Numb ASCII ANSI 8859 UTF-8 Description
32 space
33!!!!exclamation mark
34""""quotation mark
35####number sign
36$$$$dollar sign
37%%%%percent sign
3838383838&
ampersand39393939'
apostrophe40404040(
left parenthesis41414141)
right parenthesis42424242*
asterisk43434343+
plus sign44444444,
comma45454545-
hyphen-minus46464646.
full stop47474747/
solidus484848480
digit zero494949491
digit one505050502
digit two515151513
digit three525252524
digit four535353535
digit five545454546
digit six555555557
digit seven565656568
digit eight575757579
digit nine58585858:
colon59595959;
semicolon60606060<
less-than sign61616161=
equals sign62626262>
greater-than sign????question mark
64@@@@commercial at
65AAAALatin capital letter A
66BBBBLatin capital letter B
67CCCCLatin capital letter C
68DDDDLatin capital letter D
69EEEELatin capital letter E
70FFFFLatin capital letter F
71GGGGLatin capital letter G
72HHHHLatin capital letter H
73IIIILatin capital letter I
74JJJJLatin capital letter J
75KKKKLatin capital letter K
76LLLLLatin capital letter L
77MMMMLatin capital letter M
78NNNNLatin capital letter N
79OOOOLatin capital letter O
Latin capital letter MNNNNLatin capital letter N
OLatin capital letter OLatin capital letter OLatin capital letter OLatin capital letter O80
PLatin capital letter PLatin capital letter PLatin capital letter PLatin capital letter P81
QLatin capital letter QLatin capital letter QLatin capital letter QLatin capital letter Q82
RLatin capital letter RLatin capital letter RLatin capital letter RLatin capital letter R83
SLatin capital letter SLatin capital letter SLatin capital letter SLatin capital letter S84
TLatin capital letter TLatin capital letter TLatin capital letter TLatin capital letter T85
ULatin capital letter ULatin capital letter ULatin capital letter ULatin capital letter U86
VLatin capital letter VLatin capital letter VLatin capital letter VLatin capital letter V87
WLatin capital letter WLatin capital letter WLatin capital letter WLatin capital letter W88
XLatin capital letter XLatin capital letter XLatin capital letter XLatin capital letter X89
YLatin capital letter YLatin capital letter YLatin capital letter YLatin capital letter Y90
ZLatin capital letter ZLatin capital letter ZLatin capital letter ZLatin capital letter Z91
[left square bracketleft square bracketleft square bracketleft square bracket\
reverse solidus]]]]right square bracket
^circumflex accentcircumflex accentcircumflex accentcircumflex accent_
low line````grave accent
97aaaaLatin small letter a
98bbbbLatin small letter b
99ccccLatin small letter c
100ddddLatin small letter d
101eeeeLatin small letter e
102ffffLatin small letter f
103ggggLatin small letter g
104hhhhLatin small letter h
105iiiiLatin small letter i
106jjjjLatin small letter j
107kkkkLatin small letter k
108llllLatin small letter l
109mmmmLatin small letter m
110nnnnLatin small letter n
111ooooLatin small letter o
112ppppLatin small letter p
113qqqqLatin small letter q
114rrrrLatijnse kleine letter r
115ssssLatijnse kleine letter s
116ttttLatijnse kleine letter t
117uuuuLatijnse kleine letter u
118vvvvLatijnse kleine letter v
119wwwwLatijnse kleine letter w
120xxxxLatijnse kleine letter x
121yyyyLatijnse kleine letter y
122zzzzLatijnse kleine letter z
123{{{{linker haakje
124||||verticale streep
125}}}}rechter haakje
126~~~~tilde
128DEL    
129 ˆ  euro-teken
ˆ 130130130Latin small ligature oe
ˆ 131  ˆ
enkelvoudig lage-9 aanhalingsteken 132  ˆ
Latijnse kleine letter f met haak 133  ˆ
dubbele lage-9 aanhalingsteken ...  horizontale ellips
134 ˆ  zwaaiende meteervork
135 ˇ  dubbele zwaaiende meteervork
136 ˆ  modificerend teken hoekschrift
137 ˇ  promille-teken
138 ˊ  Latijnse hoofdletter S met caron
139 ˌ  enkelvoudig linksgewijzigd hoekhalingsteken
140 ˌ  Latijnse hoofdletter ligatuur OE
141 ˇˇˇLatin small ligature oe
142 ˇ  Latijnse hoofdletter Z met caron
143 ˇˇˇLatin small ligature oe
144 ˆˆˆLatin small ligature oe
145 '  '
146 '  rechter enkelvoudig aanhalingsteken
147 "  "
148 "  rechter dubbele aanhalingsteken
149 •  
149 •  bullet
150 –  en dash
151 —  em dash
152 ˜  small tilde
153 ™  trade mark sign
154 š  Latin small letter s with caron
155 ›  single right-pointing angle quotation mark
156 œœœLatin small ligature oe
157   NOT USED
158 ž  Latin small letter z with caron
159    Ÿ
Latin capital letter Y with diaeresis 160160160no-break space
¡ inverted exclamation markinverted exclamation markinverted exclamation mark162
¢ cent signcent signcent sign163
£ pound signpound signpound sign164
¤ currency signcurrency signcurrency sign¥
yen sign 166166166¦
broken bar 167167167§
section sign 168168168¨
diaeresis 169169169©
copyright sign 170170170ª
feminine ordinal indicator 171171171«
left-pointing double angle quotation mark 172172172¬
not sign ­­­soft hyphen
174 ®®®registered sign
175 ¯¯¯macron
176 °°°degree sign
177 ±±±plus-minus sign
178 ²²²superscript two
179 ³³³superscript three
180 ´´´acute accent
181 µµµmicro sign
182 pilcrow sign
183 ···middle dot
184 ¸¸¸cedilla
185 ¹¹¹superscript one
186 ºººmasculine ordinal indicator
187 »»»right-pointing double angle quotation mark
188 ¼¼¼vulgar fraction one quarter
189 ½½½vulgar fraction one half
190 ¾¾¾vulgar fraction three quarters
191 ¿¿¿inverted question mark
192 ÀÀÀLatin capital letter A with grave
193 ÁÁÁLatin capital letter A with acute
194 ÂÂÂLatin capital letter A with circumflex
195 ÃÃÃLatin capital letter A with tilde
196 ÄÄÄLatin capital letter A with diaeresis
197 ÅÅÅLatin capital letter A with ring above
198 ÆÆÆLatin capital letter AE
199 ÇÇÇLatin capital letter C with cedilla
200 ÈÈÈLatin capital letter E with grave
201 ÉÉÉLatin capital letter E with acute
202 ÊÊÊLatin capital letter E with circumflex
203 ËËËLatin capital letter E with diaeresis
204 ÌÌÌLatin capital letter I with grave
205 ÍÍÍLatin capital letter I with acute
206 ÎÎÎLatin capital letter I with circumflex
207 ÏÏÏLatin capital letter I with diaeresis
208 ÐÐÐLatin capital letter Eth
209 ÑÑÑLatin capital letter N with tilde
210 ÒÒÒLatin capital letter O with grave
211 ÓÓÓLatin capital letter O with acute
212 ÔÔÔLatin capital letter O with circumflex
213 ÕÕÕLatin capital letter O with tilde
214 ÖÖÖLatin capital letter O with diaeresis
215 ×××multiplication sign
216 ØØØLatin capital letter O with stroke
217 ÙÙÙLatin capital letter U with grave
218 ÚÚÚLatin capital letter U with acute
219 ÛÛÛLatin capital letter U with circumflex
220 ÜÜÜLatin capital letter U with diaeresis
221 ÝÝÝLatin capital letter Y with acute
222 ÞÞÞLatin capital letter Thorn
223 ßßßLatin small letter sharp s
224 àààLatin small letter a with grave
225 áááLatin small letter a with acute
226 âââLatin small letter a with circumflex
227 ãããLatin small letter a with tilde
228 äääLatin small letter a with diaeresis
229 åååLatin small letter a with ring above
230 æææLatin small letter ae
231 çççLatin small letter c with cedilla
232 èèèLatin small letter e with grave
233 233233233é
Kleine letter e met kruis 234234234ê
Kleine letter e met cirkel 235235235ë
Kleine letter e met trema 236236236ì
Kleine letter i met streep 237237237í
Kleine letter i met kruis 238238238î
Kleine letter i met cirkel 239239239ï
Kleine letter i met trema 240240240ð
Kleine letter eth 241241241ñ
Kleine letter n met tilde 242242242ò
Kleine letter o met streep 243243243ó
Kleine letter o met kruis 244244244ô
Kleine letter o met cirkel 245245245õ
Kleine letter o met tilde 246246246ö
Kleine letter o met trema 247247247÷
delingsteken øøøKleine letter o met streep
249 ùùùKleine letter u met streep
250 úúúKleine letter u met kruis
251 ûûûKleine letter met cirkel
252 üüüKleine letter u met trema
253 ýýýKleine letter y met kruis
254 þþþKleine letter thorn
255 ÿÿÿKleine letter y met trema

ASCII-karakterset

ASCII gebruikt de waarden van 0 tot 31 (en 127) als controlekarakters.

ASCII gebruikt waarden van 32 tot 126 om letters, cijfers en symbolen te representeren.

ASCII gebruikt geen waarden van 128 tot 255.

ANSI tekenset (Windows-1252)

Voor waarden van 0 tot 127 is ANSI hetzelfde als ASCII.

ANSI heeft een set van specifieke tekens met waarden van 128 tot 159.

Voor waarden van 160 tot 255 is ANSI hetzelfde als UTF-8.

ISO-8859-1 tekenset

Voor waarden van 0 tot 127 is 8859-1 hetzelfde als ASCII.

8859-1 gebruikt geen waarden van 128 tot 159.

Voor waarden van 160 tot 255 is 8859-1 hetzelfde als UTF-8.

UTF-8 tekenset

Voor waarden van 0 tot 127 is UTF-8 hetzelfde als ASCII.

UTF-8 gebruikt geen waarden van 128 tot 159.

Voor waarden van 160 tot 255 is UTF-8 hetzelfde als ANSI en 8859-1.

UTF-8 gaat verder vanaf waarde 256 en bevat meer dan 10000 verschillende tekens.

Voor verdere verdieping, lees ons volledige HTML tekenset referenties.

@charset CSS regel

U kunt de CSS @charset regel gebruiken om de characterencoding in de stylesheet te specificeren:

Voorbeeld

Stel de encoding van de stylesheet in op Unicode UTF-8:

@charset "UTF-8";

Meer informatie kunt u vinden in onze CSS referenties. CSS @charset regel inhoud.