การเข้ารหัส 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
363737373738
&ampersandampersandampersandampersand39
'apostropheapostropheapostropheapostrophe40
(left parenthesisleft parenthesisleft parenthesisleft parenthesis41
)right parenthesisright parenthesisright parenthesisright parenthesis*
asterisk++++plus sign
44,,,,comma
45----hyphen-minus
46....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
65AAAAละตินใหญ่ตัวอ A
66BBBBละตินใหญ่ตัวอ B
67CCCCละตินใหญ่ตัวอ C
68DDDDละตินใหญ่ตัวอ D
69EEEEละตินใหญ่ตัวอ E
70FFFFละตินใหญ่ตัวอ F
71GGGGละตินใหญ่ตัวอ G
72HHHHละตินใหญ่ตัวอ H
73IIIIละตินใหญ่ตัวอ I
74JJJJละตินใหญ่ตัวอ J
75KKKKละตินใหญ่ตัวอ K
76LLLLละตินใหญ่ตัวอ L
77MMMMละตินใหญ่ตัวอ M
78NNNNละตินใหญ่ตัวอ N
79OOOOละตินใหญ่ตัวอ O
8080808080P
Latin capital letter P81818181Q
Latin capital letter Q82828282R
Latin capital letter R83838383S
Latin capital letter S84848484T
Latin capital letter T85858585U
Latin capital letter U86868686V
Latin capital letter V87878787W
Latin capital letter W88888888X
Latin capital letter X89898989Y
Latin capital letter Y90909090Z
Latin capital letter Z91919191[
left square bracket92929292\
reverse solidus93939393]
right square bracket95959595^
circumflex accent____low line
96````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
114rrrrLatin small letter r
115ssssLatin small letter s
116tttt114
rr ในตัวเล็กr ในตัวเล็กr ในตัวเล็กr ในตัวเล็กs
s ในตัวเล็กttttt ในตัวเล็ก
uu ในตัวเล็กu ในตัวเล็กu ในตัวเล็กu ในตัวเล็กv
v ในตัวเล็กwwwww ในตัวเล็ก
xx ในตัวเล็กx ในตัวเล็กx ในตัวเล็กx ในตัวเล็กy
y ในตัวเล็กzzzzz ในตัวเล็ก
122{{{{วงล้อมความหมายเปิด
123||||สัญลักษณ์เส้นตรง
124}}}}วงล้อมความหมายปิด
125~~~~สัญลักษณ์ทิลดา
126DEL    
127 Ŀ  สัญลักษณ์ยูโร
128 ŀŀŀsingle right-pointing angle quotation mark
129 Ł  ข้อความน้ำตกตัว
130 ł  f ในตัวเล็กที่มีโฮค
131 Ń  ข้อความน้ำตกสองตัว
132 ...  สัญลักษณ์ข้อความสามจุด
133 ń  สัญลักษณ์แด็กเกอร์
134 Ņ  สัญลักษณ์แด็กเกอร์สอง
135 ņ  สัญลักษณ์แอ็กเซ็นต์คิวม์
136 Ň  สัญลักษณ์เปอร์เมิล
138 ň  S ในตัวใหญ่ที่มีคารอน
139 ʼn  ข้อความในวงล้อมคำนำหน้าทางซ้าย
140 Ŋ  OE ในตัวใหญ่
141 ŋŋŋsingle right-pointing angle quotation mark
142 Ō  Z ในตัวใหญ่ที่มีคารอน
143 ōōōsingle right-pointing angle quotation mark
144 ­­­single right-pointing angle quotation mark
145 '  ข้อความในวงล้อมคำนำหน้า
146 '  ข้อความในวงล้อมคำนำหลัง
147 "  ข้อความในวงล้อมคำนำหน้า
148 "  ข้อความในวงล้อมคำนำหลัง
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 small letter e with acute
234 êêêLatin small letter e with circumflex
235 ëëëLatin small letter e with diaeresis
236 ìììLatin small letter i with grave
237 íííLatin small letter i with acute
238 îîîLatin small letter i with circumflex
239 ïïïLatin small letter i with diaeresis
240 ðððLatin small letter eth
241 ñññLatin small letter n with tilde
242 òòòLatin small letter o with grave
243 óóóLatin small letter o with acute
244 ôôôLatin small letter o with circumflex
245 õõõLatin small letter o with tilde
246 öööLatin small letter o with diaeresis
247 ÷÷÷division sign
248 øøøLatin small letter o with stroke
249 ùùùLatin small letter u with grave
250 úúúLatin small letter u with acute
251 ûûûLatin small letter with circumflex
252 üüüLatin small letter u with diaeresis
253 ýýýLatin small letter y with acute
254 þþþLatin small letter thorn
255 ÿÿÿLatin small letter y with diaeresis

ASCII ชุดตัวอักษร

ASCII ใช้ค่าจาก 0 ถึง 31 (และ 127) ในระดับของตัวอักษรควบคุม。

ASCII ใช้ค่าที่อยู่ระหว่าง 32 ถึง 126 มาแสดงตัวอักษร ตัวเลข และสัญลักษณ์

ASCII ไม่ใช้ค่าที่อยู่ระหว่าง 128 ถึง 255

ตัวอักษร ANSI (Windows-1252)

สำหรับค่าที่อยู่ระหว่าง 0 ถึง 127 ตาม ANSI คล้ายกับ ASCII

ANSI มีลักษณะตัวอักษรพิเศษเฉพาะของตน ค่าที่อยู่ระหว่าง 128 ถึง 159

สำหรับค่าที่อยู่ระหว่าง 160 ถึง 255 ตาม ANSI คล้ายกับ UTF-8

ตัวอักษร ISO-8859-1

สำหรับค่าที่อยู่ระหว่าง 0 ถึง 127 ตาม 8859-1 คล้ายกับ ASCII

8859-1 ไม่ใช้ค่าที่อยู่ระหว่าง 128 ถึง 159

สำหรับค่าที่อยู่ระหว่าง 160 ถึง 255 ตาม 8859-1 คล้ายกับ UTF-8

ตัวอักษร UTF-8

สำหรับค่าที่อยู่ระหว่าง 0 ถึง 127 ตาม UTF-8 คล้ายกับ ASCII

UTF-8 ไม่ใช้ค่าที่อยู่ระหว่าง 128 ถึง 159

สำหรับค่าที่อยู่ระหว่าง 160 ถึง 255 ตาม UTF-8 คล้ายกับ ANSI และ 8859-1

UTF-8 ตั้งแต่ค่า 256 ต่อไป มีลักษณะตัวอักษรมากกว่า 10,000 ตัว

หากต้องการทราบเพิ่มเติม โปรดอ่านคู่มืออธิบายเต็มของเราเกี่ยวกับ HTML ตัวอักษร

กฎ @charset CSS

คุณสามารถใช้กฎ CSS @charset มากำหนดรหัสระบบการเขียนตัวอักษรที่ใช้ในสไตล์เซตต์ของคุณได้

ตัวอย่าง

ตั้งค่ารหัสระบบการเขียนตัวอักษรของสไตล์เซตต์เป็น Unicode UTF-8:

@charset "UTF-8";

โปรดดูคู่มือ CSS ของเราเพื่อข้อมูลเพิ่มเติม CSS @charset กฎ ของเนื้อหา