HTML特殊转义字符对照表

文章2019-05-2839 人已阅来源:网络

为什么要用转义字符串?

HTML中<,>,&等有特殊含义(<,>,用于链接签,&用于转义),不能直接使用。这些符号是不显示在我们最终看到的网页里的,那如果我们希望在网页中显示这些符号,该怎么办呢?

这就要说到HTML转义字符串(Escape Sequence)了。

转义字符串(Escape Sequence)也称字符实体(Character Entity)。在HTML中,定义转义字符串的原因有两个:第一个原因是像“<”和“>”这类符号已经用来表示HTML标签,因此就不能直接当作文本中的符号来使用。为了在HTML文档中使用这些符号,就需要定义它的转义字符串。当解释程序遇到这类字符串时就把它解释为真实的字符。在输入转义字符串时,要严格遵守字母大小写的规则。第二个原因是,有些字符在ASCII字符集中没有定义,因此需要使用转义字符串来表示。

转义字符串的组成

转义字符串(Escape Sequence),即字符实体(Character Entity)分成三部分:第一部分是一个&符号,英文叫ampersand;第二部分是实体(Entity)名字或者是#加上实体(Entity)编号;第三部分是一个分号。

比如,要显示小于号(<),就可以写 < 或者 < 。

用实体(Entity)名字的好处是比较好理解,一看lt,大概就猜出是less than的意思,但是其劣势在于并不是所有的浏览器都支持最新的Entity名字。而实体(Entity)编号,各种浏览器都能处理。

提示:实体名称(Entity)是区分大小写的。

备注:同一个符号,可以用“实体名称”和“实体编号”两种方式引用,“实体名称”的优势在于便于记忆,但不能保证所有的浏览器都能顺利识别它,而“实体编号”则没有这种担忧,但它实在不方便记忆。

如何显示空格?

通常情况下,HTML会自动截去多余的空格。不管你加多少空格,都被看做一个空格。比如你在两个字之间加了10个空格,HTML会截去9个空格,只保留一个。为了在网页中增加空格,你可以使用 表示空格。

HTML特殊转义字符对照表(较多,慢慢看)

特殊符号 命名实体 十进制编码 特殊符号 命名实体 十进制编码
&#32; ! &#33;
" &quot; &#34; # &#35;
$ &#36; % &#37;
& &amp; &#38; ' &#39;
( &#40; ) &#41;
* &#42; + &#43;
, &#44; - &#45;
. &#46; / &#47;
0 &#48; 1 &#49;
2 &#50; 3 &#51;
4 &#52; 5 &#53;
6 &#54; 7 &#55;
8 &#56; 9 &#57;
: &#58; ; &#59;
< &lt; &#60; = &#61;
> &gt; &#62; &#63; &#63;
@ &#64; A &#65;
B &#66; C &#67;
D &#68; E &#69;
F &#70; G &#71;
H &#72; I &#73;
J &#74; K &#75;
L &#76; M &#77;
N &#78; O &#79;
P &#80; Q &#81;
R &#82; S &#83;
T &#84; U &#85;
V &#86; W &#87;
X &#88; Y &#89;
Z &#90; [ &#91;
\ &#92; ] &#93;
^ &#94; _ &#95;
` &#96; a &#97;
b &#98; c &#99;
d &#100; e &#101;
f &#102; g &#103;
h &#104; i &#105;
j &#106; k &#107;
l &#108; m &#109;
n &#110; o &#111;
p &#112; q &#113;
r &#114; s &#115;
t &#116; u &#117;
v &#118; w &#119;
x &#120; y &#121;
z &#122; { &#123;
| &#124; } &#125;
~ &#126; &#127;
&#128; &#129; &#129;
&#130; ƒ &#131;
&#132; &#133;
&#134; &#135;
ˆ &#136; &#137;
Š &#138; &#139;
Π&#140; &#141; &#141;
&#142; &#142; &#143; &#143;
&#144; &#144; &#145;
&#146; &#147;
&#148; &#149;
&#150; &#151;
˜ &#152; &#153;
š &#154; &#155;
œ &#156; &#157; &#157;
&#158; &#158; Ÿ &#159;
&nbsp; &#160; ¡ &iexcl; &#161;
¢ &cent; &#162; £ &pound; &#163;
¤ &curren; &#164; ¥ &yen; &#165;
¦ &brvbar; &#166; § &sect; &#167;
¨ &uml; &#168; © &copy; &#169;
ª &ordf; &#170; « &laquo; &#171;
¬ &not; &#172; &shy; &#173;
® &reg; &#174; ¯ &macr; &#175;
° &deg; &#176; ± &plusmn; &#177;
² &sup2; &#178; ³ &sup3; &#179;
´ &acute; &#180; µ &micro; &#181;
&para; &#182; · &middot; &#183;
¸ &cedil; &#184; ¹ &sup1; &#185;
º &ordm; &#186; » &raquo; &#187;
¼ &frac14; &#188; ½ &frac12; &#189;
¾ &frac34; &#190; ¿ &iquest; &#191;
À &Agrave; &#192; Á &Aacute; &#193;
 &Acirc; &#194; à &Atilde; &#195;
Ä &Auml; &#196; Å &Aring; &#197;
Æ &AElig; &#198; Ç &Ccedil; &#199;
È &Egrave; &#200; É &Eacute; &#201;
Ê &Ecirc; &#202; Ë &Euml; &#203;
Ì &Igrave; &#204; Í &Iacute; &#205;
Î &Icirc; &#206; Ï &Iuml; &#207;
Ð &ETH; &#208; Ñ &Ntilde; &#209;
Ò &Ograve; &#210; Ó &Oacute; &#211;
Ô &Ocirc; &#212; Õ &Otilde; &#213;
Ö &Ouml; &#214; × &times; &#215;
Ø &Oslash; &#216; Ù &Ugrave; &#217;
Ú &Uacute; &#218; Û &Ucirc; &#219;
Ü &Uuml; &#220; Ý &Yacute; &#221;
Þ &THORN; &#222; ß &szlig; &#223;
à &agrave; &#224; á &aacute; &#225;
â &acirc; &#226; ã &atilde; &#227;
ä &auml; &#228; å &aring; &#229;
æ &aelig; &#230; ç &ccedil; &#231;
è &egrave; &#232; é &eacute; &#233;
ê &ecirc; &#234; ë &euml; &#235;
ì &igrave; &#236; í &iacute; &#237;
î &icirc; &#238; ï &iuml; &#239;
ð &eth; &#240; ñ &ntilde; &#241;
ò &ograve; &#242; ó &oacute; &#243;
ô &ocirc; &#244; õ &otilde; &#245;
ö &ouml; &#246; ÷ &divide; &#247;
ø &oslash; &#248; ù &ugrave; &#249;
ú &uacute; &#250; û &ucirc; &#251;
ü &uuml; &#252; ý &yacute; &#253;
þ &thorn; &#254; ÿ &yuml; &#255;
Œ &OElig; &#338; œ &oelig; &#339;
Š &Scaron; &#352; š &scaron; &#353;
Ÿ &Yuml; &#376; ƒ &fnof; &#402;
ˆ &circ; &#710; ˜ &tilde; &#732;
Α &Alpha; &#913; Β &Beta; &#914;
Γ &Gamma; &#915; Δ &Delta; &#916;
Ε &Epsilon; &#917; Ζ &Zeta; &#918;
Η &Eta; &#919; Θ &Theta; &#920;
Ι &Iota; &#921; Κ &Kappa; &#922;
Λ &Lambda; &#923; Μ &Mu; &#924;
Ν &Nu; &#925; Ξ &Xi; &#926;
Ο &Omicron; &#927; Π &Pi; &#928;
Ρ &Rho; &#929; Σ &Sigma; &#931;
Τ &Tau; &#932; Υ &Upsilon; &#933;
Φ &Phi; &#934; Χ &Chi; &#935;
Ψ &Psi; &#936; Ω &Omega; &#937;
α &alpha; &#945; β &beta; &#946;
γ &gamma; &#947; δ &delta; &#948;
ε &epsilon; &#949; ζ &zeta; &#950;
η &eta; &#951; θ &theta; &#952;
ι &iota; &#953; κ &kappa; &#954;
λ &lambda; &#955; μ &mu; &#956;
ν &nu; &#957; ξ &xi; &#958;
ο &omicron; &#959; π &pi; &#960;
ρ &rho; &#961; ς &sigmaf; &#962;
σ &sigma; &#963; τ &tau; &#964;
υ &upsilon; &#965; φ &phi; &#966;
χ &chi; &#967; ψ &psi; &#968;
ω &omega; &#969; ϑ &thetasym; &#977;
ϒ &upsih; &#978; ϖ &piv; &#982;
&ensp; &#8194; &emsp; &#8195;
&thinsp; &#8201; &zwnj; &#8204;
&zwj; &#8205; &lrm; &#8206;
&rlm; &#8207; &ndash; &#8211;
&mdash; &#8212; &lsquo; &#8216;
&rsquo; &#8217; &sbquo; &#8218;
&ldquo; &#8220; &rdquo; &#8221;
&bdquo; &#8222; &dagger; &#8224;
&Dagger; &#8225; &bull; &#8226;
&hellip; &#8230; &permil; &#8240;
&prime; &#8242; &Prime; &#8243;
&lsaquo; &#8249; &rsaquo; &#8250;
&oline; &#8254; &frasl; &#8260;
&#8364; &#8369;
&#8377; &#8451;
&#8453; &#8457;
&image; &#8465; &#8470;
&#8471; &weierp; &#8472;
&real; &#8476; &#8478; &#8478;
&#8471; &trade; &#8482;
&alefsym; &#8501; &#8531; &#8531;
&#8532; &#8532; &#8539; &#8539;
&#8540; &#8540; &#8541; &#8541;
&larr; &#8592; &uarr; &#8593;
&rarr; &#8594; &darr; &#8595;
&harr; &#8596; &#8597;
&#8602; &#8603;
&#8606; &#8607;
&#8608; &#8609;
&#8610; &#8611;
&#8619;
&#8620; &#8621;
&#8622; &#8623;
&crarr; &#8629; &#8644;
&#8630; &#8631;
&#8634; &#8635;
&#8645; &lArr; &#8656;
&uArr; &#8657; &rArr; &#8658;
&dArr; &#8659; &hArr; &#8660;
&#8668; &#8669;
&#8670; &#8671;
&#8672; &#8673;
&#8674; &#8675;
&#8678; &#8679;
&#8680; &#8681;
&#8693;
&forall; &#8704; &part; &#8706;
&exist; &#8707; &empty; &#8709;
&nabla; &#8711; &isin; &#8712;
&notin; &#8713; &ni; &#8715;
&prod; &#8719; &sum; &#8722;
&minus; &#8722; &lowast; &#8727;
&radic; &#8730; &prop; &#8733;
&infin; &#8734; &ang; &#8736;
&#8764; &#8800;
&and; &#8869; &or; &#8870;
&cap; &#8745; &cup; &#8746;
&int; &#8747; &there4; &#8756;
&sim; &#8764; &cong; &#8773;
&asymp; &#8773; &ne; &#8800;
&equiv; &#8801; &le; &#8804;
&ge; &#8805; &sub; &#8834;
&sup; &#8835; &nsub; &#8836;
&sube; &#8838; &supe; &#8839;
&oplus; &#8853; &otimes; &#8855;
&perp; &#8869; &sdot; &#8901;
&lceil; &#8968; &rceil; &#8969;
&lfloor; &#8970; &rfloor; &#8971;
&loz; &#9674; &spades; &#9824;
&clubs; &#9827; &hearts; &#9829;
特殊符号 命名实体 十进制编码 特殊符号 命名实体 十进制编码
&#9635; &#9650;
&#9658; &#9660;
&#9668; &#9670;
&#9672; &#9702;
&#9728; &#9729;
&#9730; &#9731;
&#9732; &#9733;
&#9734; &#9742;
&#9743; &#9744;
&#9745; &#9746;
&#9756; &#9757;
&#9758; &#9759;
&#9760; &#9762;
&#9763; &#9764;
&#9765; &#9768;
&#9769; &#9770;
&#9774; &#9775;
&#9784; &#9785;
&#9786; &#9787;
&#9789; &#9790;
&#9791; &#9792;
&#9793; &#9794;
&#9795; &#9796;
&#9797; &#9798;
&#9799; &#; &#;
&#9800; &#9801;
&#9802; &#9803;
&#9804; &#9805;
&#9806; &#9807;
&#9809; &#9810;
&#9811; &#9812;
&#9813; &#9814;
&#9815; &#9816;
&#9817; &#9818;
&#9819; &#9820;
&#9821; &#9822;
&#9823; &#9825;
&#9826; &#9828;
&#9830; &#9831;
&#9833; &#9834;
&#9835; &#9836;
&#9837; &#9839;
&#9888; &#9986;
&#9988; &#9990;
&#9992; &#9993;
&#9996; &#9997;
&#9998; &#9999;
&#10000; &#10001;
&#10002; &#10003;
&#10004; &#10005;
&#10006; &#10007;
&#10008; &#10009;
&#10010; &#10011;
&#10013; &#10014;
&#10015; &#10016;
&#10017; &#10018;
&#10019; &#10020;
&#10019; &#10020;
&#10021; &#10022;
&#10026; &#10029;
&#10030; &#10031;
&#10033; &#10034;
&#10035; &#10036;
&#10037; &#10038;
&#10040; &#10041;
&#10042; &#10043;
&#10045; &#10047;
&#10048; &#10049;
&#10050; &#10052;
&#10053; &#10054;
&#10056; &#10059;
&#10084; &#10086;
&#10132; &#10137;
&#10140; &#10142;
&#10143; &#10144;
&#10148; &#10149;
&#10150; &#10151;
&#10152; &#10162;
&#10163; &#10165;
&#10168; &#10170;
&#10172; &#10173;
&#10174; &#10224;
&#10225; &#10226;
&#10227;

如以上列表中不包含,可运行下面代码查看全部字符。另外,不同浏览器显示的可能会有所不同,建议用谷歌浏览器。

运行可能会有所卡顿

运行代码
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>HTML特殊字符大全</title>
</head>
<body>
    <script>
        var html = [];
        html.push("<table border='1' cellpadding='5' cellspacing='0' bordercolor='#77a594' style='border-collapse:collapse'>");
        html.push("<tr><td width='40'>符号</td><td width='80'>编码</td><td width='40'>符号</td><td width='80'>编码</td><td width='40'>符号</td><td width='80'>编码</td><td width='40'>符号</td><td width='80'>编码</td></tr>");
        for (var i = 1; i <= 65536; i++) {
            if (i % 4 == 1) {
                html.push("<tr>");
            }
            html.push("<td>&#" + i + ";</td><td><span style='font-family: monospace;font-size:14px; white-space: pre-wrap;'>&amp;</span>#" + i + ";</td>");
            if (i % 4 == 0) {
                html.push("</tr>");
            }
        }
        document.write(html.join(""));
    </script>
</body>
</html>