HTML 文档类型

所有 HTML 文档必须以 <!DOCTYPE> 声明开头。该声明并非一个 HTML 标签。它是一条“信息”,告知浏览器期望的文档类型。在 HTML5 中,<!DOCTYPE> 声明非常简单:

  1. <!DOCTYPE html>

在更老的文档中(HTML 4 或 XHTML),该声明更为复杂,因为声明必须引用 DTD (Document Type Definition)。

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

不同 DOCTYPE 中的有效 HTML 元素

标签HTML 5HTML 4XHTML
<a>YesYesYes
<abbr>YesYesYes
<acronym>NoYesYes
<address>YesYesYes
<applet>NoYesNo
<area>YesYesNo
<article>YesNoNo
<aside>YesNoNo
<audio>YesNoNo
<b>YesYesYes
<base>YesYesYes
<basefont>NoYesNo
<bdi>YesNoNo
<bdo>YesYesNo
<big>NoYesYes
<blockquote>YesYesYes
<body>YesYesYes
<br>YesYesYes
<button>YesYesYes
<canvas>YesNoNo
<caption>YesYesYes
<center>NoYesNo
<cite>YesYesYes
<code>YesYesYes
<col>YesYesNo
<colgroup>YesYesNo
<datalist>YesNoNo
<dd>YesYesYes
<del>YesYesNo
<details>YesNoNo
<dfn>YesYesYes
<dialog>YesNoNo
<dir>NoYesNo
<div>YesYesYes
<dl>YesYesYes
<dt>YesYesYes
<em>YesYesYes
<embed>YesNoNo
<fieldset>YesYesYes
<figcaption>YesNoNo
<figure>YesNoNo
<font>NoYesNo
<footer>YesNoNo
<form>YesYesYes
<frame>NoNoNo
<frameset>NoYesNo
<h1> to <h6>YesYesYes
<head>YesYesYes
<header>YesNoNo
<hr>YesYesYes
<html>YesYesYes
<i>YesYesYes
<iframe>YesYesNo
<img>YesYesYes
<input>YesYesYes
<ins>YesYesNo
<kbd>YesYesYes
<label>YesYesYes
<legend>YesYesYes
<li>YesYesYes
<link>YesYesYes
<main>YesNoNo
<map>YesYesNo
<mark>YesNoNo
<meta>YesYesYes
<meter>YesNoNo
<nav>YesNoNo
<noframes>NoYesNo
<noscript>YesYesYes
<object>YesYesYes
<ol>YesYesYes
<optgroup>YesYesYes
<option>YesYesYes
<output>YesNoNo
<p>YesYesYes
<param>YesYesYes
<pre>YesYesYes
<progress>YesNoNo
<q>YesYesYes
<rp>YesNoNo
<rt>YesNoNo
<ruby>YesNoNo
<s>YesYesNo
<samp>YesYesYes
<script>YesYesYes
<section>YesNoNo
<select>YesYesYes
<small>YesYesYes
<source>YesNoNo
<span>YesYesYes
<strike>NoYesNo
<strong>YesYesYes
<style>YesYesYes
<sub>YesYesYes
<summary>YesNoNo
<sup>YesYesYes
<table>YesYesYes
<tbody>YesYesNo
<td>YesYesYes
<textarea>YesYesYes
<tfoot>YesYesNo
<th>YesYesYes
<thead>YesYesNo
<time>YesNoNo
<title>YesYesYes
<tr>YesYesYes
<track>YesNoNo
<tt>NoYesYes
<u>YesYesNo
<ul>YesYesYes
<var>YesYesYes
<video>YesNoNo
<wbr>YesNoNo