导航
一个DOCTYPE必须包含以下部分,并严格按照顺序出现:
A string that is an ASCII case-insensitive match for the string “<!DOCTYPE”.One or more space characters.A string that is an ASCII case-insensitive match for the string “html”.Optionally, a DOCTYPE legacy string or an obsolete permitted DOCTYPE string (defined below).Zero or more space characters.A “>” (U+003E) character.
HTML文件必须加上 DOCTYPE 声明,并统一使用 HTML5 的文档声明:
<!DOCTYPE html>
Because the character sets in ISO-8859 was limited in size, and not compatible in multilingual environments, the Unicode Consortium developed the Unicode Standard.
The Unicode Standard covers (almost) all the characters, punctuations, and symbols in the world.
Unicode enables processing, storage, and transport of text independent of platform and language.
The default character encoding in HTML-5 is UTF-8.
因为 ISO-8859 中字符集大小是有限的,且在多语言环境中不兼容,所以 Unicode 联盟开发了 Unicode 标准。
Unicode 标准覆盖了(几乎)所有的字符、标点符号和符号。
Unicode 使文本的处理、存储和运输,独立于平台和语言。
HTML-5 中默认的字符编码是 UTF-8
参阅 HTML Unicode (UTF-8) Reference
一般情况下统一使用 “UTF-8” 编码
<meta charset="UTF-8">
请尽量统一写成标准的 “UTF-8”,不要写成 “utf-8” 或 “utf8” 或 “UTF8”。根据 IETF对UTF-8的定义,其编码标准的写法是 “UTF-8”;而 UTF8 或 utf8 的写法只是出现在某些编程系统中,如 .NET framework 的类 System.Text.Encoding 中的一个属性名就叫 UTF8。
UTF-8写法: UTF8 or UTF-8?
GBK:Application of IANA Charset Registration for GBK
Charset :character-encoding-declaration
HTML元素共有以下5种:
元素标签的闭合应遵循以下原则:
Tags are used to delimit the start and end of elements in the markup. Raw text, escapable raw text, and normal elements have a start tag to indicate where they begin, and an end tag to indicate where they end. The start and end tags of certain normal elements can be omitted, as described below in the section on optional tags. Those that cannot be omitted must not be omitted. Void elements only have a start tag; end tags must not be specified for void elements. Foreign elements must either have a start tag and an end tag, or a start tag that is marked as self-closing, in which case they must not have an end tag.
为了能让浏览器更好的解析代码以及能让代码具有更好的可读性,有如下约定:
推荐:
<div>
<h1>我是h1标题</h1>
<p>我是一段文字,我有始有终,浏览器能正确解析</p>
</div>
<br>
不推荐:
<div>
<h1>我是h1标题</h1>
<p>我是一段文字,我有始无终,浏览器亦能正确解析
</div>
<br/>
更多关于元素及标签关闭:#Elements
HTML 标签名、类名、标签属性和大部分属性值统一用小写
推荐:
<div class="one"></div>
不推荐:
<div class="ONE"></div>
<DIV CLASS="ONE"></DIV>
推荐:
<input type="text">
<input type="radio" name="name" checked="checked" >
不推荐:
<input type=text>
<input type='text'>
<input type="radio" name="name" checked >
更多关于元素属性:#Attributes
In certain cases described in other sections, text may be mixed with character references. These can be used to escape characters that couldn’t otherwise legally be included in text.
文本可以和字符引用混合出现。这种方法可以用来转义在文本中不能合法出现的字符。
在 HTML 中不能使用小于号 “<” 和大于号 “>”特殊字符,浏览器会将它们作为标签解析,若要正确显示,在 HTML 源代码中使用字符实体
推荐:
<a href="#">more>></a>
不推荐:
<a href="#">more>></a>