HTML 编码(字符集)

为了正确显示 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
38&&&&ampersand
3938383838&
ampersand39393939'
apostrophe40404040(
left parenthesis41414141)
right parenthesis****asterisk
+plus signplus signplus signplus sign,
comma45454545-
hyphen-minus....full stop
47////solidus
480000digit zero
491111digit one
502222digit two
513333digit three
524444digit four
535555digit five
546666digit six
557777digit seven
568888digit eight
579999digit nine
58::::colon
59;;;;semicolon
60<<<<less-than sign
61====equals sign
62>>>>greater-than sign
63????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
114114114114114r
Latin small letter r115115115115s
Latin small letter s116116116116t
Latin small letter t117117117117u
Latin small letter u118118118118v
Latin small letter v119119119119w
Latin small letter w120120120120x
Latin small letter x121121121121y
Latin small letter y122122122122z
Latin small letter z123123123123{
left curly bracket||||vertical line
125}}}}right curly bracket
126~~~~tilde
127DEL    
128 €  euro sign
129 single right-pointing angle quotation mark
130 ‚  single low-9 quotation mark
131 ƒ  Latin small letter f with hook
132 „  double low-9 quotation mark
133 …  horizontal ellipsis
134 †  dagger
135 ‡  double dagger
136 ˆ  modifier letter circumflex accent
137 ‰  per mille sign
138 Š  Latin capital letter S with caron
139 ‹  single left-pointing angle quotation mark
140 Œ  Latin capital ligature OE
141 single right-pointing angle quotation mark
142 Ž  Latin capital letter Z with caron
143 single right-pointing angle quotation mark
144 single right-pointing angle quotation mark
145 ‘  left single quotation mark
146 ’  right single quotation mark
147 “  left double quotation mark
148 ”  right double quotation mark
149 •  bullet
150 –  en dash
151 —  149
• bullet  –
en dash —  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 159159159Ÿ
Latin capital letter Y with diaeresis 160160160no-break space
¡ inverted exclamation markinverted exclamation markinverted exclamation mark¢
cent sign £££pound sign
¤ 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 éééLatin maliit na titik e na may acute
234 êêêLatin maliit na titik e na may circumflex
235 ëëëLatin maliit na titik e na may diaeresis
236 ìììLatin maliit na titik i na may grave
237 íííLatin maliit na titik i na may acute
238 îîîLatin maliit na titik i na may circumflex
239 ïïïLatin maliit na titik i na may diaeresis
240 ðððLatin maliit na titik eth
241 ñññLatin maliit na titik n na may tilde
242 òòòLatin maliit na titik o na may grave
243 óóóLatin maliit na titik o na may acute
244 ôôôLatin maliit na titik o na may circumflex
245 õõõLatin maliit na titik o na may tilde
246 öööLatin maliit na titik o na may diaeresis
247 ÷÷÷division sign
248 øøøLatin maliit na titik o na may stroke
249 ùùùLatin maliit na titik u na may grave
250 úúúLatin maliit na titik u na may acute
251 ûûûLatin maliit na titik na may circumflex
252 üüüLatin maliit na titik u na may diaeresis
253 ýýýLatin maliit na titik y na may acute
254 þþþLatin maliit na titik thorn
255 ÿÿÿLatin maliit na titik y na may diaeresis

ASCII charset

ASCII gumamit ng mga halaga mula 0 hanggang 31 (at 127) bilang kontrol na character.

ASCII uses values between 32 and 126 to represent letters, numbers, and symbols.

ASCII does not use values between 128 and 255.

ANSI Character Set (Windows-1252)

For values between 0 and 127, ANSI is the same as ASCII.

ANSI has a set of proprietary characters with values from 128 to 159.

For values between 160 and 255, ANSI is the same as UTF-8.

ISO-8859-1 Character Set

For values between 0 and 127, 8859-1 is the same as ASCII.

8859-1 does not use values between 128 and 159.

For values between 160 and 255, 8859-1 is the same as UTF-8.

UTF-8 Character Set

For values between 0 and 127, UTF-8 is the same as ASCII.

UTF-8 does not use values between 128 and 159.

For values between 160 and 255, UTF-8 is the same as ANSI and 8859-1.

UTF-8 continues from value 256, containing more than 10,000 different characters.

For a deeper understanding, please read our complete HTML Character Set Reference Manual.

CSS @charset Rule

You can use the CSS @charset rule to specify the character encoding used in the stylesheet:

Example

Set the encoding of the stylesheet to Unicode UTF-8:

@charset "UTF-8";

Get more information about it in our CSS Reference Manual. CSS @charset Rule Content.