Setting Chinese in HTML with UTF-8 includes: setting charset in the <head> tag; using Unicode to directly input Chinese; using HTML entities to represent Chinese; specifying fonts that support Chinese in CSS; using JavaScript The document.charset property sets the character set.
How to set HTML Chinese
Set directly
in HTML In the document, you can set charset
in the <head>
tag to specify the character set as UTF-8.
<code class="html"><head> <meta charset="UTF-8"> ... </head></code>
Using Unicode
Unicode is an international encoding standard that covers characters for most of the world's languages. You can input Chinese directly using Unicode encoding.
For example:
<code class="html"><h1>你好,世界!</h1></code>
Using HTML entities
HTML entities are alternative representations of special characters. You can use the following entities to represent Chinese in HTML:
Characters | Entity |
---|---|
你 | 你 |
中 | |
于 | |
皶 |
: <code class="html"><h1>你中, 於皶!</h1></code>
You can use the
font-family attribute to specify the font in CSS. The following example uses a font that supports Chinese: <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><code class="css">body {
font-family: "Noto Sans CJK SC", "Microsoft YaHei", "SimSun";
}</code></pre><div class="contentsignin">Copy after login</div></div>
You can use JavaScript’s
document.charset property to set the character set. <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><code class="js">document.charset = "UTF-8";</code></pre><div class="contentsignin">Copy after login</div></div>
The above is the detailed content of How to set Chinese in html. For more information, please follow other related articles on the PHP Chinese website!