
HTML
Living Standard — Last Updated 20 November 2014
Multipage Version
whatwg.org/html
One-Page Version
html.spec.whatwg.org
PDF Version
whatwg.org/pdf
Developer Version
developers.whatwg.org
FAQ
whatwg.org/faq
Validators
validator.whatwg.org
Join our Mailing List
Join us on IRC
#whatwg on Freenode
Change Log
html5.org's tracker
View Open Bugs
filed in Bugzilla
File a Bug
whatwg.org/newbug
1

Table of contents
1 Introduction................................................................................................................................................................................................. 2
2 Common infrastructure............................................................................................................................................................................... 3
3 Semantics, structure, and APIs of HTML documents................................................................................................................................. 4
4 The elements of HTML............................................................................................................................................................................... 5
5 Microdata.................................................................................................................................................................................................. 12
6 User interaction ........................................................................................................................................................................................ 13
7 Loading Web pages ................................................................................................................................................................................. 13
8 Web application APIs ............................................................................................................................................................................... 15
9 Communication ........................................................................................................................................................................................ 16
10 Web workers........................................................................................................................................................................................... 16
11 Web storage ........................................................................................................................................................................................... 17
12 The HTML syntax ................................................................................................................................................................................... 18
13 The XHTML syntax................................................................................................................................................................................. 20
14 Rendering............................................................................................................................................................................................... 20
15 Obsolete features ................................................................................................................................................................................... 21
16 IANA considerations............................................................................................................................................................................... 22
Index............................................................................................................................................................................................................ 22
References .................................................................................................................................................................................................. 22
Acknowledgements ..................................................................................................................................................................................... 22
Full table of contents
1 Introduction............................................................................................................................................................................................... 23
1.1 Where does this specification fit?........................................................................................................................................ 23
1.2 Is this HTML5? .................................................................................................................................................................... 23
1.3 Background ......................................................................................................................................................................... 23
1.4 Audience ............................................................................................................................................................................. 24
1.5 Scope .................................................................................................................................................................................. 24
1.6 History ................................................................................................................................................................................. 24
1.7 Design notes ....................................................................................................................................................................... 25
1.7.1 Serialisability of script execution .................................................................................................................... 25
1.7.2 Compliance with other specifications ............................................................................................................. 26
1.7.3 Extensibility..................................................................................................................................................... 26
1.8 HTML vs XHTML................................................................................................................................................................. 26
1.9 Structure of this specification .............................................................................................................................................. 27
1.9.1 How to read this specification......................................................................................................................... 28
1.9.2 Typographic conventions ............................................................................................................................... 28
1.10 Privacy concerns ............................................................................................................................................................... 29
1.10.1 Cross-site communication ............................................................................................................................ 30
1.11 A quick introduction to HTML ............................................................................................................................................ 30
1.11.1 Writing secure applications with HTML ........................................................................................................ 32
1.11.2 Common pitfalls to avoid when using the scripting APIs.............................................................................. 34
1.11.3 How to catch mistakes when writing HTML: validators and conformance checkers .................................... 34
1.12 Conformance requirements for authors............................................................................................................................. 35
1.12.1 Presentational markup ................................................................................................................................. 35
1.12.2 Syntax errors ................................................................................................................................................ 35
1.12.3 Restrictions on content models and on attribute values............................................................................... 38
1.13 Suggested reading ............................................................................................................................................................ 39
2

2 Common infrastructure............................................................................................................................................................................. 41
2.1 Terminology......................................................................................................................................................................... 41
2.1.1 Resources ...................................................................................................................................................... 41
2.1.2 XML ................................................................................................................................................................ 42
2.1.3 DOM trees ...................................................................................................................................................... 42
2.1.4 Scripting.......................................................................................................................................................... 43
2.1.5 Plugins............................................................................................................................................................ 43
2.1.6 Character encodings ...................................................................................................................................... 44
2.2 Conformance requirements................................................................................................................................................. 44
2.2.1 Conformance classes..................................................................................................................................... 45
2.2.2 Dependencies ................................................................................................................................................ 47
2.2.3 Extensibility..................................................................................................................................................... 56
2.2.4 Interactions with XPath and XSLT.................................................................................................................. 57
2.3 Case-sensitivity and string comparison............................................................................................................................... 58
2.4 Common microsyntaxes...................................................................................................................................................... 58
2.4.1 Common parser idioms .................................................................................................................................. 58
2.4.2 Boolean attributes .......................................................................................................................................... 60
2.4.3 Keywords and enumerated attributes............................................................................................................. 60
2.4.4 Numbers......................................................................................................................................................... 60
2.4.4.1 Signed integers ......................................................................................................................... 60
2.4.4.2 Non-negative integers ............................................................................................................... 61
2.4.4.3 Floating-point numbers.............................................................................................................. 61
2.4.4.4 Percentages and lengths........................................................................................................... 63
2.4.4.5 Lists of integers ......................................................................................................................... 64
2.4.4.6 Lists of dimensions.................................................................................................................... 66
2.4.5 Dates and times.............................................................................................................................................. 66
2.4.5.1 Months....................................................................................................................................... 67
2.4.5.2 Dates ......................................................................................................................................... 68
2.4.5.3 Yearless dates........................................................................................................................... 68
2.4.5.4 Times......................................................................................................................................... 69
2.4.5.5 Local dates and times ............................................................................................................... 70
2.4.5.6 Time zones................................................................................................................................ 71
2.4.5.7 Global dates and times.............................................................................................................. 72
2.4.5.8 Weeks........................................................................................................................................ 74
2.4.5.9 Durations ................................................................................................................................... 75
2.4.5.10 Vaguer moments in time ......................................................................................................... 78
2.4.6 Colours ........................................................................................................................................................... 78
2.4.7 Space-separated tokens ................................................................................................................................ 80
2.4.8 Comma-separated tokens .............................................................................................................................. 81
2.4.9 References ..................................................................................................................................................... 81
2.4.10 Media queries............................................................................................................................................... 81
2.5 URLs.................................................................................................................................................................................... 82
2.5.1 Terminology.................................................................................................................................................... 82
2.5.2 Resolving URLs.............................................................................................................................................. 82
2.5.3 Dynamic changes to base URLs .................................................................................................................... 83
2.6 Fetching resources.............................................................................................................................................................. 83
2.6.1 Terminology.................................................................................................................................................... 83
2.6.2 Processing model........................................................................................................................................... 84
2.6.3 Encrypted HTTP and related security concerns............................................................................................. 86
3

2.6.4 Determining the type of a resource ................................................................................................................ 86
2.6.5 Extracting character encodings from meta elements..................................................................................... 86
2.6.6 CORS settings attributes................................................................................................................................ 87
2.6.7 CORS-enabled fetch ...................................................................................................................................... 87
2.7 Common DOM interfaces.................................................................................................................................................... 88
2.7.1 Reflecting content attributes in IDL attributes................................................................................................. 88
2.7.2 Collections...................................................................................................................................................... 90
2.7.2.1 The HTMLAllCollection interface........................................................................................ 90
2.7.2.2 The HTMLFormControlsCollection interface .................................................................... 91
2.7.2.3 The HTMLOptionsCollection interface ............................................................................... 93
2.7.2.4 The HTMLPropertiesCollection interface......................................................................... 95
2.7.3 The DOMStringMap interface........................................................................................................................ 96
2.7.4 DOMElementMap........................................................................................................................................... 97
2.7.5 Transferable objects....................................................................................................................................... 97
2.7.6 Safe passing of structured data...................................................................................................................... 98
2.7.7 Callbacks...................................................................................................................................................... 101
2.7.8 Garbage collection ....................................................................................................................................... 101
2.8 Namespaces...................................................................................................................................................................... 101
3 Semantics, structure, and APIs of HTML documents............................................................................................................................. 102
3.1 Documents ........................................................................................................................................................................ 102
3.1.1 The Document object .................................................................................................................................. 102
3.1.2 Resource metadata management ................................................................................................................ 103
3.1.3 DOM tree accessors..................................................................................................................................... 105
3.1.4 Loading XML documents.............................................................................................................................. 109
3.2 Elements............................................................................................................................................................................ 109
3.2.1 Semantics..................................................................................................................................................... 109
3.2.2 Elements in the DOM ................................................................................................................................... 111
3.2.3 Element definitions ....................................................................................................................................... 112
3.2.3.1 Attributes ................................................................................................................................. 113
3.2.4 Content models ............................................................................................................................................ 113
3.2.4.1 The "nothing" content model ................................................................................................... 114
3.2.4.2 Kinds of content....................................................................................................................... 114
3.2.4.2.1 Metadata content................................................................................................ 115
3.2.4.2.2 Flow content ....................................................................................................... 115
3.2.4.2.3 Sectioning content.............................................................................................. 116
3.2.4.2.4 Heading content ................................................................................................. 116
3.2.4.2.5 Phrasing content ................................................................................................ 116
3.2.4.2.6 Embedded content ............................................................................................. 116
3.2.4.2.7 Interactive content .............................................................................................. 116
3.2.4.2.8 Palpable content................................................................................................. 117
3.2.4.2.9 Script-supporting elements................................................................................. 117
3.2.4.3 Transparent content models.................................................................................................... 117
3.2.4.4 Paragraphs.............................................................................................................................. 118
3.2.5 Global attributes ........................................................................................................................................... 120
3.2.5.1 The id attribute....................................................................................................................... 122
3.2.5.2 The title attribute................................................................................................................. 122
3.2.5.3 The lang and xml:lang attributes........................................................................................ 123
3.2.5.4 The translate attribute........................................................................................................ 124
3.2.5.5 The xml:base attribute (XML only)........................................................................................ 125
4

3.2.5.6 The dir attribute..................................................................................................................... 125
3.2.5.7 The class attribute................................................................................................................. 128
3.2.5.8 The style attribute................................................................................................................. 128
3.2.5.9 Embedding custom non-visible data with the data-* attributes ............................................128
3.2.6 Requirements relating to the bidirectional algorithm .................................................................................... 131
3.2.6.1 Authoring conformance criteria for bidirectional-algorithm formatting characters ...................131
3.2.6.2 User agent conformance criteria ............................................................................................. 132
3.2.7 Annotations for assistive technology products (ARIA) ................................................................................. 132
4 The elements of HTML........................................................................................................................................................................... 137
4.1 The root element ............................................................................................................................................................... 137
4.1.1 The html element........................................................................................................................................ 137
4.2 Document metadata .......................................................................................................................................................... 138
4.2.1 The head element........................................................................................................................................ 138
4.2.2 The title element...................................................................................................................................... 139
4.2.3 The base element........................................................................................................................................ 140
4.2.4 The link element........................................................................................................................................ 141
4.2.5 The meta element........................................................................................................................................ 145
4.2.5.1 Standard metadata names ...................................................................................................... 147
4.2.5.2 Other metadata names............................................................................................................ 148
4.2.5.3 Pragma directives.................................................................................................................... 149
4.2.5.4 Other pragma directives .......................................................................................................... 152
4.2.5.5 Specifying the document's character encoding....................................................................... 152
4.2.6 The style element...................................................................................................................................... 153
4.2.7 Interactions of styling and scripting .............................................................................................................. 157
4.3 Sections............................................................................................................................................................................. 157
4.3.1 The body element........................................................................................................................................ 157
4.3.2 The article element ................................................................................................................................. 159
4.3.3 The section element ................................................................................................................................. 161
4.3.4 The nav element.......................................................................................................................................... 163
4.3.5 The aside element...................................................................................................................................... 166
4.3.6 The h1, h2, h3, h4, h5, and h6 elements.................................................................................................... 168
4.3.7 The hgroup element.................................................................................................................................... 170
4.3.8 The header element.................................................................................................................................... 171
4.3.9 The footer element.................................................................................................................................... 173
4.3.10 The address element ............................................................................................................................... 175
4.3.11 Headings and sections ............................................................................................................................... 176
4.3.11.1 Creating an outline ................................................................................................................ 178
4.3.11.2 Sample outlines..................................................................................................................... 181
4.3.11.3 Exposing outlines to users .................................................................................................... 185
4.3.12 Usage summary ......................................................................................................................................... 186
4.3.12.1 Article or section?.................................................................................................................. 187
4.4 Grouping content............................................................................................................................................................... 187
4.4.1 The p element .............................................................................................................................................. 187
4.4.2 The hr element ............................................................................................................................................ 190
4.4.3 The pre element.......................................................................................................................................... 191
4.4.4 The blockquote element........................................................................................................................... 193
4.4.5 The ol element ............................................................................................................................................ 195
5
- 1
- 2
- 3
- 4
- 5
- 6
前往页