HTML5 (including next generation additions still in development) Draft Standard — 7 April 2010 You can take part in this work. Join the working group's discussion list. Web designers! We have a FAQ, a forum, and a help mailing list for you! Multiple-page version: http://whatwg.org/html5 One-page version: http://www.whatwg.org/specs/web-apps/current-work/ PDF print versions: A4: http://www.whatwg.org/specs/web-apps/current-work/html5-a4.pdf Letter: http://www.whatwg.org/specs/web-apps/current-work/html5-letter.pdf Version history: Twitter messages (non-editorial changes only): http://twitter.com/WHATWG Commit-Watchers mailing list: http://lists.whatwg.org/listinfo.cgi/commit-watchers-whatwg.org Interactive Web interface: http://html5.org/tools/web-apps-tracker Subversion interface: http://svn.whatwg.org/ Issues: To send feedback: whatwg@whatwg.org To view and vote on feedback: http://www.whatwg.org/issues/ Editor: Ian Hickson, Google, ian@hixie.ch © Copyright 2004-2010 Apple Computer, Inc., Mozilla Foundation, and Opera Software ASA. You are granted a license to use, reproduce and create derivative works of this document. Abstract This specification evolves HTML and its related APIs to ease the authoring of Web-based applications. The most recent additions include a device p381 element to enable video conferencing, as well as all the features added as part of the earlier HTML5 effort. 1 Status of this document This is a work in progress! This document is changing on a daily if not hourly basis in response to comments and as a general part of its development process. Comments are very welcome, please send them to whatwg@whatwg.org. Thank you. Outstanding feedback is tracked; all e-mails sent to the list above receive a reply. The level of outstanding feedback is charted to allow progress to be evaluated. Implementors should be aware that this specification is not stable. Implementors who are not taking part in the discussions are likely to find the specification changing out from under them in incompatible ways. Vendors interested in implementing this specification before it eventually reaches the call for implementations should join the WHATWG mailing list and take part in the discussions. This specification is intended to replace (be the new version of) what was previously the HTML5, HTML4, XHTML1, and DOM2 HTML specifications. 2 Table of contents 1 Introduction ........................................................................................................................................... 15 1.1 Is this HTML5?..................................................................................................................... 15 1.2 Background......................................................................................................................... 15 1.3 Audience............................................................................................................................. 15 1.4 Scope.................................................................................................................................. 16 1.5 History ................................................................................................................................ 16 1.6 Design notes....................................................................................................................... 17 1.6.1 Serializability of script execution ..................................................................... 17 1.6.2 Compliance with other specifications............................................................... 17 1.7 HTML vs XHTML .................................................................................................................. 17 1.8 Structure of this specification ............................................................................................. 18 1.8.1 How to read this specification .......................................................................... 19 1.8.2 Typographic conventions ................................................................................. 19 1.9 A quick introduction to HTML .............................................................................................. 19 1.10 Conformance requirements for authors ............................................................................ 21 1.10.1 Presentational markup ................................................................................... 21 1.10.2 Syntax errors ................................................................................................. 22 1.10.3 Restrictions on content models and on attribute values ................................ 23 1.11 Recommended reading..................................................................................................... 25 2 Common infrastructure ......................................................................................................................... 26 2.1 Terminology ........................................................................................................................ 26 2.1.1 Resources ........................................................................................................ 26 2.1.2 XML .................................................................................................................. 26 2.1.3 DOM trees ........................................................................................................ 27 2.1.4 Scripting........................................................................................................... 27 2.1.5 Plugins ............................................................................................................. 27 2.1.6 Character encodings ........................................................................................ 28 2.2 Conformance requirements ................................................................................................ 28 2.2.1 Dependencies .................................................................................................. 31 2.2.2 Extensibility ..................................................................................................... 32 2.3 Case-sensitivity and string comparison .............................................................................. 33 2.4 Common microsyntaxes ..................................................................................................... 33 2.4.1 Common parser idioms .................................................................................... 34 2.4.2 Boolean attributes ........................................................................................... 34 2.4.3 Keywords and enumerated attributes .............................................................. 34 2.4.4 Numbers .......................................................................................................... 35 2.4.4.1 Non-negative integers................................................................... 35 2.4.4.2 Signed integers ............................................................................. 35 2.4.4.3 Real numbers ................................................................................ 36 2.4.4.4 Percentages and lengths ............................................................... 37 2.4.4.5 Lists of integers............................................................................. 38 2.4.4.6 Lists of dimensions........................................................................ 40 2.4.5 Dates and times............................................................................................... 40 2.4.5.1 Months .......................................................................................... 41 2.4.5.2 Dates............................................................................................. 41 2.4.5.3 Times ............................................................................................ 42 2.4.5.4 Local dates and times ................................................................... 43 2.4.5.5 Global dates and times ................................................................. 44 2.4.5.6 Weeks............................................................................................ 45 2.4.5.7 Vaguer moments in time ............................................................... 46 2.4.6 Colors............................................................................................................... 47 2.4.7 Space-separated tokens................................................................................... 49 2.4.8 Comma-separated tokens ................................................................................ 50 2.4.9 References ....................................................................................................... 50 2.4.10 Media queries ................................................................................................ 51 2.5 URLs ................................................................................................................................... 51 2.5.1 Terminology ..................................................................................................... 51 2.5.2 Dynamic changes to base URLs ....................................................................... 52 2.5.3 Interfaces for URL manipulation....................................................................... 53 2.6 Fetching resources.............................................................................................................. 55 2.6.1 Protocol concepts............................................................................................. 56 2.6.2 Encrypted HTTP and related security concerns................................................ 57 2.6.3 Determining the type of a resource ................................................................. 57 2.7 Common DOM interfaces .................................................................................................... 57 2.7.1 Reflecting content attributes in IDL attributes ................................................. 57 3 2.7.2 Collections ....................................................................................................... 59 2.7.2.1 HTMLCollection.............................................................................. 59 2.7.2.2 HTMLAllCollection.......................................................................... 60 2.7.2.3 HTMLFormControlsCollection......................................................... 61 2.7.2.4 HTMLOptionsCollection ................................................................. 62 2.7.2.5 HTMLPropertiesCollection.............................................................. 64 2.7.3 DOMTokenList................................................................................................... 65 2.7.4 DOMSettableTokenList ..................................................................................... 67 2.7.5 Safe passing of structured data ....................................................................... 67 2.7.6 DOMStringMap ................................................................................................. 69 2.7.7 DOM feature strings ......................................................................................... 69 2.7.8 Exceptions ....................................................................................................... 70 2.7.9 Garbage collection ........................................................................................... 70 2.8 Namespaces ....................................................................................................................... 70 3 Semantics, structure, and APIs of HTML documents.............................................................................. 71 3.1 Documents ......................................................................................................................... 71 3.1.1 Documents in the DOM .................................................................................... 71 3.1.2 Security............................................................................................................ 73 3.1.3 Resource metadata management .................................................................... 73 3.1.4 DOM tree accessors ......................................................................................... 75 3.1.5 Creating documents......................................................................................... 79 3.2 Elements............................................................................................................................. 79 3.2.1 Semantics ........................................................................................................ 79 3.2.2 Elements in the DOM ....................................................................................... 80 3.2.3 Global attributes .............................................................................................. 82 3.2.3.1 The id attribute ............................................................................ 84 3.2.3.2 The title attribute....................................................................... 84 3.2.3.3 The lang and xml:lang attributes ................................................ 85 3.2.3.4 The xml:base attribute (XML only) ............................................... 85 3.2.3.5 The dir attribute........................................................................... 86 3.2.3.6 The class attribute....................................................................... 86 3.2.3.7 The style attribute....................................................................... 86 3.2.3.8 Embedding custom non-visible data ............................................. 87 3.2.4 Element definitions .......................................................................................... 89 3.2.5 Content models................................................................................................ 89 3.2.5.1 Kinds of content ............................................................................ 90 3.2.5.1.1 Metadata content ....................................................... 90 3.2.5.1.2 Flow content ............................................................... 91 3.2.5.1.3 Sectioning content...................................................... 91 3.2.5.1.4 Heading content ......................................................... 91 3.2.5.1.5 Phrasing content ........................................................ 91 3.2.5.1.6 Embedded content ..................................................... 92 3.2.5.1.7 Interactive content ..................................................... 92 3.2.5.2 Transparent content models.......................................................... 93 3.2.5.3 Paragraphs .................................................................................... 93 3.2.6 Annotations for assistive technology products (ARIA)...................................... 95 3.3 APIs in HTML documents..................................................................................................... 97 3.4 Interactions with XPath and XSLT........................................................................................ 98 3.5 Dynamic markup insertion.................................................................................................. 99 3.5.1 Opening the input stream ................................................................................ 99 3.5.2 Closing the input stream................................................................................ 101 3.5.3 document.write() ........................................................................................ 101 3.5.4 document.writeln() .................................................................................... 102 3.5.5 innerHTML...................................................................................................... 102 3.5.6 outerHTML...................................................................................................... 103 3.5.7 insertAdjacentHTML()................................................................................. 103 4 The elements of HTML......................................................................................................................... 106 4.1 The root element .............................................................................................................. 106 4.1.1 The html element .......................................................................................... 106 4.2 Document metadata......................................................................................................... 106 4.2.1 The head element .......................................................................................... 106 4.2.2 The title element ........................................................................................ 107 4.2.3 The base element .......................................................................................... 108 4.2.4 The link element .......................................................................................... 109 4.2.5 The meta element .......................................................................................... 112 4.2.5.1 Standard metadata names.......................................................... 113 4.2.5.2 Other metadata names ............................................................... 114 4.2.5.3 Pragma directives ....................................................................... 115 4 4.2.5.4 Other pragma directives ............................................................. 118 4.2.5.5 Specifying the document's character encoding .......................... 118 4.2.6 The style element ........................................................................................ 119 4.2.7 Styling............................................................................................................ 121 4.3 Scripting ........................................................................................................................... 122 4.3.1 The script element ...................................................................................... 122 4.3.1.1 Scripting languages..................................................................... 127 4.3.1.2 Restrictions for contents of script elements ............................. 128 4.3.1.3 Inline documentation for external scripts.................................... 129 4.3.2 The noscript element................................................................................... 129 4.4 Sections ............................................................................................................................ 131 4.4.1 The body element .......................................................................................... 131 4.4.2 The section element .................................................................................... 133 4.4.3 The nav element ............................................................................................ 134 4.4.4 The article element .................................................................................... 136 4.4.5 The aside element ........................................................................................ 137 4.4.6 The h1, h2, h3, h4, h5, and h6 elements ........................................................ 139 4.4.7 The hgroup element ...................................................................................... 140 4.4.8 The header element ...................................................................................... 140 4.4.9 The footer element ...................................................................................... 142 4.4.10 The address element .................................................................................. 143 4.4.11 Headings and sections ................................................................................. 144 4.4.11.1 Creating an outline.................................................................... 145 4.5 Grouping content.............................................................................................................. 148 4.5.1 The p element ................................................................................................ 148 4.5.2 The hr element .............................................................................................. 149 4.5.3 The pre element ............................................................................................ 150 4.5.4 The blockquote element............................................................................... 151 4.5.5 The ol element .............................................................................................. 152 4.5.6 The ul element .............................................................................................. 153 4.5.7 The li element .............................................................................................. 154 4.5.8 The dl element .............................................................................................. 155 4.5.9 The dt element .............................................................................................. 157 4.5.10 The dd element ............................................................................................ 157 4.5.11 The figure element .................................................................................... 158 4.5.12 The figcaption element............................................................................. 159 4.5.13 The div element .......................................................................................... 159 4.6 Text-level semantics ......................................................................................................... 160 4.6.1 The a element ................................................................................................ 160 4.6.2 The em element .............................................................................................. 162 4.6.3 The strong element ...................................................................................... 163 4.6.4 The small element ........................................................................................ 164 4.6.5 The cite element .......................................................................................... 165 4.6.6 The q element ................................................................................................ 166 4.6.7 The dfn element ............................................................................................ 167 4.6.8 The abbr element .......................................................................................... 167 4.6.9 The time element .......................................................................................... 168 4.6.10 The code element ........................................................................................ 171 4.6.11 The var element .......................................................................................... 172 4.6.12 The samp element ........................................................................................ 172 4.6.13 The kbd element .......................................................................................... 173 4.6.14 The sub and sup elements ........................................................................... 174 4.6.15 The i element .............................................................................................. 174 4.6.16 The b element .............................................................................................. 175 4.6.17 The mark element ........................................................................................ 176 4.6.18 The ruby element ........................................................................................ 177 4.6.19 The rt element ............................................................................................ 179 4.6.20 The rp element ............................................................................................ 179 4.6.21 The bdo element .......................................................................................... 180 4.6.22 The span element ........................................................................................ 180 4.6.23 The br element ............................................................................................ 181 4.6.24 The wbr element .......................................................................................... 181 4.6.25 Usage summary ........................................................................................... 182 4.7 Edits.................................................................................................................................. 182 4.7.1 The ins element ............................................................................................ 182 4.7.2 The del element ............................................................................................ 183 4.7.3 Attributes common to ins and del elements ................................................ 184 4.7.4 Edits and paragraphs ..................................................................................... 184 4.7.5 Edits and lists................................................................................................. 185 5 4.8 Embedded content ........................................................................................................... 186 4.8.1 The img element ............................................................................................ 186 4.8.1.1 Requirements for providing text to act as an alternative for images .................................................................................................... 191 4.8.1.1.1 A link or button containing nothing but the image ... 191 4.8.1.1.2 A phrase or paragraph with an alternative graphical representation: charts, diagrams, graphs, maps, illustrations. 191 4.8.1.1.3 A short phrase or label with an alternative graphical representation: icons, logos .................................................... 192 4.8.1.1.4 Text that has been rendered to a graphic for typographical effect ................................................................ 193 4.8.1.1.5 A graphical representation of some of the surrounding text .......................................................................................... 194 4.8.1.1.6 A purely decorative image that doesn't add any information .............................................................................. 194 4.8.1.1.7 A group of images that form a single larger picture with no links .................................................................................... 195 4.8.1.1.8 A group of images that form a single larger picture with links ......................................................................................... 195 4.8.1.1.9 A key part of the content.......................................... 195 4.8.1.1.10 An image not intended for the user........................ 198 4.8.1.1.11 An image in an e-mail or private document intended for a specific person who is known to be able to view images 198 4.8.1.1.12 General guidelines.................................................. 198 4.8.1.1.13 Guidance for markup generators............................ 199 4.8.1.1.14 Guidance for conformance checkers ...................... 199 4.8.2 The iframe element ...................................................................................... 199 4.8.3 The embed element ........................................................................................ 205 4.8.4 The object element ...................................................................................... 208 4.8.5 The param element ........................................................................................ 213 4.8.6 The video element ........................................................................................ 213 4.8.7 The audio element ........................................................................................ 216 4.8.8 The source element ...................................................................................... 217 4.8.9 Media elements.............................................................................................. 219 4.8.9.1 Error codes .................................................................................. 220 4.8.9.2 Location of the media resource ................................................... 220 4.8.9.3 MIME types .................................................................................. 221 4.8.9.4 Network states ............................................................................ 222 4.8.9.5 Loading the media resource ........................................................ 222 4.8.9.6 Offsets into the media resource .................................................. 228 4.8.9.7 The ready states ......................................................................... 229 4.8.9.8 Playing the media resource ......................................................... 231 4.8.9.9 Seeking ....................................................................................... 234 4.8.9.10 User interface............................................................................ 235 4.8.9.11 Time ranges .............................................................................. 236 4.8.9.12 Event summary ......................................................................... 237 4.8.9.13 Security and privacy considerations ......................................... 238 4.8.10 The canvas element .................................................................................... 238 4.8.10.1 The 2D context.......................................................................... 241 4.8.10.1.1 The canvas state .................................................... 243 4.8.10.1.2 Transformations ...................................................... 243 4.8.10.1.3 Compositing ........................................................... 244 4.8.10.1.4 Colors and styles .................................................... 245 4.8.10.1.5 Line styles .............................................................. 248 4.8.10.1.6 Shadows ................................................................. 249 4.8.10.1.7 Simple shapes (rectangles) .................................... 250 4.8.10.1.8 Complex shapes (paths) ......................................... 251 4.8.10.1.9 Focus management ................................................ 253 4.8.10.1.10 Text....................................................................... 255 4.8.10.1.11 Images.................................................................. 258 4.8.10.1.12 Pixel manipulation ................................................ 260 4.8.10.1.13 Drawing model ..................................................... 263 4.8.10.1.14 Examples .............................................................. 263 4.8.10.2 Color spaces and color correction ............................................. 264 4.8.10.3 Security with canvas elements ................................................. 264 4.8.11 The map element .......................................................................................... 265 4.8.12 The area element ........................................................................................ 266 4.8.13 Image maps ................................................................................................. 268 4.8.13.1 Authoring .................................................................................. 268 4.8.13.2 Processing model ...................................................................... 268 6 4.8.14 MathML ........................................................................................................ 270 4.8.15 SVG .............................................................................................................. 271 4.8.16 Dimension attributes ................................................................................... 271 4.9 Tabular data ...................................................................................................................... 271 4.9.1 The table element ........................................................................................ 271 4.9.2 The caption element .................................................................................... 277 4.9.3 The colgroup element................................................................................... 278 4.9.4 The col element ............................................................................................ 279 4.9.5 The tbody element ........................................................................................ 279 4.9.6 The thead element ........................................................................................ 280 4.9.7 The tfoot element ........................................................................................ 280 4.9.8 The tr element .............................................................................................. 281 4.9.9 The td element .............................................................................................. 282 4.9.10 The th element ............................................................................................ 283 4.9.11 Attributes common to td and th elements .................................................. 284 4.9.12 Processing model ......................................................................................... 285 4.9.12.1 Forming a table ......................................................................... 286 4.9.12.2 Forming relationships between data cells and header cells ...... 289 4.9.13 Examples ..................................................................................................... 290 4.10 Forms.............................................................................................................................. 292 4.10.1 Introduction.................................................................................................. 292 4.10.1.1 Writing a form's user interface .................................................. 292 4.10.1.2 Implementing the server-side processing for a form ................. 294 4.10.1.3 Configuring a form to communicate with a server .................... 295 4.10.1.4 Client-side form validation ........................................................ 296 4.10.2 Categories.................................................................................................... 297 4.10.3 The form element ........................................................................................ 297 4.10.4 The fieldset element................................................................................. 300 4.10.5 The legend element .................................................................................... 301 4.10.6 The label element ...................................................................................... 301 4.10.7 The input element ...................................................................................... 303 4.10.7.1 States of the type attribute ...................................................... 307 4.10.7.1.1 Hidden state ........................................................... 307 4.10.7.1.2 Text state and Search state .................................... 307 4.10.7.1.3 Telephone state ...................................................... 308 4.10.7.1.4 URL state ................................................................ 308 4.10.7.1.5 E-mail state ............................................................ 309 4.10.7.1.6 Password state ....................................................... 310 4.10.7.1.7 Date and Time state ............................................... 310 4.10.7.1.8 Date state............................................................... 311 4.10.7.1.9 Month state ............................................................ 312 4.10.7.1.10 Week state............................................................ 313 4.10.7.1.11 Time state ............................................................ 314 4.10.7.1.12 Local Date and Time state .................................... 314 4.10.7.1.13 Number state ....................................................... 315 4.10.7.1.14 Range state .......................................................... 316 4.10.7.1.15 Color state ............................................................ 318 4.10.7.1.16 Checkbox state..................................................... 318 4.10.7.1.17 Radio Button state................................................ 319 4.10.7.1.18 File Upload state ................................................... 320 4.10.7.1.19 Submit Button state ............................................. 321 4.10.7.1.20 Image Button state............................................... 321 4.10.7.1.21 Reset Button state ................................................ 323 4.10.7.1.22 Button state.......................................................... 323 4.10.7.2 Common input element attributes ........................................... 324 4.10.7.2.1 The autocomplete attribute................................... 324 4.10.7.2.2 The list attribute .................................................. 324 4.10.7.2.3 The readonly attribute .......................................... 325 4.10.7.2.4 The size attribute .................................................. 326 4.10.7.2.5 The required attribute .......................................... 326 4.10.7.2.6 The multiple attribute .......................................... 327 4.10.7.2.7 The maxlength attribute ........................................ 327 4.10.7.2.8 The pattern attribute ............................................ 328 4.10.7.2.9 The min and max attributes..................................... 328 4.10.7.2.10 The step attribute ................................................ 329 4.10.7.2.11 The placeholder attribute................................... 329 4.10.7.3 Common input element APIs.................................................... 330 4.10.7.4 Common event behaviors ......................................................... 332 4.10.8 The button element .................................................................................... 332 4.10.9 The select element .................................................................................... 334 7 4.10.10 4.10.11 4.10.12 4.10.13 4.10.14 4.10.15 4.10.16 4.10.17 4.10.18 4.10.19 4.10.20 4.10.21 4.10.22 4.10.23 The datalist element............................................................................... 338 The optgroup element............................................................................... 338 The option element .................................................................................. 339 The textarea element............................................................................... 341 The keygen element .................................................................................. 344 The output element .................................................................................. 346 The progress element............................................................................... 348 The meter element .................................................................................... 349 Association of controls and forms .............................................................. 353 Attributes common to form controls .......................................................... 354 4.10.19.1 Naming form controls.............................................................. 354 4.10.19.2 Enabling and disabling form controls ...................................... 354 4.10.19.3 A form control's value ............................................................. 354 4.10.19.4 Autofocusing a form control .................................................... 354 4.10.19.5 Limiting user input length ....................................................... 355 4.10.19.6 Form submission ..................................................................... 355 Constraints................................................................................................. 356 4.10.20.1 Definitions ............................................................................... 356 4.10.20.2 Constraint validation ............................................................... 357 4.10.20.3 The constraint validation API................................................... 358 4.10.20.4 Security ................................................................................... 360 Form submission ........................................................................................ 360 4.10.21.1 Introduction............................................................................. 360 4.10.21.2 Implicit submission.................................................................. 360 4.10.21.3 Form submission algorithm ..................................................... 361 4.10.21.4 URL-encoded form data........................................................... 365 4.10.21.5 Multipart form data ................................................................. 366 4.10.21.6 Plain text form data................................................................. 366 Resetting a form ........................................................................................ 366 Event dispatch ........................................................................................... 366 4.11 Interactive elements....................................................................................................... 367 4.11.1 The details element .................................................................................. 367 4.11.2 The summary element .................................................................................. 370 4.11.3 The command element .................................................................................. 371 4.11.4 The menu element ........................................................................................ 372 4.11.4.1 Introduction............................................................................... 373 4.11.4.2 Building menus and toolbars..................................................... 374 4.11.4.3 Context menus .......................................................................... 375 4.11.4.4 Toolbars ..................................................................................... 376 4.11.5 Commands................................................................................................... 376 4.11.5.1 Using the a element to define a command ............................... 377 4.11.5.2 Using the button element to define a command ...................... 378 4.11.5.3 Using the input element to define a command........................ 378 4.11.5.4 Using the option element to define a command ...................... 379 4.11.5.5 Using the command element to define a command .................... 379 4.11.5.6 Using the accesskey attribute on a label element to define a command ................................................................................................ 379 4.11.5.7 Using the accesskey attribute on a legend element to define a command ................................................................................................ 380 4.11.5.8 Using the accesskey attribute to define a command on other elements ................................................................................................. 380 4.11.6 The device element .................................................................................... 381 4.11.6.1 Stream API ................................................................................ 381 4.11.6.2 Peer-to-peer connections .......................................................... 382 4.12 Links ............................................................................................................................... 383 4.12.1 Hyperlink elements ...................................................................................... 383 4.12.2 Following hyperlinks..................................................................................... 384 4.12.2.1 Hyperlink auditing ..................................................................... 385 4.12.3 Link types .................................................................................................... 386 4.12.3.1 Link type "alternate" .............................................................. 386 4.12.3.2 Link type "archives" ................................................................ 387 4.12.3.3 Link type "author" .................................................................... 387 4.12.3.4 Link type "bookmark" ................................................................ 388 4.12.3.5 Link type "external" ................................................................ 388 4.12.3.6 Link type "help" ........................................................................ 388 4.12.3.7 Link type "icon" ........................................................................ 389 4.12.3.8 Link type "license" .................................................................. 390 4.12.3.9 Link type "nofollow" ................................................................ 390 4.12.3.10 Link type "noreferrer"........................................................... 390 4.12.3.11 Link type "pingback" .............................................................. 390 8 4.12.3.12 4.12.3.13 4.12.3.14 4.12.3.15 4.12.3.16 4.12.3.17 Link type "prefetch" .............................................................. 391 Link type "search" .................................................................. 391 Link type "stylesheet"........................................................... 391 Link type "sidebar" ................................................................ 391 Link type "tag"........................................................................ 391 Hierarchical link types ............................................................. 391 4.12.3.17.1 Link type "index" ................................................. 392 4.12.3.17.2 Link type "up" ....................................................... 392 4.12.3.18 Sequential link types ............................................................... 392 4.12.3.18.1 Link type "first" ................................................. 393 4.12.3.18.2 Link type "last" ................................................... 393 4.12.3.18.3 Link type "next" ................................................... 393 4.12.3.18.4 Link type "prev" ................................................... 393 4.12.3.19 Other link types....................................................................... 393 4.13 Common idioms without dedicated elements................................................................. 394 4.13.1 Tag clouds .................................................................................................... 394 4.13.2 Conversations .............................................................................................. 395 4.13.3 Footnotes ..................................................................................................... 395 4.14 Matching HTML elements using selectors....................................................................... 397 4.14.1 Case-sensitivity............................................................................................ 397 4.14.2 Pseudo-classes............................................................................................. 397 5 Microdata ............................................................................................................................................ 400 5.1 Introduction ...................................................................................................................... 400 5.1.1 Overview........................................................................................................ 400 5.1.2 The basic syntax ............................................................................................ 400 5.1.3 Typed items.................................................................................................... 402 5.1.4 Global identifiers for items............................................................................. 402 5.1.5 Selecting names when defining vocabularies ................................................ 402 5.1.6 Using the microdata DOM API ........................................................................ 403 5.2 Encoding microdata .......................................................................................................... 404 5.2.1 The microdata model ..................................................................................... 404 5.2.2 Items.............................................................................................................. 405 5.2.3 Names: the itemprop attribute...................................................................... 405 5.2.4 Values ............................................................................................................ 406 5.2.5 Associating names with items........................................................................ 407 5.3 Microdata DOM API ........................................................................................................... 408 5.4 Microdata vocabularies..................................................................................................... 410 5.4.1 vCard ............................................................................................................. 410 5.4.1.1 Conversion to vCard .................................................................... 418 5.4.1.2 Examples..................................................................................... 422 5.4.2 vEvent............................................................................................................ 423 5.4.2.1 Conversion to iCalendar .............................................................. 427 5.4.2.2 Examples..................................................................................... 428 5.4.3 Licensing works.............................................................................................. 429 5.4.3.1 Conversion to RDF....................................................................... 430 5.4.3.2 Examples..................................................................................... 430 5.5 Converting HTML to other formats.................................................................................... 431 5.5.1 JSON............................................................................................................... 431 5.5.2 RDF ................................................................................................................ 431 5.5.2.1 Examples..................................................................................... 434 5.5.3 Atom .............................................................................................................. 435 6 Loading Web pages ............................................................................................................................. 439 6.1 Browsing contexts ............................................................................................................ 439 6.1.1 Nested browsing contexts.............................................................................. 439 6.1.1.1 Navigating nested browsing contexts in the DOM....................... 440 6.1.2 Auxiliary browsing contexts ........................................................................... 440 6.1.2.1 Navigating auxiliary browsing contexts in the DOM .................... 441 6.1.3 Secondary browsing contexts ........................................................................ 441 6.1.4 Security.......................................................................................................... 441 6.1.5 Groupings of browsing contexts..................................................................... 441 6.1.6 Browsing context names................................................................................ 442 6.2 The Window object ............................................................................................................ 443 6.2.1 Security.......................................................................................................... 445 6.2.2 APIs for creating and navigating browsing contexts by name........................ 445 6.2.3 Accessing other browsing contexts ................................................................ 446 6.2.4 Named access on the Window object.............................................................. 447 6.2.5 Garbage collection and browsing contexts .................................................... 447 9 6.2.6 Browser interface elements ........................................................................... 448 6.2.7 The WindowProxy object ................................................................................ 449 6.3 Origin................................................................................................................................ 449 6.3.1 Relaxing the same-origin restriction .............................................................. 452 6.4 Session history and navigation ......................................................................................... 453 6.4.1 The session history of browsing contexts ...................................................... 453 6.4.2 The History interface ................................................................................... 454 6.4.3 The Location interface.................................................................................. 457 6.4.3.1 Security ....................................................................................... 458 6.4.4 Implementation notes for session history ...................................................... 458 6.5 Browsing the Web ............................................................................................................. 459 6.5.1 Navigating across documents ........................................................................ 459 6.5.2 Page load processing model for HTML files .................................................... 463 6.5.3 Page load processing model for XML files ...................................................... 463 6.5.4 Page load processing model for text files....................................................... 463 6.5.5 Page load processing model for images......................................................... 464 6.5.6 Page load processing model for content that uses plugins ............................ 464 6.5.7 Page load processing model for inline content that doesn't have a DOM ...... 464 6.5.8 Navigating to a fragment identifier................................................................ 465 6.5.9 History traversal ............................................................................................ 465 6.5.9.1 Event definitions ......................................................................... 467 6.5.10 Unloading documents .................................................................................. 468 6.5.10.1 Event definition ......................................................................... 469 6.5.11 Aborting a document load............................................................................ 470 6.6 Offline Web applications ................................................................................................... 470 6.6.1 Introduction.................................................................................................... 470 6.6.1.1 Event summary ........................................................................... 471 6.6.2 Application caches ......................................................................................... 471 6.6.3 The cache manifest syntax ............................................................................ 473 6.6.3.1 A sample manifest ...................................................................... 473 6.6.3.2 Writing cache manifests .............................................................. 473 6.6.3.3 Parsing cache manifests.............................................................. 475 6.6.4 Downloading or updating an application cache ............................................. 477 6.6.5 The application cache selection algorithm..................................................... 483 6.6.6 Changes to the networking model ................................................................. 483 6.6.7 Expiring application caches ........................................................................... 484 6.6.8 Application cache API..................................................................................... 484 6.6.9 Browser state ................................................................................................. 486 7 Web application APIs ........................................................................................................................... 487 7.1 Scripting ........................................................................................................................... 487 7.1.1 Introduction.................................................................................................... 487 7.1.2 Enabling and disabling scripting .................................................................... 487 7.1.3 Processing model ........................................................................................... 487 7.1.3.1 Definitions ................................................................................... 487 7.1.3.2 Calling scripts.............................................................................. 488 7.1.3.3 Creating scripts ........................................................................... 488 7.1.3.4 Killing scripts ............................................................................... 489 7.1.4 Event loops .................................................................................................... 489 7.1.4.1 Definitions ................................................................................... 489 7.1.4.2 Processing model ........................................................................ 490 7.1.4.3 Generic task sources ................................................................... 491 7.1.5 The javascript: protocol ............................................................................. 491 7.1.6 Events ............................................................................................................ 492 7.1.6.1 Event handlers ............................................................................ 492 7.1.6.2 Event handlers on elements, Document objects, and Window objects..................................................................................................... 494 7.1.6.3 Event firing.................................................................................. 496 7.1.6.4 Events and the Window object ..................................................... 496 7.1.6.5 Runtime script errors................................................................... 496 7.2 Timers............................................................................................................................... 496 7.3 User prompts .................................................................................................................... 499 7.3.1 Simple dialogs................................................................................................ 499 7.3.2 Printing .......................................................................................................... 499 7.3.3 Dialogs implemented using separate documents .......................................... 500 7.4 System state and capabilities........................................................................................... 502 7.4.1 Client identification ........................................................................................ 502 7.4.2 Custom scheme and content handlers........................................................... 503 7.4.2.1 Security and privacy ................................................................... 504 10 7.4.2.2 Sample user interface ................................................................. 505 7.4.3 Manually releasing the storage mutex ........................................................... 507 8 User interaction ................................................................................................................................... 508 8.1 The hidden attribute ........................................................................................................ 508 8.2 Activation.......................................................................................................................... 508 8.3 Scrolling elements into view ............................................................................................. 509 8.4 Focus ................................................................................................................................ 509 8.4.1 Sequential focus navigation........................................................................... 509 8.4.2 Focus management........................................................................................ 510 8.4.3 Document-level focus APIs............................................................................. 511 8.4.4 Element-level focus APIs ................................................................................ 512 8.5 The accesskey attribute................................................................................................... 512 8.6 The text selection APIs ..................................................................................................... 514 8.6.1 APIs for the browsing context selection ......................................................... 514 8.6.2 APIs for the text field selections..................................................................... 517 8.7 The contenteditable attribute ....................................................................................... 518 8.7.1 User editing actions ....................................................................................... 518 8.7.2 Making entire documents editable................................................................. 520 8.8 Spelling and grammar checking ....................................................................................... 520 8.9 Drag and drop................................................................................................................... 522 8.9.1 Introduction.................................................................................................... 522 8.9.2 The DragEvent and DataTransfer interfaces ............................................... 524 8.9.3 Events fired during a drag-and-drop action ................................................... 526 8.9.4 Drag-and-drop processing model ................................................................... 527 8.9.4.1 When the drag-and-drop operation starts or ends in another document ................................................................................................ 531 8.9.4.2 When the drag-and-drop operation starts or ends in another application .............................................................................................. 531 8.9.5 The draggable attribute ................................................................................ 531 8.9.6 Security risks in the drag-and-drop model ..................................................... 531 8.10 Undo history ................................................................................................................... 532 8.10.1 Definitions.................................................................................................... 532 8.10.2 The UndoManager interface .......................................................................... 532 8.10.3 Undo: moving back in the undo transaction history..................................... 534 8.10.4 Redo: moving forward in the undo transaction history ................................ 534 8.10.5 The UndoManagerEvent interface and the undo and redo events................ 534 8.10.6 Implementation notes .................................................................................. 535 8.11 Editing APIs..................................................................................................................... 535 9 Communication ................................................................................................................................... 540 9.1 Event definitions ............................................................................................................... 540 9.2 Cross-document messaging.............................................................................................. 540 9.2.1 Introduction.................................................................................................... 541 9.2.2 Security.......................................................................................................... 541 9.2.2.1 Authors........................................................................................ 541 9.2.2.2 User agents ................................................................................. 541 9.2.3 Posting messages .......................................................................................... 542 9.2.4 Posting messages with message ports .......................................................... 542 9.3 Channel messaging .......................................................................................................... 543 9.3.1 Introduction.................................................................................................... 543 9.3.2 Message channels.......................................................................................... 543 9.3.3 Message ports................................................................................................ 544 9.3.3.1 Ports and garbage collection ....................................................... 546 10 The HTML syntax ............................................................................................................................... 547 10.1 Writing HTML documents................................................................................................ 547 10.1.1 The DOCTYPE ............................................................................................... 547 10.1.2 Elements ...................................................................................................... 548 10.1.2.1 Start tags .................................................................................. 549 10.1.2.2 End tags .................................................................................... 550 10.1.2.3 Attributes .................................................................................. 550 10.1.2.4 Optional tags............................................................................. 551 10.1.2.5 Restrictions on content models ................................................. 552 10.1.2.6 Restrictions on the contents of raw text and RCDATA elements ................................................................................................. 552 10.1.3 Text .............................................................................................................. 553 10.1.3.1 Newlines.................................................................................... 553 10.1.4 Character references ................................................................................... 553 10.1.5 CDATA sections ............................................................................................ 553 11 10.1.6 Comments.................................................................................................... 554 10.2 Parsing HTML documents................................................................................................ 554 10.2.1 Overview of the parsing model .................................................................... 554 10.2.2 The input stream.......................................................................................... 555 10.2.2.1 Determining the character encoding......................................... 556 10.2.2.2 Character encodings ................................................................. 560 10.2.2.3 Preprocessing the input stream................................................. 561 10.2.2.4 Changing the encoding while parsing ....................................... 561 10.2.3 Parse state ................................................................................................... 562 10.2.3.1 The insertion mode ................................................................... 562 10.2.3.2 The stack of open elements ...................................................... 563 10.2.3.3 The list of active formatting elements....................................... 564 10.2.3.4 The element pointers ................................................................ 565 10.2.3.5 Other parsing state flags........................................................... 565 10.2.4 Tokenization ................................................................................................. 566 10.2.4.1 Data state ................................................................................. 566 10.2.4.2 Character reference in data state ............................................. 566 10.2.4.3 RCDATA state............................................................................. 566 10.2.4.4 Character reference in RCDATA state ........................................ 567 10.2.4.5 RAWTEXT state.......................................................................... 567 10.2.4.6 Script data state........................................................................ 567 10.2.4.7 PLAINTEXT state........................................................................ 567 10.2.4.8 Tag open state........................................................................... 567 10.2.4.9 End tag open state .................................................................... 568 10.2.4.10 Tag name state........................................................................ 568 10.2.4.11 RCDATA less-than sign state.................................................... 568 10.2.4.12 RCDATA end tag open state..................................................... 569 10.2.4.13 RCDATA end tag name state.................................................... 569 10.2.4.14 RAWTEXT less-than sign state ................................................. 569 10.2.4.15 RAWTEXT end tag open state .................................................. 569 10.2.4.16 RAWTEXT end tag name state................................................. 570 10.2.4.17 Script data less-than sign state ............................................... 570 10.2.4.18 Script data end tag open state................................................ 570 10.2.4.19 Script data end tag name state............................................... 571 10.2.4.20 Script data escape start state ................................................. 571 10.2.4.21 Script data escape start dash state......................................... 571 10.2.4.22 Script data escaped state ....................................................... 571 10.2.4.23 Script data escaped dash state ............................................... 572 10.2.4.24 Script data escaped dash dash state ...................................... 572 10.2.4.25 Script data escaped less-than sign state................................. 572 10.2.4.26 Script data escaped end tag open state.................................. 572 10.2.4.27 Script data escaped end tag name state ................................ 573 10.2.4.28 Script data double escape start state ..................................... 573 10.2.4.29 Script data double escaped state............................................ 574 10.2.4.30 Script data double escaped dash state ................................... 574 10.2.4.31 Script data double escaped dash dash state........................... 574 10.2.4.32 Script data double escaped less-than sign state ..................... 574 10.2.4.33 Script data double escape end state ....................................... 575 10.2.4.34 Before attribute name state .................................................... 575 10.2.4.35 Attribute name state ............................................................... 576 10.2.4.36 After attribute name state....................................................... 576 10.2.4.37 Before attribute value state .................................................... 577 10.2.4.38 Attribute value (double-quoted) state ..................................... 577 10.2.4.39 Attribute value (single-quoted) state ...................................... 577 10.2.4.40 Attribute value (unquoted) state ............................................. 578 10.2.4.41 Character reference in attribute value state ........................... 578 10.2.4.42 After attribute value (quoted) state ........................................ 578 10.2.4.43 Self-closing start tag state ...................................................... 579 10.2.4.44 Bogus comment state ............................................................. 579 10.2.4.45 Markup declaration open state................................................ 579 10.2.4.46 Comment start state ............................................................... 579 10.2.4.47 Comment start dash state....................................................... 579 10.2.4.48 Comment state ....................................................................... 580 10.2.4.49 Comment end dash state ........................................................ 580 10.2.4.50 Comment end state................................................................. 580 10.2.4.51 Comment end bang state........................................................ 580 10.2.4.52 Comment end space state ...................................................... 581 10.2.4.53 DOCTYPE state ........................................................................ 581 10.2.4.54 Before DOCTYPE name state ................................................... 581 10.2.4.55 DOCTYPE name state .............................................................. 582 12 10.2.5 10.2.6 10.2.7 10.2.8 10.2.4.56 After DOCTYPE name state...................................................... 582 10.2.4.57 After DOCTYPE public keyword state....................................... 582 10.2.4.58 Before DOCTYPE public identifier state ................................... 583 10.2.4.59 DOCTYPE public identifier (double-quoted) state .................... 583 10.2.4.60 DOCTYPE public identifier (single-quoted) state ..................... 583 10.2.4.61 After DOCTYPE public identifier state ...................................... 584 10.2.4.62 Between DOCTYPE public and system identifiers state........... 584 10.2.4.63 After DOCTYPE system keyword state ..................................... 585 10.2.4.64 Before DOCTYPE system identifier state ................................. 585 10.2.4.65 DOCTYPE system identifier (double-quoted) state .................. 585 10.2.4.66 DOCTYPE system identifier (single-quoted) state.................... 586 10.2.4.67 After DOCTYPE system identifier state .................................... 586 10.2.4.68 Bogus DOCTYPE state ............................................................. 586 10.2.4.69 CDATA section state ................................................................ 586 10.2.4.70 Tokenizing character references.............................................. 587 Tree construction ......................................................................................... 589 10.2.5.1 Creating and inserting elements ............................................... 589 10.2.5.2 Closing elements that have implied end tags ........................... 592 10.2.5.3 Foster parenting ........................................................................ 592 10.2.5.4 The "initial" insertion mode....................................................... 592 10.2.5.5 The "before html" insertion mode ............................................. 594 10.2.5.6 The "before head" insertion mode ............................................ 595 10.2.5.7 The "in head" insertion mode.................................................... 595 10.2.5.8 The "in head noscript" insertion mode ...................................... 596 10.2.5.9 The "after head" insertion mode ............................................... 597 10.2.5.10 The "in body" insertion mode.................................................. 598 10.2.5.11 The "text" insertion mode ....................................................... 607 10.2.5.12 The "in table" insertion mode.................................................. 608 10.2.5.13 The "in table text" insertion mode .......................................... 609 10.2.5.14 The "in caption" insertion mode .............................................. 609 10.2.5.15 The "in column group" insertion mode .................................... 610 10.2.5.16 The "in table body" insertion mode......................................... 611 10.2.5.17 The "in row" insertion mode .................................................... 611 10.2.5.18 The "in cell" insertion mode .................................................... 612 10.2.5.19 The "in select" insertion mode ................................................ 613 10.2.5.20 The "in select in table" insertion mode ................................... 614 10.2.5.21 The "in foreign content" insertion mode ................................. 614 10.2.5.22 The "after body" insertion mode ............................................. 616 10.2.5.23 The "in frameset" insertion mode ........................................... 617 10.2.5.24 The "after frameset" insertion mode ....................................... 617 10.2.5.25 The "after after body" insertion mode..................................... 618 10.2.5.26 The "after after frameset" insertion mode .............................. 618 The end........................................................................................................ 618 Coercing an HTML DOM into an infoset........................................................ 619 An introduction to error handling and strange cases in the parser .............. 620 10.2.8.1 Misnested tags: ........................................... 620 10.2.8.2 Misnested tags:

......................................... 621 10.2.8.3 Unexpected markup in tables ................................................... 622 10.2.8.4 Scripts that modify the page as it is being parsed .................... 624 10.3 Serializing HTML fragments ............................................................................................ 625 10.4 Parsing HTML fragments ................................................................................................. 626 10.5 Named character references .......................................................................................... 627 11 The XHTML 11.1 11.2 11.3 11.4 syntax............................................................................................................................. 635 Writing XHTML documents.............................................................................................. 635 Parsing XHTML documents ............................................................................................. 635 Serializing XHTML fragments .......................................................................................... 636 Parsing XHTML fragments............................................................................................... 637 12 Rendering .......................................................................................................................................... 638 12.1 Introduction .................................................................................................................... 638 12.2 The CSS user agent style sheet and presentational hints............................................... 638 12.2.1 Introduction.................................................................................................. 638 12.2.2 Display types ............................................................................................... 639 12.2.3 Margins and padding ................................................................................... 639 12.2.4 Alignment .................................................................................................... 641 12.2.5 Fonts and colors........................................................................................... 643 12.2.6 Punctuation and decorations ....................................................................... 645 12.2.7 Resetting rules for inherited properties ....................................................... 647 12.2.8 The hr element ............................................................................................ 647 13 12.2.9 The fieldset element................................................................................. 648 12.3 Replaced elements ......................................................................................................... 648 12.3.1 Embedded content....................................................................................... 648 12.3.2 Images ......................................................................................................... 649 12.3.3 Attributes for embedded content and images ............................................. 649 12.3.4 Image maps ................................................................................................. 651 12.3.5 Toolbars........................................................................................................ 651 12.4 Bindings.......................................................................................................................... 651 12.4.1 Introduction.................................................................................................. 651 12.4.2 The button element .................................................................................... 651 12.4.3 The details element .................................................................................. 651 12.4.4 The input element as a text entry widget................................................... 652 12.4.5 The input element as domain-specific widgets........................................... 652 12.4.6 The input element as a range control......................................................... 653 12.4.7 The input element as a color well............................................................... 653 12.4.8 The input element as a check box and radio button widgets ..................... 653 12.4.9 The input element as a file upload control ................................................. 653 12.4.10 The input element as a button ................................................................. 653 12.4.11 The marquee element ................................................................................ 654 12.4.12 The meter element .................................................................................... 655 12.4.13 The progress element............................................................................... 655 12.4.14 The select element .................................................................................. 655 12.4.15 The textarea element............................................................................... 656 12.4.16 The keygen element .................................................................................. 656 12.4.17 The time element ...................................................................................... 657 12.5 Frames and framesets .................................................................................................... 657 12.6 Interactive media............................................................................................................ 659 12.6.1 Links, forms, and navigation ........................................................................ 659 12.6.2 The title attribute...................................................................................... 659 12.6.3 Editing hosts ................................................................................................ 659 12.7 Print media ..................................................................................................................... 659 13 Obsolete features .............................................................................................................................. 660 13.1 Obsolete but conforming features .................................................................................. 660 13.1.1 Warnings for obsolete but conforming features ........................................... 660 13.2 Non-conforming features ................................................................................................ 660 13.3 Requirements for implementations................................................................................. 665 13.3.1 The applet element .................................................................................... 665 13.3.2 The marquee element .................................................................................. 666 13.3.3 Frames ......................................................................................................... 668 13.3.4 Other elements, attributes and APIs ............................................................ 669 14 IANA considerations .......................................................................................................................... 678 14.1 text/html ...................................................................................................................... 678 14.2 text/html-sandboxed ................................................................................................... 679 14.3 application/xhtml+xml................................................................................................ 680 14.4 text/cache-manifest ................................................................................................... 681 14.5 text/ping ...................................................................................................................... 681 14.6 application/microdata+json ...................................................................................... 682 14.7 Ping-From ...................................................................................................................... 683 14.8 Ping-To .......................................................................................................................... 683 Index ...................................................................................................................................................... 685 Elements................................................................................................................................. 685 Element content categories.................................................................................................... 690 Attributes................................................................................................................................ 691 Interfaces................................................................................................................................ 697 Events..................................................................................................................................... 699 References.............................................................................................................................................. 700 Acknowledgements ................................................................................................................................ 706 14 1 Introduction 1.1 Is this HTML5? This section is non-normative. In short: Yes. In more length: "HTML5" has at various times been used to refer to a wide variety of technologies, some of which originated in this document, and some of which have only ever been tangentially related. This specification actually now defines the next generation of HTML after HTML5. HTML5 reached Last Call at the WHATWG in October 2009, and shortly after we started working on some experimental new features that are not as stable as the rest of the specification. The stability of sections is annotated in the margin. The W3C has also been working on HTML in conjunction with the WHATWG; at the W3C, this document has been split into several parts, and the occasional informative paragraph or example has been removed for technical reasons. For all intents and purposes, however, the W3C HTML specifications and this specification are equivalent (and they are in fact all generated from the same source document). Features that are considered part of the next generation of HTML beyond HTML5 currently consist of only: • • The device p381 element. The ping p384 attribute and related hyperlink auditing p385 features. Features that are part of HTML5 (and this specification) but that are either currently, or have been in the past, published as separate specifications: • • • • • • Canvas 2D Graphics Context p241 Microdata p400 Microdata vocabularies p410 Cross-document messaging p540 (also known as Communications) Channel messaging p543 (also known as Communications) Forms p292 (previously known as Web Forms 2) Features that are not currently in this document that were in the past considered part of HTML5, or that were never part of HTML5 but have been referred to as part of HTML5 in the media, include: • • • • • • • • • • Web Workers Web Storage WebSocket API WebSocket protocol Server-sent Events Web SQL Database Geolocation API SVG MathML XMLHttpRequest 1.2 Background This section is non-normative. The World Wide Web's markup language has always been HTML. HTML was primarily designed as a language for semantically describing scientific documents, although its general design and adaptations over the years have enabled it to be used to describe a number of other types of documents. The main area that has not been adequately addressed by HTML is a vague subject referred to as Web Applications. This specification attempts to rectify this, while at the same time updating the HTML specifications to address issues raised in the past few years. 1.3 Audience This section is non-normative. This specification is intended for authors of documents and scripts that use the features defined in this specification, implementors of tools that operate on pages that use the features defined in this specification, and individuals wishing to establish the correctness of documents or implementations with respect to the requirements of this specification. This document is probably not suited to readers who do not already have at least a passing familiarity with Web technologies, as in places it sacrifices clarity for precision, and brevity for completeness. More approachable tutorials and authoring guides can provide a gentler introduction to the topic. 15 In particular, familiarity with the basics of DOM Core and DOM Events is necessary for a complete understanding of some of the more technical parts of this specification. An understanding of Web IDL, HTTP, XML, Unicode, character encodings, JavaScript, and CSS will also be helpful in places but is not essential. 1.4 Scope This section is non-normative. This specification is limited to providing a semantic-level markup language and associated semantic-level scripting APIs for authoring accessible pages on the Web ranging from static documents to dynamic applications. The scope of this specification does not include providing mechanisms for media-specific customization of presentation (although default rendering rules for Web browsers are included at the end of this specification, and several mechanisms for hooking into CSS are provided as part of the language). The scope of this specification is not to describe an entire operating system. In particular, hardware configuration software, image manipulation tools, and applications that users would be expected to use with high-end workstations on a daily basis are out of scope. In terms of applications, this specification is targeted specifically at applications that would be expected to be used by users on an occasional basis, or regularly but from disparate locations, with low CPU requirements. For instance online purchasing systems, searching systems, games (especially multiplayer online games), public telephone books or address books, communications software (e-mail clients, instant messaging clients, discussion software), document editing software, etc. 1.5 History This section is non-normative. For its first five years (1990-1995), HTML went through a number of revisions and experienced a number of extensions, primarily hosted first at CERN, and then at the IETF. With the creation of the W3C, HTML's development changed venue again. A first abortive attempt at extending HTML in 1995 known as HTML 3.0 then made way to a more pragmatic approach known as HTML 3.2, which was completed in 1997. HTML4 followed, reaching completion in 1998. At this time, the W3C membership decided to stop evolving HTML and instead begin work on an XML-based equivalent, called XHTML. This effort started with a reformulation of HTML4 in XML, known as XHTML 1.0, which added no new features except the new serialization, and which was completed in 2000. After XHTML 1.0, the W3C's focus turned to making it easier for other working groups to extend XHTML, under the banner of XHTML Modularization. In parallel with this, the W3C also worked on a new language that was not compatible with the earlier HTML and XHTML languages, calling it XHTML2. Around the time that HTML's evolution was stopped in 1998, parts of the API for HTML developed by browser vendors were specified and published under the name DOM Level 1 (in 1998) and DOM Level 2 Core and DOM Level 2 HTML (starting in 2000 and culminating in 2003). These efforts then petered out, with some DOM Level 3 specifications published in 2004 but the working group being closed before all the Level 3 drafts were completed. In 2003, the publication of XForms, a technology which was positioned as the next generation of Web forms, sparked a renewed interest in evolving HTML itself, rather than finding replacements for it. This interest was borne from the realization that XML's deployment as a Web technology was limited to entirely new technologies (like RSS and later Atom), rather than as a replacement for existing deployed technologies (like HTML). A proof of concept to show that it was possible to extend HTML4's forms to provide many of the features that XForms 1.0 introduced, without requiring browsers to implement rendering engines that were incompatible with existing HTML Web pages, was the first result of this renewed interest. At this early stage, while the draft was already publicly available, and input was already being solicited from all sources, the specification was only under Opera Software's copyright. The idea that HTML's evolution should be reopened was tested at a W3C workshop in 2004, where some of the principles that underlie the HTML5 work (described below), as well as the aforementioned early draft proposal covering just forms-related features, were presented to the W3C jointly by Mozilla and Opera. The proposal was rejected on the grounds that the proposal conflicted with the previously chosen direction for the Web's evolution; the W3C staff and membership voted to continue developing XML-based replacements instead. Shortly thereafter, Apple, Mozilla, and Opera jointly announced their intent to continue working on the effort under the umbrella of a new venue called the WHATWG. A public mailing list was created, and the draft was moved to the WHATWG site. The copyright was subsequently amended to be jointly owned by all three vendors, and to allow reuse of the specification. The WHATWG was based on several core principles, in particular that technologies need to be backwards compatible, that specifications and implementations need to match even if this means changing the specification 16 rather than the implementations, and that specifications need to be detailed enough that implementations can achieve complete interoperability without reverse-engineering each other. The latter requirement in particular required that the scope of the HTML5 specification include what had previously been specified in three separate documents: HTML4, XHTML1, and DOM2 HTML. It also meant including significantly more detail than had previously been considered the norm. In 2006, the W3C indicated an interest to participate in the development of HTML5 after all, and in 2007 formed a working group chartered to work with the WHATWG on the development of the HTML5 specification. Apple, Mozilla, and Opera allowed the W3C to publish the specification under the W3C copyright, while keeping a version with the less restrictive license on the WHATWG site. Since then, both groups have been working together. A separate document has been published by the W3C HTML working group to document the differences between this specification and the language described in the HTML4 specification. [HTMLDIFF] p701 1.6 Design notes This section is non-normative. It must be admitted that many aspects of HTML appear at first glance to be nonsensical and inconsistent. HTML, its supporting DOM APIs, as well as many of its supporting technologies, have been developed over a period of several decades by a wide array of people with different priorities who, in many cases, did not know of each other's existence. Features have thus arisen from many sources, and have not always been designed in especially consistent ways. Furthermore, because of the unique characteristics of the Web, implementation bugs have often become de-facto, and now de-jure, standards, as content is often unintentionally written in ways that rely on them before they can be fixed. Despite all this, efforts have been made to adhere to certain design goals. These are described in the next few subsections. 1.6.1 Serializability of script execution This section is non-normative. To avoid exposing Web authors to the complexities of multithreading, the HTML and DOM APIs are designed such that no script can ever detect the simultaneous execution of other scripts. Even with workers, the intent is that the behavior of implementations can be thought of as completely serializing the execution of all scripts in all browsing contexts p439 . Note: The navigator.yieldForStorageUpdates() p507 method, in this model, is equivalent to allowing other scripts to run while the calling script is blocked. 1.6.2 Compliance with other specifications This section is non-normative. This specification interacts with and relies on a wide variety of other specifications. In certain circumstances, unfortunately, conflicting needs have led to this specification violating the requirements of these other specifications. Whenever this has occurred, the transgressions have each been noted as a "willful violation", and the reason for the violation has been noted. 1.7 HTML vs XHTML This section is non-normative. This specification defines an abstract language for describing documents and applications, and some APIs for interacting with in-memory representations of resources that use this language. The in-memory representation is known as "DOM HTML", or "the DOM" for short. This specification defines version 5 of DOM HTML, known as "DOM5 HTML". There are various concrete syntaxes that can be used to transmit resources that use this abstract language, two of which are defined in this specification. 17 The first such concrete syntax is the HTML syntax. This is the format suggested for most authors. It is compatible with most legacy Web browsers. If a document is transmitted with an HTML MIME type p26 , such as text/html p678 , then it will be processed as an HTML document by Web browsers. This specification defines the latest HTML syntax, known simply as "HTML". The second concrete syntax is the XHTML syntax, which is an application of XML. When a document is transmitted with an XML MIME type p27 , such as application/xhtml+xml p680 , then it is treated as an XML document by Web browsers, to be parsed by an XML processor. Authors are reminded that the processing for XML and HTML differs; in particular, even minor syntax errors will prevent a document labeled as XML from being rendered fully, whereas they would be ignored in the HTML syntax. This specification defines the latest XHTML syntax, known simply as "XHTML". The DOM, the HTML syntax, and XML cannot all represent the same content. For example, namespaces cannot be represented using the HTML syntax, but they are supported in the DOM and in XML. Similarly, documents that use the noscript p129 feature can be represented using the HTML syntax, but cannot be represented with the DOM or in XML. Comments that contain the string "-->" can be represented in the DOM but not in the HTML syntax or in XML. 1.8 Structure of this specification This section is non-normative. This specification is divided into the following major sections: Common infrastructure p26 The conformance classes, algorithms, definitions, and the common underpinnings of the rest of the specification. Semantics, structure, and APIs of HTML documents p71 Documents are built from elements. These elements form a tree using the DOM. This section defines the features of this DOM, as well as introducing the features common to all elements, and the concepts used in defining elements. The elements of HTML p106 Each element has a predefined meaning, which is explained in this section. Rules for authors on how to use the element, along with user agent requirements for how to handle each element, are also given. Microdata p400 This specification introduces a mechanism for adding machine-readable annotations to documents, so that tools can extract trees of name/value pairs from the document. This section describes this mechanism and some algorithms that can be used to convert HTML documents into other formats. This section also defines some Microdata vocabularies for contact information, calendar events, and licensing works. Loading Web pages p439 HTML documents do not exist in a vacuum — this section defines many of the features that affect environments that deal with multiple pages. Web application APIs p487 This section introduces basic features for scripting of applications in HTML. User interaction p508 HTML documents can provide a number of mechanisms for users to interact with and modify content, which are described in this section. The communication APIs p540 This section describes some mechanisms that applications written in HTML can use to communicate with other applications from different domains running on the same client. The HTML syntax p547 The XHTML syntax p635 All of these features would be for naught if they couldn't be represented in a serialized form and sent to other people, and so these sections define the syntaxes of HTML, along with rules for how to parse content using those syntaxes. There are also some appendices, defining rendering rules p638 for Web browsers and listing obsolete features p660 and IANA considerations p678 . 18 1.8.1 How to read this specification This specification should be read like all other specifications. First, it should be read cover-to-cover, multiple times. Then, it should be read backwards at least once. Then it should be read by picking random sections from the contents list and following all the cross-references. 1.8.2 Typographic conventions This is a definition, requirement, or explanation. Note: This is a note. This is an example. ** This is an open issue. ⚠Warning! This is a warning. interface Example { // this is an IDL definition }; This box is non-normative. Implementation requirements are given below this box. variable = object . method( [ optionalArgument ] ) This is a note to authors describing the usage of an interface. /* this is a CSS fragment */ The defining instance of a term is marked up like this. Uses of that term are marked up like this p19 or like this p19 . The defining instance of an element, attribute, or API is marked up like this. References to that element, attribute, or API are marked up like this p19 . Other code fragments are marked up like this. Variables are marked up like this. This is an implementation requirement. 1.9 A quick introduction to HTML This section is non-normative. A basic HTML document looks like this: Sample page

Sample page

This is a simple sample.

HTML documents consist of a tree of elements and text. Each element is denoted in the source by a start tag p549 , such as "", and an end tag p550 , such as "". (Certain start tags and end tags can in certain cases be omitted p551 and are implied by other tags.) Tags have to be nested such that elements are all completely within each other, without overlapping:

This is very wrong!

This is correct.

19 This specification defines a set of elements that can be used in HTML, along with rules about the ways in which the elements can be nested. Elements can have attributes, which control how the elements work. In the example below, there is a hyperlink p383 , formed using the a p160 element and its href p383 attribute: simple Attributes p550 are placed inside the start tag, and consist of a name p550 and a value p550 , separated by an "=" character. The attribute value can remain unquoted p550 if it doesn't contain spaces or any of " ' ` = < or >. Otherwise, it has to be quoted using either single or double quotes. The value, along with the "=" character, can be omitted altogether if the value is the empty string. HTML user agents (e.g. Web browsers) then parse this markup, turning it into a DOM (Document Object Model) tree. A DOM tree is an in-memory representation of a document. DOM trees contain several kinds of nodes, in particular a DOCTYPE node, elements, text nodes, and comment nodes. The markup snippet at the top of this section p19 would be turned into the following DOM tree: DOCTYPE: html p106 html p106 head p106 #text: ??? title p107 #text: Sample page #text: ?? #text: ?? body p131 #text: ??? h1 p139 #text: Sample page #text: ??? p p148 #text: This is a a p160 href="demo.html" #text: simple #text: sample. #text: ??? #comment: this is a comment #text: ??? The root element p27 of this tree is the html p106 element, which is the element always found at the root of HTML documents. It contains two elements, head p106 and body p131 , as well as a text node between them. There are many more text nodes in the DOM tree than one would initially expect, because the source contains a number of spaces (represented here by "␣") and line breaks ("⏎") that all end up as text nodes in the DOM. The head p106 element contains a title p107 element, which itself contains a text node with the text "Sample page". Similarly, the body p131 element contains an h1 p139 element, a p p148 element, and a comment. This DOM tree can be manipulated from scripts in the page. Scripts (typically in JavaScript) are small programs that can be embedded using the script p122 element or using event handler content attributes p492 . For example, here is a form with a script that sets the value of the form's output p346 element to say "Hello World":
Result:
20 Each element in the DOM tree is represented by an object, and these objects have APIs so that they can be manipulated. For instance, a link (e.g. the a p160 element in the tree above) can have its "href p383 " attribute changed in several ways: var a = document.links[0]; // obtain the first link in the document a.href = 'sample.html'; // change the destination URL of the link a.protocol = 'https'; // change just the scheme part of the URL a.setAttribute('href', 'http://example.com/'); // change the content attribute directly Since DOM trees are used as the way to represent HTML documents when they are processed and presented by implementations (especially interactive implementations like Web browsers), this specification is mostly phrased in terms of DOM trees, instead of the markup described above. HTML documents represent a media-independent description of interactive content. HTML documents might be rendered to a screen, or through a speech synthesizer, or on a braille display. To influence exactly how such rendering takes place, authors can use a styling language such as CSS. In the following example, the page has been made yellow-on-blue using CSS. Sample styled page

Sample styled page

This page is just a demo.

For more details on how to use HTML, authors are encouraged to consult tutorials and guides. Some of the examples included in this specification might also be of use, but the novice author is cautioned that this specification, by necessity, defines the language with a level of detail that might be difficult to understand at first. 1.10 Conformance requirements for authors This section is non-normative. Unlike previous versions of the HTML specification, this specification defines in some detail the required processing for invalid documents as well as valid documents. However, even though the processing of invalid content is in most cases well-defined, conformance requirements for documents are still important: in practice, interoperability (the situation in which all implementations process particular content in a reliable and identical or equivalent way) is not the only goal of document conformance requirements. This section details some of the more common reasons for still distinguishing between a conforming document and one with errors. 1.10.1 Presentational markup This section is non-normative. The majority of presentational features from previous versions of HTML are no longer allowed. Presentational markup in general has been found to have a number of problems: The use of presentational elements leads to poorer accessibility While it is possible to use presentational markup in a way that provides users of assistive technologies (ATs) with an acceptable experience (e.g. using ARIA), doing so is significantly more difficult than doing so when using semantically-appropriate markup. Furthermore, even using such techniques doesn't help make pages accessible for non-AT non-graphical users, such as users of text-mode browsers. Using media-independent markup, on the other hand, provides an easy way for documents to be authored in such a way that they work for more users (e.g. text browsers). Higher cost of maintenance It is significantly easier to maintain a site written in such a way that the markup is style-independent. For example, changing the color of a site that uses throughout requires changes across the entire site, whereas a similar change to a site based on CSS can be done by changing a single file. 21 Higher document sizes Presentational markup tends to be much more redundant, and thus results in larger document sizes. For those reasons, presentational markup has been removed from HTML in this version. This change should not come as a surprise; HTML4 deprecated presentational markup many years ago and provided a mode (HTML4 Transitional) to help authors move away from presentational markup; later, XHTML 1.1 went further and obsoleted those features altogether. The only remaining presentational markup features in HTML are the style p86 attribute and the style p119 element. Use of the style p86 attribute is somewhat discouraged in production environments, but it can be useful for rapid prototyping (where its rules can be directly moved into a separate style sheet later) and for providing specific styles in unusual cases where a separate style sheet would be inconvenient. Similarly, the style p119 element can be useful in syndication or for page-specific styles, but in general an external style sheet is likely to be more convenient when the styles apply to multiple pages. It is also worth noting that four elements that were previously presentational have been redefined in this specification to be media-independent: b p175 , i p174 , hr p149 , and small p164 . 1.10.2 Syntax errors This section is non-normative. The syntax of HTML is constrained to avoid a wide variety of problems. Unintuitive error-handling behavior Certain invalid syntax constructs, when parsed, result in DOM trees that are highly unintuitive. For example, the following markup fragment results in a DOM with an hr p149 element that is an earlier sibling of the corresponding table p271 element:
... Errors with optional error recovery To allow user agents to be used in controlled environments without having to implement the more bizarre and convoluted error handling rules, user agents are permitted to fail whenever encountering a parse error p554 . Errors where the error-handling behavior is not compatible with streaming user agents Some error-handling behavior, such as the behavior for the

... example mentioned above, are incompatible with streaming user agents. To avoid interoperability problems with such user agents, any syntax resulting in such behavior is considered invalid. Errors that can result in infoset coercion When a user agent based on XML is connected to an HTML parser, it is possible that certain invariants that XML enforces, such as comments never containing two consecutive hyphens, will be violated by an HTML file. Handling this can require that the parser coerce the HTML DOM into an XML-compatible infoset. Most syntax constructs that require such handling are considered invalid. Errors that result in disproportionally poor performance Certain syntax constructs can result in disproportionally poor performance. To discourage the use of such constructs, they are typically made non-conforming. For example, the following markup results in poor performance when hitting the highlighted end tag, since all the open elements are examined first to see if they match the close tag:

... Errors that help authors avoid fragile syntax constructs There are syntax constructs that, for historical reasons, are relatively fragile. To help reduce the number of users who accidentally run into such problems, they are made non-conforming. For example, the parsing of certain named character references in attributes happens even with the closing semicolon being omitted. It is safe to include an ampersand followed by letters that do not form a named character reference, but if the letters are changed to a string that does form a named character reference, they will be interpreted as that character instead. In this fragment, the attribute's value is "?hello=1&world=2": Demo In the following fragment, however, the attribute's value is actually "?original=1©=2", not the intended "?original=1©=2": Compare 22 To avoid this problem, all named character references are required to end with a semicolon, and uses of named character references without a semicolon are flagged as errors. Thus, the correct way to express the above cases is as follows: Demo Compare Errors that flag known interoperability problems in legacy user agents Certain syntax constructs are known to cause especially subtle or serious problems in legacy user agents, and are therefore marked as non-conforming to help authors avoid them. For example, this is why the U+0060 GRAVE ACCENT character (`) is not allowed in unquoted attributes. In certain legacy user agents, it is sometimes treated as a quote character. Another example of this is the DOCTYPE, which is required to trigger no-quirks mode p75 , because the behavior of legacy user agents in quirks mode p75 is often largely undocumented. Errors that protect authors from security attacks Certain restrictions exist purely to avoid known security problems. For example, the restriction on using UTF-7 exists purely to avoid authors falling prey to a known cross-site-scripting attack using UTF-7. Cases where the author's intent is unclear Some errors merely flag cases where the author's intent is most unclear. Correcting these errors early makes later maintenance easier. For example, it is unclear whether the author intended the following to be an h1 p139 heading or an h2 p139 heading:

Contact details

Cases that are likely to be typos When a user makes a simple typo, it is helpful if the error can be caught early, as this can save the author a lot of debugging time. This specification therefore usually considers it an error to use element names, attribute names, and so forth, that do not match the names defined in this specification. For example, if the author typed instead of Another example is the restrictions on the content models of the ul p153 element, which only allows li p154 element children. Lists by definition consist just of zero or more list items, so if a ul p153 element contains something other than an li p154 element, it's not clear what was meant. Errors that catch cases where the default styles are likely to lead to confusion Certain elements have default styles or behaviors that make certain combinations likely to lead to confusion. Where these have equivalent alternatives without this problem, the confusing combinations are disallowed. For example, div p159 elements are rendered as block boxes, and span p180 elements as inline boxes. Putting a block box in an inline box is unnecessarily confusing; since either nesting just div p159 elements, or nesting just span p180 elements, or nesting span p180 elements inside div p159 elements all serve the same purpose as nesting a div p159 element in a span p180 element, but only the latter involves a block box in an inline box, the latter combination is disallowed. Another example would be the way interactive content p92 cannot be nested. For example, a button p332 element cannot contain a textarea p341 element. This is because the default behavior of such nesting interactive elements would be highly confusing to users. Instead of nesting these elements, they can be placed side by side. Errors that encourage a correct understanding of the spec Sometimes, something is disallowed because allowing it would likely cause author confusion. For example, setting the disabled p354 attribute to the value "false" is disallowed, because despite the appearance of meaning that the element is enabled, it in fact means that the element is disabled (what matters for implementations is the presence of the attribute, not its value). Errors that are intended merely to simplify the language Some conformance errors simplify the language that authors need to learn. For example, the area p266 element's shape p267 attribute, despite accepting both circ p267 and circle p267 values in practice as synonyms, disallows the use of the circ p267 value, so as to simplify tutorials and other learning aids. There would be no benefit to allowing both, but it would cause extra confusion when teaching the language. Errors that avoid peculiarities of the parser Certain elements are parsed in someone eccentric ways (typically for historical reasons), and their content model restrictions are intended to avoid exposing the author to these issues. For example, a form p297 element isn't allowed inside phrasing content p91 , because when parsed as HTML, a form p297 element's start tag will imply a p p148 element's end tag. Thus, the following markup results in two paragraphs p93 , not one:

Welcome.
It is parsed exactly like the following:

Welcome.

Errors that would likely result in scripts failing in hard-to-debug ways Some errors are intended to help prevent script problems that would be hard to debug. This is why, for instance, it is non-conforming to have two id p84 attributes with the same value. Duplicate IDs lead to the wrong element being selected, with sometimes disastrous effects whose cause is hard to determine. Errors that are intended to save the author time Some constructs are disallowed because historically they have been the cause of a lot of wasted authoring time. For example, a script p122 element's src p123 attribute causes the element's contents to be ignored. However, this isn't obvious, especially if the element's contents appear to be executable script — which can lead to authors spending a lot of time trying to debug the inline script without realising that it is not executing. To reduce this problem, this specification makes it non-conforming to have executable script in a script p122 element when the src p123 attribute is present. This means that authors who are validating their documents are less likely to waste time with this kind of mistake. Errors that are intended to help authors migrating to and from XHTML Some authors like to write files that can be interpreted as both XML and HTML with similar results. Though this practice is discouraged in general due to the myriad of subtle complications involved (especially when 24 involving scripting, styling, or any kind of automated serialization), this specification has a few restrictions intended to at least somewhat mitigate the difficulties. This makes it easier for authors to use this as a transitionary step when migrating between HTML and XHTML. For example, there are somewhat complicated rules surrounding the lang p85 and xml:lang p85 attributes intended to keep the two synchronized. Another example would be the restrictions on the values of xmlns attributes in the HTML serialization, which are intended to ensure that elements in conforming documents end up in the same namespaces whether processed as HTML or XML. Errors that reserve space for future expansion As with the restrictions on the syntax intended to allow for new syntax in future revisions of the language, some restrictions on the content models of elements and values of attributes are intended to allow for future expansion of the HTML vocabulary. For example, limiting the values of the target p384 attribute that start with an U+005F LOW LINE character (_) to only specific predefined values allows new predefined values to be introduced at a future time without conflicting with author-defined values. Errors that indicate a mis-use of other specifications Certain restrictions are intended to support the restrictions made by other specifications. For example, requiring that attributes that take media queries use only valid media queries reinforces the importance of following the conformance rules of that specification. 1.11 Recommended reading This section is non-normative. The following documents might be of interest to readers of this specification. Character Model for the World Wide Web 1.0: Fundamentals [CHARMOD] p700 This Architectural Specification provides authors of specifications, software developers, and content developers with a common reference for interoperable text manipulation on the World Wide Web, building on the Universal Character Set, defined jointly by the Unicode Standard and ISO/IEC 10646. Topics addressed include use of the terms 'character', 'encoding' and 'string', a reference processing model, choice and identification of character encodings, character escaping, and string indexing. Unicode Security Considerations [UTR36] p704 Because Unicode contains such a large number of characters and incorporates the varied writing systems of the world, incorrect usage can expose programs or systems to possible security attacks. This is especially important as more and more products are internationalized. This document describes some of the security considerations that programmers, system analysts, standards developers, and users should take into account, and provides specific recommendations to reduce the risk of problems. Web Content Accessibility Guidelines (WCAG) 2.0 [WCAG] p704 Web Content Accessibility Guidelines (WCAG) 2.0 covers a wide range of recommendations for making Web content more accessible. Following these guidelines will make content accessible to a wider range of people with disabilities, including blindness and low vision, deafness and hearing loss, learning disabilities, cognitive limitations, limited movement, speech disabilities, photosensitivity and combinations of these. Following these guidelines will also often make your Web content more usable to users in general. Authoring Tool Accessibility Guidelines (ATAG) 2.0 [ATAG] p700 This specification provides guidelines for designing Web content authoring tools that are more accessible for people with disabilities. An authoring tool that conforms to these guidelines will promote accessibility by providing an accessible user interface to authors with disabilities as well as by enabling, supporting, and promoting the production of accessible Web content by all authors. User Agent Accessibility Guidelines (UAAG) 2.0 [UAAG] p704 This document provides guidelines for designing user agents that lower barriers to Web accessibility for people with disabilities. User agents include browsers and other types of software that retrieve and render Web content. A user agent that conforms to these guidelines will promote accessibility through its own user interface and through other internal facilities, including its ability to communicate with other technologies (especially assistive technologies). Furthermore, all users, not just users with disabilities, should find conforming user agents to be more usable. 25 2 Common infrastructure 2.1 Terminology This specification refers to both HTML and XML attributes and IDL attributes, often in the same context. When it is not clear which is being referred to, they are referred to as content attributes for HTML and XML attributes, and IDL attributes for those defined on IDL interfaces. Similarly, the term "properties" is used for both JavaScript object properties and CSS properties. When these are ambiguous they are qualified as object properties and CSS properties respectively. Generally, when the specification states that a feature applies to the HTML syntax p547 or the XHTML syntax p635 , it also includes the other. When a feature specifically only applies to one of the two languages, it is called out by explicitly stating that it does not apply to the other format, as in "for HTML, ... (this does not apply to XHTML)". This specification uses the term document to refer to any use of HTML, ranging from short static documents to long essays or reports with rich multimedia, as well as to fully-fledged interactive applications. For simplicity, terms such as shown, displayed, and visible might sometimes be used when referring to the way a document is rendered to the user. These terms are not meant to imply a visual medium; they must be considered to apply to other media in equivalent ways. When an algorithm B says to return to another algorithm A, it implies that A called B. Upon returning to A, the implementation must continue from where it left off in calling B. 2.1.1 Resources The specification uses the term supported when referring to whether a user agent has an implementation capable of decoding the semantics of an external resource. A format or type is said to be supported if the implementation can process an external resource of that format or type without critical aspects of the resource being ignored. Whether a specific resource is supported can depend on what features of the resource's format are in use. For example, a PNG image would be considered to be in a supported format if its pixel data could be decoded and rendered, even if, unbeknownst to the implementation, the image also contained animation data. A MPEG4 video file would not be considered to be in a supported format if the compression format used was not supported, even if the implementation could determine the dimensions of the movie from the file's metadata. The term MIME type is used to refer to what is sometimes called an Internet media type in protocol literature. The term media type in this specification is used to refer to the type of media intended for presentation, as used by the CSS specifications. [RFC2046] p702 [MQ] p702 A string is a valid MIME type if it matches the media-type rule defined in section 3.7 "Media Types" of RFC 2616. In particular, a valid MIME type p26 may include MIME type parameters. [HTTP] p701 A string is a valid MIME type with no parameters if it matches the media-type rule defined in section 3.7 "Media Types" of RFC 2616, but does not contain any U+003B SEMICOLON characters (;). In other words, if it consists only of a type and subtype, with no MIME Type parameters. [HTTP] p701 The term HTML MIME type is used to refer to the MIME types p26 text/html p678 and text/html-sandboxed p679 . A resource's critical subresources are those that the resource needs to have available to be correctly processed. Which resources are considered critical or not is defined by the specification that defines the resource's format. For CSS resources, only @import rules introduce critical subresources p26 ; other resources, e.g. fonts or backgrounds, are not. 2.1.2 XML To ease migration from HTML to XHTML, UAs conforming to this specification will place elements in HTML in the http://www.w3.org/1999/xhtml namespace, at least for the purposes of the DOM and CSS. The term "HTML elements", when used in this specification, refers to any element in that namespace, and thus refers to both HTML and XHTML elements. Except where otherwise stated, all elements defined or mentioned in this specification are in the http://www.w3.org/1999/xhtml namespace, and all attributes defined or mentioned in this specification have no namespace. 26 Attribute names are said to be XML-compatible if they match the Name production defined in XML, they contain no U+003A COLON characters (:), and their first three characters are not an ASCII case-insensitive p33 match for the string "xml". [XML] p705 The term XML MIME type is used to refer to the MIME types p26 text/xml, application/xml, and any MIME type p26 whose subtype ends with the four characters "+xml". [RFC3023] p703 2.1.3 DOM trees The term root element, when not explicitly qualified as referring to the document's root element, means the furthest ancestor element node of whatever node is being discussed, or the node itself if it has no ancestors. When the node is a part of the document, then the node's root element p27 is indeed the document's root element; however, if the node is not currently part of the document tree, the root element will be an orphaned node. When an element's root element p27 is the root element of a Document p31 , it is said to be in a Document. An element is said to have been inserted into a document when its root element p27 changes and is now the document's root element p27 . Analogously, an element is said to have been removed from a document when its root element p27 changes from being the document's root element p27 to being another element. A node's home subtree is the subtree rooted at that node's root element p27 . When a node is in a Document p27 , its home subtree p27 is that Document p31 's tree. The Document p31 of a Node p31 (such as an element) is the Document p31 that the Node p31 's ownerDocument IDL attribute returns. When a Node p31 is in a Document p27 then that Document p31 is always the Node p31 's Document p31 , and the Node p31 's ownerDocument IDL attribute thus always returns that Document p31 . The term tree order means a pre-order, depth-first traversal of DOM nodes involved (through the parentNode p31 /childNodes p31 relationship). When it is stated that some element or attribute is ignored, or treated as some other value, or handled as if it was something else, this refers only to the processing of the node after it is in the DOM. A user agent must not mutate the DOM in such situations. The term text node refers to any Text p31 node, including CDATASection p31 nodes; specifically, any Node p31 with node type TEXT_NODE (3) or CDATA_SECTION_NODE (4). [DOMCORE] p701 A content attribute is said to change value only if its new value is different than its previous value; setting an attribute to a value it already has does not change it. 2.1.4 Scripting The construction "a Foo object", where Foo is actually an interface, is sometimes used instead of the more accurate "an object implementing the interface Foo". An IDL attribute is said to be getting when its value is being retrieved (e.g. by author script), and is said to be setting when a new value is assigned to it. If a DOM object is said to be live, then the attributes and methods on that object must operate on the actual underlying data, not a snapshot of the data. The terms fire and dispatch are used interchangeably in the context of events, as in the DOM Events specifications. The term trusted event is used as defined by the DOM Events specification. [DOMEVENTS] p701 2.1.5 Plugins The term plugin is used to mean any content handler that supports displaying content as part of the user agent's rendering of a Document p31 object, but that neither acts as a child browsing context p439 of the Document p31 nor introduces any Node p31 objects to the Document p31 's DOM. Typically such content handlers are provided by third parties, though a user agent can designate content handlers to be plugins. One example of a plugin would be a PDF viewer that is instantiated in a browsing context p439 when the user navigates to a PDF file. This would count as a plugin regardless of whether the party that implemented the PDF viewer component was the same as that which implemented the user agent itself. However, a PDF viewer application that launches separate from the user agent (as opposed to using the same interface) is not a plugin by this definition. Note: This specification does not define a mechanism for interacting with plugins, as it is expected to be user-agent- and platform-specific. Some UAs might opt to support a plugin 27 mechanism such as the Netscape Plugin API; others might use remote content converters or have built-in support for certain types. [NPAPI] p702 ⚠Warning! Browsers should take extreme care when interacting with external content intended for plugins p27 . When third-party software is run with the same privileges as the user agent itself, vulnerabilities in the third-party software become as dangerous as those in the user agent. 2.1.6 Character encodings The preferred MIME name of a character encoding is the name or alias labeled as "preferred MIME name" in the IANA Character Sets registry, if there is one, or the encoding's name, if none of the aliases are so labeled. [IANACHARSET] p701 An ASCII-compatible character encoding is a single-byte or variable-length encoding in which the bytes 0x09, 0x0A, 0x0C, 0x0D, 0x20 - 0x22, 0x26, 0x27, 0x2C - 0x3F, 0x41 - 0x5A, and 0x61 - 0x7A, ignoring bytes that are the second and later bytes of multibyte sequences, all correspond to single-byte sequences that map to the same Unicode characters as those bytes in ANSI_X3.4-1968 (US-ASCII). [RFC1345] p702 Note: This includes such encodings as Shift_JIS, HZ-GB-2312, and variants of ISO-2022, even though it is possible in these encodings for bytes like 0x70 to be part of longer sequences that are unrelated to their interpretation as ASCII. It excludes such encodings as UTF-7, UTF-16, GSM03.38, and EBCDIC variants. The term Unicode character is used to mean a Unicode scalar value (i.e. any Unicode code point that is not a surrogate code point). [UNICODE] p704 2.2 Conformance requirements All diagrams, examples, and notes in this specification are non-normative, as are all sections explicitly marked non-normative. Everything else in this specification is normative. The key words "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this document are to be interpreted as described in RFC2119. For readability, these words do not appear in all uppercase letters in this specification. [RFC2119] p702 Requirements phrased in the imperative as part of algorithms (such as "strip any leading space characters" or "return false and abort these steps") are to be interpreted with the meaning of the key word ("must", "should", "may", etc) used in introducing the algorithm. This specification describes the conformance criteria for user agents (relevant to implementors) and documents (relevant to authors and authoring tool implementors). Conforming documents are those that comply with all the conformance criteria for documents. For readability, some of these conformance requirements are phrased as conformance requirements on authors; such requirements are implicitly requirements on documents: by definition, all documents are assumed to have had an author. (In some cases, that author may itself be a user agent — such user agents are subject to additional rules, as explained below.) For example, if a requirement states that "authors must not use the foobar element", it would imply that documents are not allowed to contain elements named foobar. User agents fall into several (overlapping) categories with different conformance requirements. Web browsers and other interactive user agents Web browsers that support the XHTML syntax p635 must process elements and attributes from the HTML namespace p70 found in XML documents as described in this specification, so that users can interact with them, unless the semantics of those elements have been overridden by other specifications. A conforming XHTML processor would, upon finding an XHTML script p122 element in an XML document, execute the script contained in that element. However, if the element is found within a transformation expressed in XSLT (assuming the user agent also supports XSLT), then the processor would instead treat the script p122 element as an opaque element that forms part of the transform. Web browsers that support the HTML syntax p547 must process documents labeled with an HTML MIME type p26 as described in this specification, so that users can interact with them. User agents that support scripting must also be conforming implementations of the IDL fragments in this specification, as described in the Web IDL specification. [WEBIDL] p704 28 Note: Unless explicitly stated, specifications that override the semantics of HTML elements do not override the requirements on DOM objects representing those elements. For example, the script p122 element in the example above would still implement the HTMLScriptElement p123 interface. Non-interactive presentation user agents User agents that process HTML and XHTML documents purely to render non-interactive versions of them must comply to the same conformance criteria as Web browsers, except that they are exempt from requirements regarding user interaction. Note: Typical examples of non-interactive presentation user agents are printers (static UAs) and overhead displays (dynamic UAs). It is expected that most static non-interactive presentation user agents will also opt to lack scripting support p29 . A non-interactive but dynamic presentation UA would still execute scripts, allowing forms to be dynamically submitted, and so forth. However, since the concept of "focus" is irrelevant when the user cannot interact with the document, the UA would not need to support any of the focus-related DOM APIs. User agents with no scripting support Implementations that do not support scripting (or which have their scripting features disabled entirely) are exempt from supporting the events and DOM interfaces mentioned in this specification. For the parts of this specification that are defined in terms of an events model or in terms of the DOM, such user agents must still act as if events and the DOM were supported. Note: Scripting can form an integral part of an application. Web browsers that do not support scripting, or that have scripting disabled, might be unable to fully convey the author's intent. Conformance checkers Conformance checkers must verify that a document conforms to the applicable conformance criteria described in this specification. Automated conformance checkers are exempt from detecting errors that require interpretation of the author's intent (for example, while a document is non-conforming if the content of a blockquote p151 element is not a quote, conformance checkers running without the input of human judgement do not have to check that blockquote p151 elements only contain quoted material). Conformance checkers must check that the input document conforms when parsed without a browsing context p439 (meaning that no scripts are run, and that the parser's scripting flag p565 is disabled), and should also check that the input document conforms when parsed with a browsing context p439 in which scripts execute, and that the scripts never cause non-conforming states to occur other than transiently during script execution itself. (This is only a "SHOULD" and not a "MUST" requirement because it has been proven to be impossible. [COMPUTABLE] p700 ) The term "HTML validator" can be used to refer to a conformance checker that itself conforms to the applicable requirements of this specification. XML DTDs cannot express all the conformance requirements of this specification. Therefore, a validating XML processor and a DTD cannot constitute a conformance checker. Also, since neither of the two authoring formats defined in this specification are applications of SGML, a validating SGML system cannot constitute a conformance checker either. To put it another way, there are three types of conformance criteria: 1. Criteria that can be expressed in a DTD. 2. Criteria that cannot be expressed by a DTD, but can still be checked by a machine. 3. Criteria that can only be checked by a human. A conformance checker must check for the first two. A simple DTD-based validator only checks for the first class of errors and is therefore not a conforming conformance checker according to this specification. Data mining tools Applications and tools that process HTML and XHTML documents for reasons other than to either render the documents or check them for conformance should act in accordance with the semantics of the documents that they process. 29 A tool that generates document outlines p145 but increases the nesting level for each paragraph and does not increase the nesting level for each section would not be conforming. Authoring tools and markup generators Authoring tools and markup generators must generate conforming documents p28 . Conformance criteria that apply to authors also apply to authoring tools, where appropriate. Authoring tools are exempt from the strict requirements of using elements only for their specified purpose, but only to the extent that authoring tools are not yet able to determine author intent. However, authoring tools must not automatically misuse elements or encourage their users to do so. For example, it is not conforming to use an address p143 element for arbitrary contact information; that element can only be used for marking up contact information for the author of the document or section. However, since an authoring tool is likely unable to determine the difference, an authoring tool is exempt from that requirement. This does not mean, though, that authoring tools can use address p143 elements for any block of italics text (for instance); it just means that the authoring tool doesn't have to verify that when the user uses a tool for inserting contact information for a section, that the user really is doing that and not inserting something else instead. Note: In terms of conformance checking, an editor has to output documents that conform to the same extent that a conformance checker will verify. When an authoring tool is used to edit a non-conforming document, it may preserve the conformance errors in sections of the document that were not edited during the editing session (i.e. an editing tool is allowed to round-trip erroneous content). However, an authoring tool must not claim that the output is conformant if errors have been so preserved. Authoring tools are expected to come in two broad varieties: tools that work from structure or semantic data, and tools that work on a What-You-See-Is-What-You-Get media-specific editing basis (WYSIWYG). The former is the preferred mechanism for tools that author HTML, since the structure in the source information can be used to make informed choices regarding which HTML elements and attributes are most appropriate. However, WYSIWYG tools are legitimate. WYSIWYG tools should use elements they know are appropriate, and should not use elements that they do not know to be appropriate. This might in certain extreme cases mean limiting the use of flow elements to just a few elements, like div p159 , b p175 , i p174 , and span p180 and making liberal use of the style p86 attribute. All authoring tools, whether WYSIWYG or not, should make a best effort attempt at enabling users to create well-structured, semantically rich, media-independent content. Some conformance requirements are phrased as requirements on elements, attributes, methods or objects. Such requirements fall into two categories: those describing content model restrictions, and those describing implementation behavior. Those in the former category are requirements on documents and authoring tools. Those in the second category are requirements on user agents. Similarly, some conformance requirements are phrased as requirements on authors; such requirements are to be interpreted as conformance requirements on the documents that authors produce. (In other words, this specification does not distinguish between conformance criteria on authors and conformance criteria on documents.) Conformance requirements phrased as algorithms or specific steps may be implemented in any manner, so long as the end result is equivalent. (In particular, the algorithms defined in this specification are intended to be easy to follow, and not intended to be performant.) User agents may impose implementation-specific limits on otherwise unconstrained inputs, e.g. to prevent denial of service attacks, to guard against running out of memory, or to work around platform-specific limitations. Note: There is no implied relationship between document conformance requirements and implementation conformance requirements. User agents are not free to handle nonconformant documents as they please; the processing model described in this specification applies to implementations regardless of the conformity of the input documents. For compatibility with existing content and prior specifications, this specification describes two authoring formats: one based on XML (referred to as the XHTML syntax p635 ), and one using a custom format p547 inspired by SGML (referred to as the HTML syntax p547 ). Implementations may support only one of these two formats, although supporting both is encouraged. The language in this specification assumes that the user agent expands all entity references, and therefore does not include entity reference nodes in the DOM. If user agents do include entity reference nodes in the DOM, then user agents must handle them as if they were fully expanded when implementing this specification. For example, if a requirement talks about an element's child text nodes, then any text nodes that are children of an entity reference that is a child of that element would be used as well. Entity references to unknown entities must be 30 treated as if they contained just an empty text node for the purposes of the algorithms defined in this specification. 2.2.1 Dependencies This specification relies on several other underlying specifications. XML Implementations that support the XHTML syntax p635 must support some version of XML, as well as its corresponding namespaces specification, because that syntax uses an XML serialization with namespaces. [XML] p705 [XMLNS] p705 DOM The Document Object Model (DOM) is a representation — a model — of a document and its content. The DOM is not just an API; the conformance criteria of HTML implementations are defined, in this specification, in terms of operations on the DOM. [DOMCORE] p701 Implementations must support some version of DOM Core and DOM Events, because this specification is defined in terms of the DOM, and some of the features are defined as extensions to the DOM Core interfaces. [DOMCORE] p701 [DOMEVENTS] p701 In particular, the following features are defined in the DOM Core specification: [DOMCORE] p701 • • • • • • • • • • • • • • • • • • • • • Attr interface CDATASection interface Comment interface DOMImplementation interface Document interface DocumentFragment interface DocumentType interface DOMException interface Element interface Node interface NodeList interface ProcessingInstruction interface Text interface createDocument() method getElementById() method insertBefore() method childNodes attribute localName attribute parentNode attribute tagName attribute textContent attribute The following features are defined in the DOM Events specification: [DOMEVENTS] p701 • • • • • • Event interface EventTarget interface UIEvent interface click event DOMActivate event target attribute Web IDL The IDL fragments in this specification must be interpreted as required for conforming IDL fragments, as described in the Web IDL specification. [WEBIDL] p704 Except where otherwise specified, if an IDL attribute that is a floating point number type (float) is assigned an Infinity or Not-a-Number (NaN) value, a NOT_SUPPORTED_ERR p70 exception must be raised. Except where otherwise specified, if a method with an argument that is a floating point number type (float) is passed an Infinity or Not-a-Number (NaN) value, a NOT_SUPPORTED_ERR p70 exception must be raised. JavaScript Some parts of the language described by this specification only support JavaScript as the underlying scripting language. [ECMA262] p701 Note: The term "JavaScript" is used to refer to ECMA262, rather than the official term ECMAScript, since the term JavaScript is more widely known. Similarly, the MIME type p26 used to refer to JavaScript in this specification is text/javascript, since that is the most commonly used type, despite it being an officially obsoleted type p17 according to RFC 4329. [RFC4329] p703 31 Media Queries Implementations must support some version of the Media Queries language. [MQ] p702 URIs, IRIs, IDNA Implementations must support the semantics of URLs p51 defined in the URI and IRI specifications, as well as the semantics of IDNA domain names defined in the Internationalizing Domain Names in Applications (IDNA) specification. [RFC3986] p703 [RFC3987] p703 [RFC3490] p703 This specification does not require support of any particular network protocol, style sheet language, scripting language, or any of the DOM specifications beyond those described above. However, the language described by this specification is biased towards CSS as the styling language, JavaScript as the scripting language, and HTTP as the network protocol, and several features assume that those languages and protocols are in use. Note: This specification might have certain additional requirements on character encodings, image formats, audio formats, and video formats in the respective sections. 2.2.2 Extensibility HTML has a wide number of extensibility mechanisms that can be used for adding semantics in a safe manner: • Authors can use the class p86 attribute to extend elements, effectively creating their own elements, while using the most applicable existing "real" HTML element, so that browsers and other tools that don't know of the extension can still support it somewhat well. This is the tack used by Microformats, for example. • Authors can include data for inline client-side scripts or server-side site-wide scripts to process using the data-*="" p87 attributes. These are guaranteed to never be touched by browsers, and allow scripts to include data on HTML elements that scripts can then look for and process. • Authors can use the p112 mechanism to include page-wide metadata by registering extensions to the predefined set of metadata names p114 . • Authors can use the rel="" p384 mechanism to annotate links with specific meanings by registering extensions to the predefined set of link types p393 . This is also used by Microformats. • Authors can embed raw data using the ... Note: The title p107 element is a required child in most situations, but when a higher-level protocol provides title information, e.g. in the Subject line of an e-mail when HTML is used as an e-mail authoring format, the title p107 element can be omitted. 4.2.2 The title element Categories Metadata content p90 . Contexts in which this element may be used: In a head p106 element containing no other title p107 elements. Content model: Text p91 . Content attributes: Global attributes p82 DOM interface: interface HTMLTitleElement : HTMLElement { attribute DOMString text; }; The title p107 element represents p638 the document's title or name. Authors should use titles that identify their documents even when they are used out of context, for example in a user's history or bookmarks, or in search results. The document's title is often different from its first heading, since the first heading does not have to stand alone when taken out of context. There must be no more than one title p107 element per document. 107 This box is non-normative. Implementation requirements are given below this box. title . text p108 [ = value ] Returns the contents of the element, ignoring child nodes that aren't text nodes p27 . Can be set, to replace the element's children with the given value. The IDL attribute text must return a concatenation of the contents of all the text nodes p27 that are direct children of the title p107 element (ignoring any other nodes such as comments or elements), in tree order. On setting, it must act the same way as the textContent p31 IDL attribute. Here are some examples of appropriate titles, contrasted with the top-level headings that might be used on those same pages. Introduction to The Mating Rituals of Bees ...

Introduction

This companion guide to the highly successful Introduction to Medieval Bee-Keeping book is... The next page might be a part of the same site. Note how the title describes the subject matter unambiguously, while the first heading assumes the reader knows what the context is and therefore won't wonder if the dances are Salsa or Waltz: Dances used during bee mating rituals ...

The Dances

The string to use as the document's title is given by the document.title p76 IDL attribute. User agents should use the document's title when referring to the document in their user interface. 4.2.3 The base element Categories Metadata content p90 . Contexts in which this element may be used: In a head p106 element containing no other base p108 elements. Content model: Empty. Content attributes: Global attributes p82 href p108 target p109 DOM interface: interface HTMLBaseElement : HTMLElement { attribute DOMString href; attribute DOMString target; }; The base p108 element allows authors to specify the document base URL p52 for the purposes of resolving relative URLs p51 , and the name of the default browsing context p439 for the purposes of following hyperlinks p384 . The element does not represent p638 any content beyond this information. There must be no more than one base p108 element per document. A base p108 element must have either an href p108 attribute, a target p109 attribute, or both. The href content attribute, if specified, must contain a valid URL p51 . A base p108 element, if it has an href p108 attribute, must come before any other elements in the tree that have attributes defined as taking URLs p51 , except the html p106 element (its manifest p106 attribute isn't affected by base p108 elements). Note: If there are multiple base p108 elements with href p108 attributes, all but the first are ignored. 108 The target attribute, if specified, must contain a valid browsing context name or keyword p442 , which specifies which browsing context p439 is to be used as the default when hyperlinks p383 and forms p297 in the Document p31 cause navigation p459 . A base p108 element, if it has a target p109 attribute, must come before any elements in the tree that represent hyperlinks p383 . Note: If there are multiple base p108 elements with target p109 attributes, all but the first are ignored. The href and target IDL attributes must reflect p57 the respective content attributes of the same name. In this example, a base p108 element is used to set the document base URL p52 : This is an example for the <base> element

Visit the archives.

The link in the above example would be a link to "http://www.example.com/news/archives.html". 4.2.4 The link element Categories Metadata content p90 . If the itemprop p405 attribute is present: flow content p91 . If the itemprop p405 attribute is present: phrasing content p91 . Contexts in which this element may be used: Where metadata content p90 is expected. In a noscript p129 element that is a child of a head p106 element. If the itemprop p405 attribute is present: where phrasing content p91 is expected. Content model: Empty. Content attributes: Global attributes p82 href p109 rel p110 media p111 hreflang p111 type p111 sizes p389 Also, the title p111 attribute has special semantics on this element. DOM interface: interface HTMLLinkElement : HTMLElement { attribute boolean disabled; attribute DOMString href; attribute DOMString rel; readonly attribute DOMTokenList relList; attribute DOMString media; attribute DOMString hreflang; attribute DOMString type; [PutForwards=value] readonly attribute DOMSettableTokenList sizes; }; HTMLLinkElement implements LinkStyle; The link p109 element allows authors to link their document to other resources. The destination of the link(s) is given by the href attribute, which must be present and must contain a valid nonempty URL p51 . If the href p109 attribute is absent, then the element does not define a link. 109 A link p109 element must have either a rel p110 attribute, or an itemprop p405 attribute, or both. The types of link indicated (the relationships) are given by the value of the rel attribute, which, if present, must have a value that is a set of space-separated tokens p49 . The allowed values and their meanings p386 are defined in a later section. If the rel p110 attribute is absent, or if none of the values used are allowed according to the definitions in this specification, then the element does not define a link. Two categories of links can be created using the link p109 element. Links to external resources are links to resources that are to be used to augment the current document, and hyperlink links are links to other documents p383 . The link types section p386 defines whether a particular link type is an external resource or a hyperlink. One element can create multiple links (of which some might be external resource links and some might be hyperlinks); exactly which and how many links are created depends on the keywords given in the rel p110 attribute. User agents must process the links on a per-link basis, not a per-element basis. Note: Each link is handled separately. For instance, if there are two link p109 elements with rel="stylesheet", they each count as a separate external resource, and each is affected by its own attributes independently. The exact behavior for links to external resources depends on the exact relationship, as defined for the relevant link type. Some of the attributes control whether or not the external resource is to be applied (as defined below). For external resources that are represented in the DOM (for example, style sheets), the DOM representation must be made available even if the resource is not applied. To obtain the resource, the user agent must run the following steps: 1. If the href p109 attribute's value is the empty string, then abort these steps. 2. Resolve p51 the URL p51 given by the href p109 attribute, relative to the element. 3. If the previous step fails, then abort these steps. 4. Fetch p55 the resulting absolute URL p52 . User agents may opt to only try to obtain such resources when they are needed, instead of pro-actively fetching p55 all the external resources that are not applied. The semantics of the protocol used (e.g. HTTP) must be followed when fetching external resources. (For example, redirects will be followed and 404 responses will cause the external resource to not be applied.) Once the attempts to obtain the resource and its critical subresources p26 are complete, the user agent must, if the loads were successful, queue a task p490 to fire a simple event p496 named load at the link p109 element, or, if the resource or one of its critical subresources p26 failed to completely load for any reason (e.g. DNS error, HTTP 404 response, a connection being prematurely closed, unsupported Content-Type), queue a task p490 to fire a simple event p496 named error at the link p109 element. Non-network errors in processing the resource or its subresources (e.g. CSS parse errors, PNG decoding errors) are not failures for the purposes of this paragraph. The task source p490 for these tasks p489 is the DOM manipulation task source p491 . The element must delay the load event p619 of the element's document until all the attempts to obtain the resource and its critical subresources p26 are complete. (Resources that the user agent has not yet attempted to obtain, e.g. because it is waiting for the resource to be needed, do not delay the load event p619 .) Interactive user agents may provide users with a means to follow the hyperlinks p384 created using the link p109 element, somewhere within their user interface. The exact interface is not defined by this specification, but it could include the following information (obtained from the element's attributes, again as defined below), in some form or another (possibly simplified), for each hyperlink created with each link p109 element in the document: • The relationship between this document and the resource (given by the rel p110 attribute) • The title of the resource (given by the title p111 attribute). • The address of the resource (given by the href p109 attribute). • The language of the resource (given by the hreflang p111 attribute). • The optimum media for the resource (given by the media p111 attribute). User agents could also include other information, such as the type of the resource (as given by the type p111 attribute). 110 Note: Hyperlinks created with the link p109 element and its rel p110 attribute apply to the whole page. This contrasts with the rel p384 attribute of a p160 and area p266 elements, which indicates the type of a link whose context is given by the link's location within the document. The media attribute says which media the resource applies to. The value must be a valid media query p51 . If the link is a hyperlink p110 then the media p111 attribute is purely advisory, and describes for which media the document in question was designed. However, if the link is an external resource link p110 , then the media p111 attribute is prescriptive. The user agent must apply the external resource when the media p111 attribute's value matches the environment p51 and the other relevant conditions apply, and must not apply it otherwise. Note: The external resource might have further restrictions defined within that limit its applicability. For example, a CSS style sheet might have some @media blocks. This specification does not override such further restrictions or requirements. The default, if the media p111 attribute is omitted, is "all", meaning that by default links apply to all media. The hreflang attribute on the link p109 element has the same semantics as the hreflang attribute on hyperlink elements p384 . The type attribute gives the MIME type p26 of the linked resource. It is purely advisory. The value must be a valid MIME type p26 . For external resource links p110 , the type p111 attribute is used as a hint to user agents so that they can avoid fetching resources they do not support. If the attribute is present, then the user agent must assume that the resource is of the given type (even if that is not a valid MIME type p26 , e.g. the empty string). If the attribute is omitted, but the external resource link type has a default type defined, then the user agent must assume that the resource is of that type. If the UA does not support the given MIME type p26 for the given link relationship, then the UA should not obtain p110 the resource; if the UA does support the given MIME type p26 for the given link relationship, then the UA should obtain p110 the resource. If the attribute is omitted, and the external resource link type does not have a default type defined, but the user agent would obtain p110 the resource if the type was known and supported, then the user agent should obtain p110 the resource under the assumption that it will be supported. User agents must not consider the type p111 attribute authoritative — upon fetching the resource, user agents must not use the type p111 attribute to determine its actual type. Only the actual type (as defined in the next paragraph) is used to determine whether to apply the resource, not the aforementioned assumed type. If the external resource link type defines rules for processing the resource's Content-Type metadata p57 , then those rules apply. Otherwise, if the resource is expected to be an image, user agents may apply the image sniffing rules p57 , with the official type being the type determined from the resource's Content-Type metadata p57 , and use the resulting sniffed type of the resource as if it was the actual type. Otherwise, if neither of these conditions apply or if the user agent opts not to apply the image sniffing rules, then the user agent must use the resource's Content-Type metadata p57 to determine the type of the resource. If there is no type metadata, but the external resource link type has a default type defined, then the user agent must assume that the resource is of that type. Note: The stylesheet p391 link type defines rules for processing the resource's Content-Type metadata p57 . Once the user agent has established the type of the resource, the user agent must apply the resource if it is of a supported type and the other relevant conditions apply, and must ignore the resource otherwise. If a document contains style sheet links labeled as follows: ...then a compliant UA that supported only CSS style sheets would fetch the B and C files, and skip the A file (since text/plain is not the MIME type p26 for CSS style sheets). For files B and C, it would then check the actual types returned by the server. For those that are sent as text/css, it would apply the styles, but for those labeled as text/plain, or any other type, it would not. If one of the two files was returned without a Content-Type p57 metadata, or with a syntactically incorrect type like Content-Type: "null", then the default type for stylesheet p391 links would kick in. Since that default type is text/css, the style sheet would nonetheless be applied. The title attribute gives the title of the link. With one exception, it is purely advisory. The value is text. The exception is for style sheet links, where the title p111 attribute defines alternative style sheet sets. 111 Note: The title p111 attribute on link p109 elements differs from the global title p84 attribute of most other elements in that a link without a title does not inherit the title of the parent element: it merely has no title. The sizes p389 attribute is used with the icon p389 link type. The attribute must not be specified on link p109 elements that do not have a rel p110 attribute that specifies the icon p389 keyword. Some versions of HTTP defined a Link: header, to be processed like a series of link p109 elements. If supported, for the purposes of ordering links defined by HTTP headers must be assumed to come before any links in the document, in the order that they were given in the HTTP entity header. (URIs in these headers are to be processed and resolved according to the rules given in HTTP; the rules of this specification don't apply.) [HTTP] p701 [WEBLINK] p704 The IDL attributes href, rel, media, hreflang, and type, and sizes each must reflect p57 the respective content attributes of the same name. The IDL attribute relList must reflect p57 the rel p110 content attribute. The IDL attribute disabled only applies to style sheet links. When the link p109 element defines a style sheet link, then the disabled p112 attribute behaves as defined for the alternative style sheets DOM p122 . For all other link p109 elements it always return false and does nothing on setting. The LinkStyle interface is also implemented by this element; the styling processing model p121 defines how. [CSSOM] p700 Here, a set of link p109 elements provide some style sheets: href="contrast.css" title="High contrast"> href="big.css" title="Big fonts"> href="wide.css" title="Wide screen"> The following example shows how you can specify versions of the page that use alternative formats, are aimed at other languages, and that are intended for other media: 4.2.5 The meta element Categories Metadata content p90 . If the itemprop p405 attribute is present: flow content p91 . If the itemprop p405 attribute is present: phrasing content p91 . Contexts in which this element may be used: If the charset p113 attribute is present, or if the element's http-equiv p115 attribute is in the Encoding declaration state p116 : in a head p106 element. If the http-equiv p115 attribute is present but not in the Encoding declaration state p116 : in a head p106 element. If the http-equiv p115 attribute is present but not in the Encoding declaration state p116 : in a noscript p129 element that is a child of a head p106 element. If the name p113 attribute is present: where metadata content p90 is expected. If the itemprop p405 attribute is present: where metadata content p90 is expected. If the itemprop p405 attribute is present: where phrasing content p91 is expected. 112 Content model: Empty. Content attributes: Global attributes p82 name p113 http-equiv p115 content p113 charset p113 DOM interface: interface HTMLMetaElement : HTMLElement { attribute DOMString name; attribute DOMString httpEquiv; attribute DOMString content; }; The meta p112 element represents p638 various kinds of metadata that cannot be expressed using the title p107 , base p108 , link p109 , style p119 , and script p122 elements. The meta p112 element can represent document-level metadata with the name p113 attribute, pragma directives with the http-equiv p115 attribute, and the file's character encoding declaration p118 when an HTML document is serialized to string form (e.g. for transmission over the network or for disk storage) with the charset p113 attribute. Exactly one of the name p113 , http-equiv p115 , charset p113 , and itemprop p405 attributes must be specified. If either name p113 , http-equiv p115 , or itemprop p405 is specified, then the content p113 attribute must also be specified. Otherwise, it must be omitted. The charset attribute specifies the character encoding used by the document. This is a character encoding declaration p118 . If the attribute is present in an XML document p71 , its value must be an ASCII case-insensitive p33 match for the string "UTF-8" (and the document is therefore forced to use UTF-8 as its encoding). Note: The charset p113 attribute on the meta p112 element has no effect in XML documents, and is only allowed in order to facilitate migration to and from XHTML. There must not be more than one meta p112 element with a charset p113 attribute per document. The content attribute gives the value of the document metadata or pragma directive when the element is used for those purposes. The allowed values depend on the exact context, as described in subsequent sections of this specification. If a meta p112 element has a name attribute, it sets document metadata. Document metadata is expressed in terms of name/value pairs, the name p113 attribute on the meta p112 element giving the name, and the content p113 attribute on the same element giving the value. The name specifies what aspect of metadata is being set; valid names and the meaning of their values are described in the following sections. If a meta p112 element has no content p113 attribute, then the value part of the metadata name/value pair is the empty string. The name and content IDL attributes must reflect p57 the respective content attributes of the same name. The IDL attribute httpEquiv must reflect p57 the content attribute http-equiv p115 . 4.2.5.1 Standard metadata names This specification defines a few names for the name p113 attribute of the meta p112 element. Names are case-insensitive, and must be compared in an ASCII case-insensitive p33 manner. application-name The value must be a short free-form string giving the name of the Web application that the page represents. If the page is not a Web application, the application-name p113 metadata name must not be used. There must not be more than one meta p112 element with its name p113 attribute set to the value applicationname p113 per document. User agents may use the application name in UI in preference to the page's title p107 , since the title might include status messages and the like relevant to the status of the page at a particular moment in time instead of just being the name of the application. author The value must be a free-form string giving the name of one of the page's authors. 113 description The value must be a free-form string that describes the page. The value must be appropriate for use in a directory of pages, e.g. in a search engine. There must not be more than one meta p112 element with its name p113 attribute set to the value description p114 per document. generator The value must be a free-form string that identifies one of the software packages used to generate the document. This value must not be used on hand-authored pages. Here is what a tool called "Frontweaver" could include in its output, in the page's head p106 element, to identify itself as the tool used to generate the page: keywords The value must be a set of comma-separated tokens p50 , each of which is a keyword relevant to the page. This page about typefaces on British motorways uses a meta p112 element to specify some keywords that users might use to look for the page: Typefaces on UK motorways ... Note: Many search engines do not consider such keywords, because this feature has historically been used unreliably and even misleadingly as a way to spam search engine results in a way that is not helpful for users. To obtain the list of keywords that the author has specified as applicable to the page, the user agent must run the following steps: 1. Let keywords be an empty list. 2. For each meta p112 element with a name p113 attribute and a content p113 attribute and whose name p113 attribute's value is keywords p114 , run the following substeps: 1. Split the value of the element's content attribute on commas p50 . 2. Add the resulting tokens, if any, to keywords. 3. Remove any duplicates from keywords. 4. Return keywords. This is the list of keywords that the author has specified as applicable to the page. User agents should not use this information when there is insufficient confidence in the reliability of the value. For instance, it would be reasonable for a content management system to use the keyword information of pages within the system to populate the index of a site-specific search engine, but a large-scale content aggregator that used this information would likely find that certain users would try to game its ranking mechanism through the use of inappropriate keywords. 4.2.5.2 Other metadata names Extensions to the predefined set of metadata names may be registered in the WHATWG Wiki MetaExtensions page. [WHATWGWIKI] p704 Anyone is free to edit the WHATWG Wiki MetaExtensions page at any time to add a type. These new names must be specified with the following information: Keyword The actual name being defined. The name should not be confusingly similar to any other defined name (e.g. differing only in case). Brief description A short non-normative description of what the metadata name's meaning is, including the format the value is required to be in. 114 Specification A link to a more detailed description of the metadata name's semantics and requirements. It could be another page on the Wiki, or a link to an external page. Synonyms A list of other names that have exactly the same processing requirements. Authors should not use the names defined to be synonyms, they are only intended to allow user agents to support legacy content. Anyone may remove synonyms that are not used in practice; only names that need to be processed as synonyms for compatibility with legacy content are to be registered in this way. Status One of the following: Proposed The name has not received wide peer review and approval. Someone has proposed it and is, or soon will be, using it. Ratified The name has received wide peer review and approval. It has a specification that unambiguously defines how to handle pages that use the name, including when they use it in incorrect ways. Discontinued The metadata name has received wide peer review and it has been found wanting. Existing pages are using this metadata name, but new pages should avoid it. The "brief description" and "specification" entries will give details of what authors should use instead, if anything. If a metadata name is found to be redundant with existing values, it should be removed and listed as a synonym for the existing value. If a metadata name is registered in the "proposed" state for a period of a month or more without being used or specified, then it may be removed from the registry. If a metadata name is added with the "proposed" status and found to be redundant with existing values, it should be removed and listed as a synonym for the existing value. If a metadata name is added with the "proposed" status and found to be harmful, then it should be changed to "discontinued" status. Anyone can change the status at any time, but should only do so in accordance with the definitions above. Conformance checkers must use the information given on the WHATWG Wiki MetaExtensions page to establish if a value is allowed or not: values defined in this specification or marked as "proposed" or "ratified" must be accepted, whereas values marked as "discontinued" or not listed in either this specification or on the aforementioned page must be rejected as invalid. Conformance checkers may cache this information (e.g. for performance reasons or to avoid the use of unreliable network connectivity). When an author uses a new metadata name not defined by either this specification or the Wiki page, conformance checkers should offer to add the value to the Wiki, with the details described above, with the "proposed" status. Metadata names whose values are to be URLs p51 must not be proposed or accepted. Links must be represented using the link p109 element, not the meta p112 element. 4.2.5.3 Pragma directives When the http-equiv attribute is specified on a meta p112 element, the element is a pragma directive. The http-equiv p115 attribute is an enumerated attribute p34 . The following table lists the keywords defined for this attribute. The states given in the first cell of the rows with keywords give the states to which those keywords map. State Content Language Keywords p115 Notes content-language Conformance checkers will include a warning Encoding declaration p116 content-type Default style p116 default-style Refresh p116 refresh When a meta p112 element is inserted into the document p27 , if its http-equiv p115 attribute is present and represents one of the above states, then the user agent must run the algorithm appropriate for that state, as described in the following list: Content language state (http-equiv="content-language") This pragma sets the pragma-set default language. Until the pragma is successfully processed, there is no pragma-set default language p115 . Note: Conformance checkers will include a warning if this pragma is used. Authors are encouraged to use the lang p85 attribute instead. 115 1. If another meta p112 element with an http-equiv p115 attribute in the Content Language state p115 has already been successfully processed (i.e. when it was inserted the user agent processed it and reached the last step of this list of steps), then abort these steps. 2. If the meta p112 element has no content p113 attribute, or if that attribute's value is the empty string, then abort these steps. 3. If the element's content p113 attribute contains a U+002C COMMA character (,) then abort these steps. 4. Let input be the value of the element's content p113 attribute. 5. Let position point at the first character of input. 6. Skip whitespace p34 . 7. Collect a sequence of characters p34 that are not space characters p34 . 8. Let the pragma-set default language p115 be the string that resulted from the previous step. For meta p112 elements with an http-equiv p115 attribute in the Content Language state p115 , the content p113 attribute must have a value consisting of a valid BCP 47 language code. [BCP47] p700 Note: This pragma is not exactly equivalent to the HTTP Content-Language header, for instance it only supports one language. [HTTP] p701 Encoding declaration state (http-equiv="content-type") The Encoding declaration state p116 is just an alternative form of setting the charset attribute: it is a character encoding declaration p118 . This state's user agent requirements are all handled by the parsing section of the specification. For meta p112 elements with an http-equiv p115 attribute in the Encoding declaration state p116 , the content p113 attribute must have a value that is an ASCII case-insensitive p33 match for a string that consists of: the literal string "text/html;", optionally followed by any number of space characters p34 , followed by the literal string "charset=", followed by the character encoding name of the character encoding declaration p118 . If the document contains a meta p112 element with an http-equiv p115 attribute in the Encoding declaration state p116 , then the document must not contain a meta p112 element with the charset p113 attribute present. The Encoding declaration state p116 may be used in HTML documents p71 , but elements with an http-equiv p115 attribute in that state must not be used in XML documents p71 . Default style state (http-equiv="default-style") This pragma sets the name of the default alternative style sheet set. 1. If the meta p112 element has no content p113 attribute, or if that attribute's value is the empty string, then abort these steps. 2. Set the preferred style sheet set to the value of the element's content p113 attribute. [CSSOM] p700 Refresh state (http-equiv="refresh") This pragma acts as timed redirect. 116 1. If another meta p112 element with an http-equiv p115 attribute in the Refresh state p116 has already been successfully processed (i.e. when it was inserted the user agent processed it and reached the last step of this list of steps), then abort these steps. 2. If the meta p112 element has no content p113 attribute, or if that attribute's value is the empty string, then abort these steps. 3. Let input be the value of the element's content p113 attribute. 4. Let position point at the first character of input. 5. Skip whitespace p34 . 6. Collect a sequence of characters p34 in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), and parse the resulting string using the rules for parsing non-negative integers p35 . If the sequence of characters collected is the empty string, then no number will have been parsed; abort these steps. Otherwise, let time be the parsed number. 7. Collect a sequence of characters p34 in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9) and U+002E FULL STOP (.). Ignore any collected characters. 8. Skip whitespace p34 . 9. Let url be the address of the current page. 10. If the character in input pointed to by position is a U+003B SEMICOLON (";"), then advance position to the next character. Otherwise, jump to the last step. 11. Skip whitespace p34 . 12. If the character in input pointed to by position is a U+0055 LATIN CAPITAL LETTER U character (U) or a U+0075 LATIN SMALL LETTER U character (u), then advance position to the next character. Otherwise, jump to the last step. 13. If the character in input pointed to by position is a U+0052 LATIN CAPITAL LETTER R character (R) or a U+0072 LATIN SMALL LETTER R character (r), then advance position to the next character. Otherwise, jump to the last step. 14. If the character in input pointed to by position is s U+004C LATIN CAPITAL LETTER L character (L) or a U+006C LATIN SMALL LETTER L character (l), then advance position to the next character. Otherwise, jump to the last step. 15. Skip whitespace p34 . 16. If the character in input pointed to by position is a U+003D EQUALS SIGN ("="), then advance position to the next character. Otherwise, jump to the last step. 17. Skip whitespace p34 . 18. If the character in input pointed to by position is either a U+0027 APOSTROPHE character (') or U+0022 QUOTATION MARK character ("), then let quote be that character, and advance position to the next character. Otherwise, let quote be the empty string. 19. Let url be equal to the substring of input from the character at position to the end of the string. 20. If quote is not the empty string, and there is a character in url equal to quote, then truncate url at that character, so that it and all subsequent characters are removed. 21. Strip any trailing space characters p34 from the end of url. 22. Strip any U+0009 CHARACTER TABULATION, U+000A LINE FEED (LF), and U+000D CARRIAGE RETURN (CR) characters from url. 23. Resolve p51 the url value to an absolute URL p52 , relative to the meta p112 element. If this fails, abort these steps. 24. Perform one or more of the following steps: • Set a timer so that in time seconds, adjusted to take into account user or user agent preferences, if the user has not canceled the redirect and if the meta p112 element's Document p31 's browsing context p439 did not have the sandboxed automatic features browsing context flag p203 set when the Document p31 was created, the user agent navigates p459 the Document p31 's browsing context p439 to url, with replacement enabled p466 , and with the Document p31 's browsing context p439 as the source browsing context p459 . • Provide the user with an interface that, when selected, navigates p459 a browsing context p439 to url, with the document's browsing context as the source browsing context p459 . • Do nothing. In addition, the user agent may, as with anything, inform the user of any and all aspects of its operation, including the state of any timers, the destinations of any timed redirects, and so forth. For meta p112 elements with an http-equiv p115 attribute in the Refresh state p116 , the content p113 attribute must have a value consisting either of: • just a valid non-negative integer p35 , or • a valid non-negative integer p35 , followed by a U+003B SEMICOLON character (;), followed by one or more space characters p34 , followed by either a U+0055 LATIN CAPITAL LETTER U character (U) or a U+0075 LATIN SMALL LETTER U character (u), a U+0052 LATIN CAPITAL LETTER R character (R) or a U+0072 LATIN SMALL LETTER R character (r), a U+004C LATIN CAPITAL LETTER L character (L) or a U+006C LATIN SMALL LETTER L character (l), a U+003D EQUALS SIGN character (=), and then a valid URL p51 . 117 In the former case, the integer represents a number of seconds before the page is to be reloaded; in the latter case the integer represents a number of seconds before the page is to be replaced by the page at the given URL p51 . A news organization's front page could include the following markup in the page's head p106 element, to ensure that the page automatically reloads from the server every five minutes: A sequence of pages could be used as an automated slide show by making each page refresh to the next page in the sequence, using markup such as the following: There must not be more than one meta p112 element with any particular state in the document at a time. 4.2.5.4 Other pragma directives Extensions to the predefined set of pragma directives may, under certain conditions, be registered in the WHATWG Wiki PragmaExtensions page. [WHATWGWIKI] p704 Such extensions must use a name that is identical to an HTTP header registered in the Permanent Message Header Field Registry, and must have behavior identical to that described for the HTTP header. [IANAPERMHEADERS] p701 Pragma directives corresponding to headers describing metadata, or not requiring specific user agent processing, must not be registered; instead, use metadata names p114 . Pragma directives corresponding to headers that affect the HTTP processing model (e.g. caching) must not be registered, as they would result in HTTP-level behavior being different for user agents that implement HTML than for user agents that do not. Anyone is free to edit the WHATWG Wiki PragmaExtensions page at any time to add a pragma directive satisfying these conditions. Such registrations must specify the following information: Keyword The actual name being defined. The name must match a previously-registered HTTP name with the same requirements. Brief description A short non-normative description of the purpose of the pragma directive. Specification A link to the specification defining the corresponding HTTP header. Conformance checkers must use the information given on the WHATWG Wiki PragmaExtensions page to establish if a value is allowed or not: values defined in this specification or listed on the aforementioned page must be accepted, whereas values not listed in either this specification or on the aforementioned page must be rejected as invalid. Conformance checkers may cache this information (e.g. for performance reasons or to avoid the use of unreliable network connectivity). 4.2.5.5 Specifying the document's character encoding A character encoding declaration is a mechanism by which the character encoding used to store or transmit a document is specified. The following restrictions apply to character encoding declarations: • The character encoding name given must be the name of the character encoding used to serialize the file. • The value must be a valid character encoding name, and must be an ASCII case-insensitive p33 match for the preferred MIME name p28 for that encoding. [IANACHARSET] p701 • The character encoding declaration must be serialized without the use of character references p553 or character escapes of any kind. • The element containing the character encoding declaration must be serialized completely within the first 512 bytes of the document. • There can only be one character encoding declaration in the document. If an HTML document p71 does not start with a BOM, and if its encoding is not explicitly given by Content-Type metadata p57 , and the document is not an iframe srcdoc document p200 , then the character encoding used must be an ASCII-compatible character encoding p28 , and, in addition, if that encoding isn't US-ASCII itself, then the 118 encoding must be specified using a meta p112 element with a charset p113 attribute or a meta p112 element with an http-equiv p115 attribute in the Encoding declaration state p116 . If the document is an iframe srcdoc document p200 , the document must not have a character encoding declaration p118 . (In this case, the source is already decoded, since it is part of the document that contained the iframe p199 .) If an HTML document p71 contains a meta p112 element with a charset p113 attribute or a meta p112 element with an http-equiv p115 attribute in the Encoding declaration state p116 , then the character encoding used must be an ASCIIcompatible character encoding p28 . Authors are encouraged to use UTF-8. Conformance checkers may advise authors against using legacy encodings. Authoring tools should default to using UTF-8 for newly-created documents. Encodings in which a series of bytes in the range 0x20 to 0x7E can encode characters other than the corresponding characters in the range U+0020 to U+007E represent a potential security vulnerability: a user agent that does not support the encoding (or does not support the label used to declare the encoding, or does not use the same mechanism to detect the encoding of unlabelled content as another user agent) might end up interpreting technically benign plain text content as HTML tags and JavaScript. For example, this applies to encodings in which the bytes corresponding to " The data in this case might be used by the script to generate the map of a video game. The data doesn't have to be used that way, though; maybe the map data is actually embedded in other parts of the page's markup, and the data block here is just used by the site's search engine to help users who are looking for particular features in their game maps. The following sample shows how a script element can be used to define a function that is then used by other parts of the document. It also shows how a script p122 element can be used to invoke script while the document is being parsed, in this case to initialize the form's output.
Work out the price of your car

Base cost: £52000.

Select additional options:

Total: £

4.3.1.1 Scripting languages A user agent is said to support the scripting language if the script block's type p124 is an ASCII caseinsensitive p33 match for the MIME type p26 string of a scripting language that the user agent implements. The following lists some MIME type p26 strings and the languages to which they refer: 127 "application/ecmascript" "application/javascript" "application/x-ecmascript" "application/x-javascript" "text/ecmascript" "text/javascript" "text/javascript1.0" "text/javascript1.1" "text/javascript1.2" "text/javascript1.3" "text/javascript1.4" "text/javascript1.5" "text/jscript" "text/livescript" "text/x-ecmascript" "text/x-javascript" JavaScript. [ECMA262] p701 "text/javascript;e4x=1" JavaScript with ECMAScript for XML. [ECMA357] p701 User agents may support other MIME types p26 and other languages. When examining types to determine if they support the language, user agents must not ignore unknown MIME parameters — types with unknown parameters must be assumed to be unsupported. The charset parameter must be treated as an unknown parameter for the purpose of comparing MIME types p26 here. 4.3.1.2 Restrictions for contents of script elements The textContent p31 of a script p122 element must match the script production in the following ABNF, the character set for which is Unicode. [ABNF] p700 128 script escape = data1 *( escape [ script-start data3 ] "-->" data1 ) [ escape ] = "" data3 not-data3 = = script-end / "-->" script-start script-end = lt s c r i p t tag-end = lt slash s c r i p t tag-end lt slash = = %x003C ; U+003C LESS-THAN SIGN character (<) %x002F ; U+002F SOLIDUS character (/) s s c c r r i i p p t t = =/ = =/ = =/ = =/ = =/ = =/ %x0053 %x0073 %x0043 %x0063 %x0052 %x0072 %x0049 %x0069 %x0050 %x0070 %x0054 %x0074 ; ; ; ; ; ; ; ; ; ; ; ; U+0053 U+0073 U+0043 U+0063 U+0052 U+0072 U+0049 U+0069 U+0050 U+0070 U+0054 U+0074 LATIN LATIN LATIN LATIN LATIN LATIN LATIN LATIN LATIN LATIN LATIN LATIN tag-end tag-end tag-end tag-end = =/ =/ =/ %x0009 %x000A %x000C %x0020 ; ; ; ; U+0009 U+000A U+000C U+0020 CHARACTER TABULATION LINE FEED (LF) FORM FEED (FF) SPACE CAPITAL LETTER SMALL LETTER S CAPITAL LETTER SMALL LETTER C CAPITAL LETTER SMALL LETTER R CAPITAL LETTER SMALL LETTER I CAPITAL LETTER SMALL LETTER P CAPITAL LETTER SMALL LETTER T S C R I P T tag-end tag-end =/ %x002F ; U+002F SOLIDUS (/) =/ %x003E ; U+003E GREATER-THAN SIGN (>) When a script p122 element contains script documentation p129 , there are further restrictions on the contents of the element, as described in the section below. 4.3.1.3 Inline documentation for external scripts If a script p122 element's src p123 attribute is specified, then the contents of the script p122 element, if any, must be such that the value of the text p126 IDL attribute, which is derived from the element's contents, matches the documentation production in the following ABNF, the character set for which is Unicode. [ABNF] p700 documentation = *( *( space / tab / comment ) [ line-comment ] newline ) comment = slash star *( not-star / star not-slash ) 1*star slash line-comment = slash slash *not-newline ; characters tab newline space star slash not-newline not-star not-slash = = = = = = %x0009 ; U+0009 TAB %x000A ; U+000A LINE FEED (LF) %x0020 ; U+0020 SPACE %x002A ; U+002A ASTERISK (*) %x002F ; U+002F SOLIDUS (/) %x0000-0009 / %x000B-10FFFF ; a Unicode character other than U+000A LINE FEED (LF) = %x0000-0029 / %x002B-10FFFF ; a Unicode character other than U+002A ASTERISK (*) = %x0000-002E / %x0030-10FFFF ; a Unicode character other than U+002F SOLIDUS (/) Note: This corresponds to putting the contents of the element in JavaScript comments. Note: This requirement is in addition to the earlier restrictions on the syntax of contents of script p122 elements. This allows authors to include documentation, such as license information or API information, inside their documents while still referring to external script files. The syntax is constrained so that authors don't accidentally include what looks like valid script while also providing a src p123 attribute. 4.3.2 The noscript element Categories Metadata content p90 . Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: In a head p106 element of an HTML document p71 , if there are no ancestor noscript p129 elements. Where phrasing content p91 is expected in HTML documents p71 , if there are no ancestor noscript p129 elements. Content model: When scripting is disabled p487 , in a head p106 element: in any order, zero or more link p109 elements, zero or more style p119 elements, and zero or more meta p112 elements. When scripting is disabled p487 , not in a head p106 element: transparent p93 , but there must be no noscript p129 element descendants. Otherwise: text that conforms to the requirements given in the prose. Content attributes: Global attributes p82 129 DOM interface: Uses HTMLElement p81 . The noscript p129 element represents p638 nothing if scripting is enabled p487 , and represents p638 its children if scripting is disabled p487 . It is used to present different markup to user agents that support scripting and those that don't support scripting, by affecting how the document is parsed. When used in HTML documents p71 , the allowed content model is as follows: In a head p106 element, if scripting is disabled p487 for the noscript p129 element The noscript p129 element must contain only link p109 , style p119 , and meta p112 elements. In a head p106 element, if scripting is enabled p487 for the noscript p129 element The noscript p129 element must contain only text, except that invoking the HTML fragment parsing algorithm p626 with the noscript p129 element as the context element and the text contents as the input must result in a list of nodes that consists only of link p109 , style p119 , and meta p112 elements that would be conforming if they were children of the noscript p129 element, and no parse errors p554 . Outside of head p106 elements, if scripting is disabled p487 for the noscript p129 element The noscript p129 element's content model is transparent p93 , with the additional restriction that a noscript p129 element must not have a noscript p129 element as an ancestor (that is, noscript p129 can't be nested). Outside of head p106 elements, if scripting is enabled p487 for the noscript p129 element The noscript p129 element must contain only text, except that the text must be such that running the following algorithm results in a conforming document with no noscript p129 elements and no script p122 elements, and such that no step in the algorithm causes an HTML parser p554 to flag a parse error p554 : 1. Remove every script p122 element from the document. 2. Make a list of every noscript p129 element in the document. For every noscript p129 element in that list, perform the following steps: 1. Let the parent element be the parent element of the noscript p129 element. 2. Take all the children of the parent element that come before the noscript p129 element, and call these elements the before children. 3. Take all the children of the parent element that come after the noscript p129 element, and call these elements the after children. 4. Let s be the concatenation of all the text node p27 children of the noscript p129 element. 5. Set the innerHTML p102 attribute of the parent element to the value of s. (This, as a sideeffect, causes the noscript p129 element to be removed from the document.) 6. Insert the before children at the start of the parent element, preserving their original relative order. 7. Insert the after children at the end of the parent element, preserving their original relative order. Note: All these contortions are required because, for historical reasons, the noscript p129 element is handled differently by the HTML parser p554 based on whether scripting was enabled or not p565 when the parser was invoked. The noscript p129 element must not be used in XML documents p71 . Note: The noscript p129 element is only effective in the HTML syntax p547 , it has no effect in the XHTML syntax p635 . The noscript p129 element has no other requirements. In particular, children of the noscript p129 element are not exempt from form submission p360 , scripting, and so forth, even when scripting is enabled p487 for the element. In the following example, a noscript p129 element is used to provide fallback for a script.

: 130

When script is disabled, a button appears to do the calculation on the server side. When script is enabled, the value is computed on-the-fly instead. The noscript p129 element is a blunt instrument. Sometimes, scripts might be enabled, but for some reason the page's script might fail. For this reason, it's generally better to avoid using noscript p129 , and to instead design the script to change the page from being a scriptless page to a scripted page on the fly, as in the next example:

:

The above technique is also useful in XHTML, since noscript p129 is not supported in the XHTML syntax p635 . 4.4 Sections 4.4.1 The body element Categories Sectioning root p144 . Contexts in which this element may be used: As the second element in an html p106 element. Content model: Flow content p91 . Content attributes: Global attributes p82 onafterprint p495 onbeforeprint p495 onbeforeunload p495 onblur p495 onerror p495 onfocus p495 onhashchange p495 131 onload p495 onmessage p495 onoffline p495 ononline p495 onpagehide p495 onpageshow p495 onpopstate p495 onredo p495 onresize p495 onstorage p496 onundo p496 onunload p496 DOM interface: interface HTMLBodyElement : HTMLElement { attribute Function onafterprint; attribute Function onbeforeprint; attribute Function onbeforeunload; attribute Function onblur; attribute Function onerror; attribute Function onfocus; attribute Function onhashchange; attribute Function onload; attribute Function onmessage; attribute Function onoffline; attribute Function ononline; attribute Function onpopstate; attribute Function onpagehide; attribute Function onpageshow; attribute Function onredo; attribute Function onresize; attribute Function onstorage; attribute Function onundo; attribute Function onunload; }; The body p131 element represents p638 the main content of the document. In conforming documents, there is only one body p131 element. The document.body p77 IDL attribute provides scripts with easy access to a document's body p131 element. Note: Some DOM operations (for example, parts of the drag and drop p522 model) are defined in terms of "the body element p76 ". This refers to a particular element in the DOM, as per the definition of the term, and not any arbitrary body p131 element. The body p131 element exposes as event handler content attributes p492 a number of the event handlers p492 of the Window p443 object. It also mirrors their event handler IDL attributes p492 . The onblur p495 , onerror p495 , onfocus p495 , and onload p495 event handlers p492 of the Window p443 object, exposed on the body p131 element, shadow the generic event handlers p492 with the same names normally supported by HTML elements p26 . Thus, for example, a bubbling error event fired on a child of the body element p76 of a Document p31 would first trigger the onerror p495 event handler content attributes p492 of that element, then that of the root html p106 element, and only then would it trigger the onerror p495 event handler content attribute p492 on the body p131 element. This is because the event would bubble from the target, to the body p131 , to the html p106 , to the Document p31 , to the Window p443 , and the event handler p492 on the body p131 is watching the Window p443 not the body p131 . A regular event listener attached to the body p131 using addEventListener(), however, would fire when the event bubbled through the body p131 and not when it reaches the Window p443 object. This page updates an indicator to show whether or not the user is online: Online or offline?

You are: (Unknown)

4.4.2 The section element Categories Flow content p91 . Sectioning content p91 . formatBlock candidate p536 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Flow content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The section p133 element represents p638 a generic document or application section. A section, in this context, is a thematic grouping of content, typically with a heading. Examples of sections would be chapters, the various tabbed pages in a tabbed dialog box, or the numbered sections of a thesis. A Web site's home page could be split into sections for an introduction, news items, contact information. Note: Authors are encouraged to use the article p136 element instead of the section p133 element when it would make sense to syndicate the contents of the element. Note: The section p133 element is not a generic container element. When an element is needed for styling purposes or as a convenience for scripting, authors are encouraged to use the div p159 element instead. A general rule is that the section p133 element is appropriate only if the element's contents would be listed explicitly in the document's outline p145 . In the following example, we see an article (part of a larger Web page) about apples, containing two short sections.

Apples

Tasty, delicious fruit!

The apple is the pomaceous fruit of the apple tree.

Red Delicious

These bright red apples are the most common found in many supermarkets.

Granny Smith

These juicy, green apples make a great filling for apple pies.

Notice how the use of section p133 means that the author can use h1 p139 elements throughout, without having to worry about whether a particular section is at the top level, the second level, the third level, and so on. 133 Here is a graduation programme with two sections, one for the list of people graduating, and one for the description of the ceremony. Graduation Ceremony Summer 2022

Graduation

Ceremony

Opening Procession

Speech by Validactorian

Speech by Class President

Presentation of Diplomas

Closing Speech by Headmaster

Graduates

  • Molly Carpenter
  • Anastasia Luccio
  • Ebenezar McCoy
  • Karrin Murphy
  • Thomas Raith
  • Susan Rodriguez
4.4.3 The nav element Categories Flow content p91 . Sectioning content p91 . formatBlock candidate p536 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Flow content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The nav p134 element represents p638 a section of a page that links to other pages or to parts within the page: a section with navigation links. 134 Not all groups of links on a page need to be in a nav p134 element — only sections that consist of major navigation blocks are appropriate for the nav p134 element. In particular, it is common for footers to have a short list of links to various pages of a site, such as the terms of service, the home page, and a copyright page. The footer p142 element alone is sufficient for such cases, without a nav p134 element. Note: User agents (such as screen readers) that are targeted at users who can benefit from navigation information being omitted in the initial rendering, or who can benefit from navigation information being immediately available, can use this element as a way to determine what content on the page to initially skip and/or provide on request. In the following example, the page has several places where links are present, but only one of those places is considered a navigation section.

Wake up sheeple!

News Blog Forums

Last Modified:

My Day at the Beach

Today I went to the beach and had a lot of fun.

...more content...

Posted .

...more blog posts...
Notice the div p159 elements being used to wrap all the contents of the page other than the header and footer, and all the contents of the blog entry other than its header and footer. In the following example, there are two nav p134 elements, one for primary navigation around the site, and one for secondary navigation around the page itself.

The Wiki Center Of Exampland

© copyright 1998 Exampland Emperor

4.4.4 The article element Categories Flow content p91 . Sectioning content p91 . formatBlock candidate p536 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Flow content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The article p136 element represents p638 a component of a page that consists of a self-contained composition in a document, page, application, or site and that is intended to be independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content. When article p136 elements are nested, the inner article p136 elements represent articles that are in principle related to the contents of the outer article. For instance, a blog entry on a site that accepts user-submitted comments could represent the comments as article p136 elements nested within the article p136 element for the blog entry. Author information associated with an article p136 element (q.v. the address p143 element) does not apply to nested article p136 elements. Note: When used specifically with content to be redistributed in syndication, the article p136 element is similar in purpose to the entry element in Atom. [ATOM] p700 Note: The time p168 element's pubdate p169 attribute can be used to provide the publication date for an article p136 element. This example shows a blog post using the article p136 element: 136

The Very First Rule of Life

If there's a microphone anywhere near you, assume it's hot and sending whatever you're saying to the world. Seriously.

...

Here is that same blog post, but showing some of the comments:

The Very First Rule of Life

If there's a microphone anywhere near you, assume it's hot and sending whatever you're saying to the world. Seriously.

...

Comments

Posted by: George Washington

Yeah! Especially when talking about your lobbyist friends!

Posted by: George Hammond

Hey, you have the same first name as me.

Notice the use of footer p142 to give the information each comment (such as who wrote it and when): the footer p142 element can appear at the start of its section when appropriate, such as in this case. (Using header p140 in this case wouldn't be wrong either; it's mostly a matter of authoring preference.) 4.4.5 The aside element Categories Flow content p91 . Sectioning content p91 . formatBlock candidate p536 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Flow content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The aside p137 element represents p638 a section of a page that consists of content that is tangentially related to the content around the aside p137 element, and which could be considered separate from that content. Such sections are often represented as sidebars in printed typography. The element can be used for typographical effects like pull quotes or sidebars, for advertising, for groups of nav p134 elements, and for other content that is considered separate from the main content of the page. 137 Note: It's not appropriate to use the aside p137 element just for parentheticals, since those are part of the main flow of the document. The following example shows how an aside is used to mark up background material on Switzerland in a much longer news story on Europe. The following example shows how an aside is used to mark up a pull quote in a longer article. ...

He later joined a large company, continuing on the same work. I love my job. People ask me what I do for fun when I'm not at work. But I'm paid to do my hobby, so I never know what to answer. Some people wonder what they would do if they didn't have to work... but I know what I would do, because I was unemployed for a year, and I filled that time doing exactly what I do now.

Of course his work — or should that be hobby? — isn't his only passion. He also enjoys other pleasures.

... The following extract shows how aside p137 can be used for blogrolls and other side content on a blog:

My wonderful blog

My tagline

138

My last post

This is my last post.

My first post

This is my first post.

4.4.6 The h1, h2, h3, h4, h5, and h6 elements Categories Flow content p91 . Heading content p91 . formatBlock candidate p536 . Contexts in which this element may be used: As a child of an hgroup p140 element. Where flow content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: interface HTMLHeadingElement : HTMLElement {}; These elements represent p638 headings for their sections. The semantics and meaning of these elements are defined in the section on headings and sections p144 . These elements have a rank given by the number in their name. The h1 p139 element is said to have the highest rank, the h6 p139 element has the lowest rank, and two elements with the same name have equal rank. These two snippets are equivalent:

Let's call it a draw(ing surface)

Diving in

Simple shapes

Canvas coordinates

Canvas coordinates diagram

Paths

139

Let's call it a draw(ing surface)

Diving in

Simple shapes

Canvas coordinates

Canvas coordinates diagram

Paths

4.4.7 The hgroup element Categories Flow content p91 . Heading content p91 . formatBlock candidate p536 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: One or more h1 p139 , h2 p139 , h3 p139 , h4 p139 , h5 p139 , and/or h6 p139 elements. Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The hgroup p140 element represents p638 the heading of a section. The element is used to group a set of h1 p139 –h6 p139 elements when the heading has multiple levels, such as subheadings, alternative titles, or taglines. For the purposes of document summaries, outlines, and the like, the text of hgroup p140 elements is defined to be the text of the highest ranked p139 h1 p139 –h6 p139 element descendant of the hgroup p140 element, if there are any such elements, and the first such element if there are multiple elements with that rank p139 . If there are no such elements, then the text of the hgroup p140 element is the empty string. Other elements of heading content p91 in the hgroup p140 element indicate subheadings or subtitles. The rank p139 of an hgroup p140 element is the rank of the highest-ranked h1 p139 –h6 p139 element descendant of the hgroup p140 element, if there are any such elements, or otherwise the same as for an h1 p139 element (the highest rank). The section on headings and sections p144 defines how hgroup p140 elements are assigned to individual sections. Here are some examples of valid headings. In each case, the emphasized text represents the text that would be used as the heading in an application extracting heading data and ignoring subheadings.

The reality dysfunction

Space is not the only void

Dr. Strangelove

Or: How I Learned to Stop Worrying and Love the Bomb

The point of using hgroup p140 in these examples is to mask the h2 p139 element (which acts as a secondary title) from the outline p145 algorithm. 4.4.8 The header element 140 Categories Flow content p91 . formatBlock candidate p536 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Flow content p91 , but with no header p140 or footer p142 element descendants. Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The header p140 element represents p638 a group of introductory or navigational aids. Note: A header p140 element is intended to usually contain the section's heading (an h1 p139 –h6 p139 element or an hgroup p140 element), but this is not required. The header p140 element can also be used to wrap a section's table of contents, a search form, or any relevant logos. Here are some sample headers. This first one is for a game:

Welcome to...

Voidwars!

The following snippet shows how the element can be used to mark up a specification's header:

Scalable Vector Graphics (SVG) 1.2

W3C Working Draft 27 October 2004

This version:
http://www.w3.org/TR/2004/ WD-SVG12-20041027/
Previous version:
http://www.w3.org/TR/2004/ WD-SVG12-20040510/
Latest version of SVG 1.2:
http://www.w3.org/TR/SVG12/
Latest SVG Recommendation:
http://www.w3.org/TR/SVG/
Editor:
Dean Jackson, W3C, dean@w3.org
Authors:
See Author List
  • Forum
  • Download 141

    Important News

    To play today's games you will need to update your client.

    Games

  • You have three active games:

    ... 4.4.9 The footer element Categories Flow content p91 . formatBlock candidate p536 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Flow content p91 , but with no header p140 or footer p142 element descendants. Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The footer p142 element represents p638 a footer for its nearest ancestor sectioning content p91 or sectioning root p144 element. A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like. Note: Contact information for the author or editor of a section belongs in an address p143 element, possibly itself inside a footer p142 . Footers don't necessarily have to appear at the end of a section, though they usually do. When the footer p142 element contains entire sections, they represent p638 appendices, indexes, long colophons, verbose license agreements, and other such content. Note: The footer p142 element is not sectioning content p91 ; it doesn't introduce a new section. When the nearest ancestor sectioning content p91 or sectioning root p144 element is the body element p76 , then it applies to the whole page. Here is a page with two footers, one at the top and one at the bottom, with the same content:

    Lorem ipsum

    The ipsum of all lorems

    A dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

    Here is an example which shows the footer p142 element being used both for a site-wide footer and for a section footer. The Ramblings of a Scientist 142

    The Ramblings of a Scientist

    My Favorite Trains

    I love my trains. My favorite train of all time is a Köf.

    It is fun to see them pull some coal cars because they look so dwarfed in comparison.

    Published

    4.4.10 The address element Categories Flow content p91 . formatBlock candidate p536 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Flow content p91 , but with no heading content p91 descendants, no sectioning content p91 descendants, and no header p140 , footer p142 , or address p143 element descendants. Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The address p143 element represents p638 the contact information for its nearest article p136 or body p131 element ancestor. If that is the body element p76 , then the contact information applies to the document as a whole. For example, a page at the W3C Web site related to HTML might include the following contact information:
    Dave Raggett, Arnaud Le Hors, contact persons for the W3C HTML Activity
    The address p143 element must not be used to represent arbitrary addresses (e.g. postal addresses), unless those addresses are in fact the relevant contact information. (The p p148 element is the appropriate element for marking up postal addresses in general.) The address p143 element must not contain information other than contact information. For example, the following is non-conforming use of the address p143 element:
    Last Modified: 1999/12/24 23:37:50
    Typically, the address p143 element would be included along with other information in a footer p142 element. 143 The contact information for a node node is a collection of address p143 elements defined by the first applicable entry from the following list: p136 element ↪ If node is an article p131 element ↪ If node is a body The contact information consists of all the address p143 elements that have node as an ancestor and do not have another body p131 or article p136 element ancestor that is a descendant of node. p136 element ↪ If node has an ancestor element that is an article p131 element ↪ If node has an ancestor element that is a body The contact information of node is the same as the contact information of the nearest article p136 or body p131 element ancestor, whichever is nearest. p31 has a body element p76 ↪ If node's Document The contact information of node is the same as the contact information the body element p76 of the Document p31 . ↪ Otherwise There is no contact information for node. User agents may expose the contact information of a node to the user, or use it for other purposes, such as indexing sections based on the sections' contact information. 4.4.11 Headings and sections The h1 p139 –h6 p139 elements and the hgroup p140 element are headings. The first element of heading content p91 in an element of sectioning content p91 represents p638 the heading for that section. Subsequent headings of equal or higher rank p139 start new (implied) sections, headings of lower rank p139 start implied subsections that are part of the previous one. In both cases, the element represents p638 the heading of the implied section. Certain elements are said to be sectioning roots, including blockquote p151 and td p282 elements. These elements can have their own outlines, but the sections and headings inside these elements do not contribute to the outlines of their ancestors. ⇒ blockquote p151 , body p131 , details p367 , fieldset p300 , figure p158 , td p282 Sectioning content p91 elements are always considered subsections of their nearest ancestor sectioning root p144 or their nearest ancestor element of sectioning content p91 , whichever is nearest, regardless of what implied sections other headings may have created. For the following fragment:

    Foo

    Bar

    Bla

    Baz

    Quux

    Thud

    Grunt

    ...the structure would be: 1. Foo (heading of explicit body p131 section, containing the "Grunt" paragraph) 1. Bar (heading starting implied section, containing a block quote and the "Baz" paragraph) 2. Quux (heading starting implied section with no content other than the heading itself) 3. Thud (heading of explicit section p133 section) Notice how the section p133 ends the earlier implicit section so that a later paragraph ("Grunt") is back at the top level. Sections may contain headings of any rank p139 , but authors are strongly encouraged to either use only h1 p139 elements, or to use elements of the appropriate rank p139 for the section's nesting level. 144 Authors are also encouraged to explicitly wrap sections in elements of sectioning content p91 , instead of relying on the implicit sections generated by having multiple headings in one element of sectioning content p91 . For example, the following is correct:

    Apples

    Apples are fruit.

    Taste

    They taste lovely.

    Sweet

    Red apples are sweeter than green ones.

    Color

    Apples come in various colors.

    However, the same document would be more clearly expressed as:

    Apples

    Apples are fruit.

    Taste

    They taste lovely.

    Sweet

    Red apples are sweeter than green ones.

    Color

    Apples come in various colors.

    Both of the documents above are semantically identical and would produce the same outline in compliant user agents. 4.4.11.1 Creating an outline This section defines an algorithm for creating an outline for a sectioning content p91 element or a sectioning root p144 element. It is defined in terms of a walk over the nodes of a DOM tree, in tree order, with each node being visited when it is entered and when it is exited during the walk. The outline for a sectioning content p91 element or a sectioning root p144 element consists of a list of one or more potentially nested sections p145 . A section is a container that corresponds to some nodes in the original DOM tree. Each section can have one heading associated with it, and can contain any number of further nested sections. The algorithm for the outline also associates each node in the DOM tree with a particular section and potentially a heading. (The sections in the outline aren't section p133 elements, though some may correspond to such elements — they are merely conceptual sections.) The following markup fragment:

    A

    B

    C

    D

    E

    F

    ...results in the following outline being created for the body p131 node (and thus the entire document): 1. Section created for body p131 node. Associated with heading "A". Also associated with paragraph "B". Nested sections: 1. Section implied for first h2 p139 element. Associated with heading "C". 145 2. Also associated with paragraph "D". No nested sections. Section implied for second h2 p139 element. Associated with heading "E". Also associated with paragraph "F". No nested sections. The algorithm that must be followed during a walk of a DOM subtree rooted at a sectioning content p91 element or a sectioning root p144 element to determine that element's outline p145 is as follows: 1. Let current outlinee be null. (It holds the element whose outline p145 is being created.) 2. Let current section be null. (It holds a pointer to a section p145 , so that elements in the DOM can all be associated with a section.) 3. Create a stack to hold elements, which is used to handle nesting. Initialize this stack to empty. 4. As you walk over the DOM in tree order p27 , trigger the first relevant step below for each element as you enter and exit it. ↪ If the top of the stack is an element, and you are exiting that element Note: The element being exited is a heading content p91 element. Pop that element from the stack. p91 element ↪ If the top of the stack is a heading content Do nothing. p91 element or a sectioning root p144 element ↪ When entering a sectioning content If current outlinee is not null, and the current section has no heading, create an implied heading and let that be the heading for the current section. If current outlinee is not null, push current outlinee onto the stack. Let current outlinee be the element that is being entered. Let current section be a newly created section p145 for the current outlinee element. Let there be a new outline p145 for the new current outlinee, initialized with just the new current section as the only section p145 in the outline. p91 element, if the stack is not empty ↪ When exiting a sectioning content Pop the top element from the stack, and let the current outlinee be that element. Let current section be the last section in the outline p145 of the current outlinee element. Append the outline p145 of the sectioning content p91 element being exited to the current section. (This does not change which section is the last section in the outline p145 .) p144 element, if the stack is not empty ↪ When exiting a sectioning root Run these steps: 1. Pop the top element from the stack, and let the current outlinee be that element. 2. Let current section be the last section in the outline p145 of the current outlinee element. 3. Finding the deepest child: If current section has no child sections, stop these steps. 4. Let current section be the last child section p145 of the current current section. 5. Go back to the substep labeled finding the deepest child. p91 element or a sectioning root p144 element ↪ When exiting a sectioning content Note: The current outlinee is the element being exited. Let current section be the first section p145 in the outline p145 of the current outlinee element. Skip to the next step in the overall set of steps. (The walk is over.) ↪ If the current outlinee is null Do nothing. 146 p91 element ↪ When entering a heading content If the current section has no heading, let the element being entered be the heading for the current section. Otherwise, if the element being entered has a rank p139 equal to or greater than the heading of the last section of the outline p145 of the current outlinee, then create a new section p145 and append it to the outline p145 of the current outlinee element, so that this new section is the new last section of that outline. Let current section be that new section. Let the element being entered be the new heading for the current section. Otherwise, run these substeps: 1. Let candidate section be current section. 2. If the element being entered has a rank p139 lower than the rank p139 of the heading of the candidate section, then create a new section p145 , and append it to candidate section. (This does not change which section is the last section in the outline.) Let current section be this new section. Let the element being entered be the new heading for the current section. Abort these substeps. 3. Let new candidate section be the section p145 that contains candidate section in the outline p145 of current outlinee. 4. Let candidate section be new candidate section. 5. Return to step 2. Push the element being entered onto the stack. (This causes the algorithm to skip any descendants of the element.) Note: Recall that h1 p139 has the highest rank, and h6 p139 has the lowest rank. ↪ Otherwise Do nothing. In addition, whenever you exit a node, after doing the steps above, if current section is not null, associate the node with the section p145 current section. 5. If the current outlinee is null, then there was no sectioning content p91 element or sectioning root p144 element in the DOM. There is no outline p145 . Abort these steps. 6. Associate any nodes that were not associated with a section p145 in the steps above with current outlinee as their section. 7. Associate all nodes with the heading of the section p145 with which they are associated, if any. 8. If current outlinee is the body element p76 , then the outline created for that element is the outline p145 of the entire document. The tree of sections created by the algorithm above, or a proper subset thereof, must be used when generating document outlines, for example when generating tables of contents. When creating an interactive table of contents, entries should jump the user to the relevant sectioning content p91 element, if the section p145 was created for a real element in the original document, or to the relevant heading content p91 element, if the section p145 in the tree was generated for a heading in the above process. Note: Selecting the first section p145 of the document therefore always takes the user to the top of the document, regardless of where the first heading in the body p131 is to be found. The outline depth of a heading content p91 element associated with a section p145 section is the number of sections p145 that are ancestors of section in the outline p145 that section finds itself in when the outlines p145 of its Document p31 's elements are created, plus 1. The outline depth p147 of a heading content p91 element not associated with a section p145 is 1. User agents should provide default headings for sections that do not have explicit section headings. Consider the following snippet:

    Hello world.

    Although it contains no headings, this snippet has three sections: a document (the body p131 ) with two subsections (a nav p134 and an aside p137 ). A user agent could present the outline as follows: 1. Untitled document 1. Navigation 2. Sidebar These default headings ("Untitled document", "Navigation", "Sidebar") are not specified by this specification, and might vary with the user's language, the page's language, the user's preferences, the user agent implementor's preferences, etc. The following JavaScript function shows how the tree walk could be implemented. The root argument is the root of the tree to walk, and the enter and exit arguments are callbacks that are called with the nodes as they are entered and exited. [ECMA262] p701 function (root, enter, exit) { var node = root; start: while (node) { enter(node); if (node.firstChild) { node = node.firstChild; continue start; } while (node) { exit(node); if (node.nextSibling) { node = node.nextSibling; continue start; } if (node == root) node = null; else node = node.parentNode; } } } 4.5 Grouping content 4.5.1 The p element Categories Flow content p91 . formatBlock candidate p536 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: interface HTMLParagraphElement : HTMLElement {}; The p p148 element represents p638 a paragraph p93 . The following examples are conforming HTML fragments:

    The little kitten gently seated himself on a piece of carpet. Later in his life, this would be referred to as the time the cat sat on the mat.

    Personal information

    148

    There was once an example from Femley,
    Whose markup was of dubious quality.
    The validator complained,
    So the author was pained,
    To move the error from the markup to the rhyming.

    The p p148 element should not be used when a more specific element is more appropriate. The following example is technically correct:

    Last modified: 2001-04-23

    Author: fred@example.com

    However, it would be better marked-up as:
    Last modified: 2001-04-23
    Author: fred@example.com
    Or:

    Last modified: 2001-04-23

    Author: fred@example.com
    4.5.2 The hr element Categories Flow content p91 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Empty. Content attributes: Global attributes p82 DOM interface: interface HTMLHRElement : HTMLElement {}; The hr p149 element represents p638 a paragraph p93 -level thematic break, e.g. a scene change in a story, or a transition to another topic within a section of a reference book. The following extract from Pandora's Star by Peter F. Hamilton shows two paragraphs that precede a scene change and the paragraph that follows it. The scene change, represented in the printed book by a gap containing a solitary centered star between the second and third paragraphs, is here represented using the hr p149 element.

    Dudley was ninety-two, in his second life, and fast approaching time for another rejuvenation. Despite his body having the physical age of a standard fifty-year-old, the prospect of a long degrading campaign within academia was one he regarded with dread. For a supposedly advanced civilization, the Intersolar Commonwearth could be appallingly backward at times, not to mention cruel.

    Maybe it won't be that bad, he told himself. The lie was comforting enough to get him through the rest of the night's 149 shift.


    The Carlton AllLander drove Dudley home just after dawn. Like the astronomer, the vehicle was old and worn, but perfectly capable of doing its job. It had a cheap diesel engine, common enough on a semi-frontier world like Gralmond, although its drive array was a thoroughly modern photoneural processor. With its high suspension and deep-tread tyres it could plough along the dirt track to the observatory in all weather and seasons, including the metre-deep snow of Gralmond's winters.

    4.5.3 The pre element Categories Flow content p91 . formatBlock candidate p536 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: interface HTMLPreElement : HTMLElement {}; The pre p150 element represents p638 a block of preformatted text, in which structure is represented by typographic conventions rather than by elements. Note: In the HTML syntax p547 , a leading newline character immediately following the pre p150 element start tag is stripped. Some examples of cases where the pre p150 element could be used: • Including an e-mail, with paragraphs indicated by blank lines, lists indicated by lines prefixed with a bullet, and so on. • Including fragments of computer code, with structure indicated according to the conventions of that language. • Displaying ASCII art. Note: Authors are encouraged to consider how preformatted text will be experienced when the formatting is lost, as will be the case for users of speech synthesizers, braille displays, and the like. For cases like ASCII art, it is likely that an alternative presentation, such as a textual description, would be more universally accessible to the readers of the document. To represent a block of computer code, the pre p150 element can be used with a code p171 element; to represent a block of computer output the pre p150 element can be used with a samp p172 element. Similarly, the kbd p173 element can be used within a pre p150 element to indicate text that the user is to enter. In the following snippet, a sample of computer code is presented.

    This is the Panel constructor:

    function Panel(element, canClose, closeHandler) {
    this.element = element;
    this.canClose = canClose;
    this.closeHandler = function () { if (closeHandler) closeHandler() };
    }
    In the following snippet, samp p172 and kbd p173 elements are mixed in the contents of a pre p150 element to show a session of Zork I.
    You are in an open field west of a big white house with a boarded
    front door.
    There is a small mailbox here.
    > open mailbox
    
    150
    
    Opening the mailbox reveals:
    A leaflet.
    >
    The following shows a contemporary poem that uses the pre p150 element to preserve its unusual formatting, which forms an intrinsic part of the poem itself.
    
    maxling
    
    it is with a
    
    heart
    heavy
    
    that i admit loss of a feline
    so
    loved
    a friend lost to the
    unknown
    (night)
    ~cdr 11dec07
    4.5.4 The blockquote element Categories Flow content p91 . Sectioning root p144 . formatBlock candidate p536 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Flow content p91 . Content attributes: Global attributes p82 cite p151 DOM interface: interface HTMLQuoteElement : HTMLElement { attribute DOMString cite; }; Note: The HTMLQuoteElement p151 interface is also used by the q p166 element. The blockquote p151 element represents p638 a section that is quoted from another source. Content inside a blockquote p151 must be quoted from another source, whose address, if it has one, should be cited in the cite attribute. If the cite p151 attribute is present, it must be a valid URL p51 . To obtain the corresponding citation link, the value of the attribute must be resolved p51 relative to the element. User agents should allow users to follow such citation links. The cite IDL attribute must reflect p57 the element's cite content attribute. This next example shows the use of cite p165 alongside blockquote p151 :

    His next piece was the aptly named Sonnet 130:

    My mistress' eyes are nothing like the sun,
    Coral is far more red, than her lips red,
    ... This example shows how a forum post could use blockquote p151 to show what post a user is replying to. The article p136 element is used for each post, to mark up the threading.

    Bacon on a crowbar

    151
    t3yw 12 points 1 hour ago

    I bet a narwhal would love that.

    greg 8 points 1 hour ago

    I bet a narwhal would love that.

    Dude narwhals don't eat bacon.

    t3yw 15 points 1 hour ago

    I bet a narwhal would love that.

    Dude narwhals don't eat bacon.

    Next thing you'll be saying they don't get capes and wizard hats either!

    boing -5 points 1 hour ago

    narwhals are worse than ceiling cat

    fred 1 points 23 minutes ago

    I bet a narwhal would love that.

    I bet they'd love to peel a banana too.

    Note: Examples of how to represent a conversation p395 are shown in a later section; it is not appropriate to use the cite p165 and blockquote p151 elements for this purpose. 4.5.5 The ol element Categories Flow content p91 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Zero or more li p154 elements. Content attributes: Global attributes p82 reversed p152 start p153 DOM interface: interface HTMLOListElement : HTMLElement { attribute boolean reversed; attribute long start; }; The ol p152 element represents p638 a list of items, where the items have been intentionally ordered, such that changing the order would change the meaning of the document. The items of the list are the li p154 element child nodes of the ol p152 element, in tree order p27 . The reversed attribute is a boolean attribute p34 . If present, it indicates that the list is a descending list (..., 3, 2, 1). If the attribute is omitted, the list is an ascending list (1, 2, 3, ...). 152 The start attribute, if present, must be a valid integer p35 giving the ordinal value of the first list item. If the start p153 attribute is present, user agents must parse it as an integer p35 , in order to determine the attribute's value. The default value, used if the attribute is missing or if the value cannot be converted to a number according to the referenced algorithm, is 1 if the element has no reversed p152 attribute, and is the number of child li p154 elements otherwise. The first item in the list has the ordinal value given by the ol p152 element's start p153 attribute, unless that li p154 element has a value p154 attribute with a value that can be successfully parsed, in which case it has the ordinal value given by that value p154 attribute. Each subsequent item in the list has the ordinal value given by its value p154 attribute, if it has one, or, if it doesn't, the ordinal value of the previous item, plus one if the reversed p152 is absent, or minus one if it is present. The reversed IDL attribute must reflect p57 the value of the reversed p152 content attribute. The start IDL attribute must reflect p57 the value of the start p153 content attribute. The following markup shows a list where the order matters, and where the ol p152 element is therefore appropriate. Compare this list to the equivalent list in the ul p153 section to see an example of the same items using the ul p153 element.

    I have lived in the following countries (given in the order of when I first lived there):

    1. Switzerland
    2. United Kingdom
    3. United States
    4. Norway
    Note how changing the order of the list changes the meaning of the document. In the following example, changing the relative order of the first two items has changed the birthplace of the author:

    I have lived in the following countries (given in the order of when I first lived there):

    1. United Kingdom
    2. Switzerland
    3. United States
    4. Norway
    4.5.6 The ul element Categories Flow content p91 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Zero or more li p154 elements. Content attributes: Global attributes p82 DOM interface: interface HTMLUListElement : HTMLElement {}; The ul p153 element represents p638 a list of items, where the order of the items is not important — that is, where changing the order would not materially change the meaning of the document. The items of the list are the li p154 element child nodes of the ul p153 element. The following markup shows a list where the order does not matter, and where the ul p153 element is therefore appropriate. Compare this list to the equivalent list in the ol p152 section to see an example of the same items using the ol p152 element.

    I have lived in the following countries:

    • Norway 153
    • Switzerland
    • United Kingdom
    • United States
    Note that changing the order of the list does not change the meaning of the document. The items in the snippet above are given in alphabetical order, but in the snippet below they are given in order of the size of their current account balance in 2007, without changing the meaning of the document whatsoever:

    I have lived in the following countries:

    • Switzerland
    • Norway
    • United Kingdom
    • United States
    4.5.7 The li element Categories None. Contexts in which this element may be used: Inside ol p152 elements. Inside ul p153 elements. Inside menu p372 elements. Content model: Flow content p91 . Content attributes: Global attributes p82 If the element is a child of an ol p152 element: value p154 DOM interface: interface HTMLLIElement : HTMLElement { attribute long value; }; The li p154 element represents p638 a list item. If its parent element is an ol p152 , ul p153 , or menu p372 element, then the element is an item of the parent element's list, as defined for those elements. Otherwise, the list item has no defined list-related relationship to any other li p154 element. The value attribute, if present, must be a valid integer p35 giving the ordinal value of the list item. If the value p154 attribute is present, user agents must parse it as an integer p35 , in order to determine the attribute's value. If the attribute's value cannot be converted to a number, the attribute must be treated as if it was absent. The attribute has no default value. The value p154 attribute is processed relative to the element's parent ol p152 element (q.v.), if there is one. If there is not, the attribute has no effect. The value IDL attribute must reflect p57 the value of the value p154 content attribute. The following example, the top ten movies are listed (in reverse order). Note the way the list is given a title by using a figure p158 element and its figcaption p159 element.
    The top 10 movies of all time
    1. Josie and the Pussycats, 2001
    2. Црна мачка, бели мачор, 1998
    3. A Bug's Life, 1998
    4. Toy Story, 1995
    5. Monsters, Inc, 2001
    6. Cars, 2006
    7. Toy Story 2, 1999
    8. Finding Nemo, 2003
    9. The Incredibles, 2004
    10. Ratatouille, 2007
    11. 154
    The markup could also be written as follows, using the reversed p152 attribute on the ol p152 element:
    The top 10 movies of all time
    1. Josie and the Pussycats, 2001
    2. Црна мачка, бели мачор, 1998
    3. A Bug's Life, 1998
    4. Toy Story, 1995
    5. Monsters, Inc, 2001
    6. Cars, 2006
    7. Toy Story 2, 1999
    8. Finding Nemo, 2003
    9. The Incredibles, 2004
    10. Ratatouille, 2007
    Note: If the li p154 element is the child of a menu p372 element and itself has a child that defines a command p376 , then the li p154 element will match the :enabled p398 and :disabled p398 pseudoclasses in the same way as the first such child element does. 4.5.8 The dl element Categories Flow content p91 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Zero or more groups each consisting of one or more dt p157 elements followed by one or more dd p157 elements. Content attributes: Global attributes p82 DOM interface: interface HTMLDListElement : HTMLElement {}; The dl p155 element represents p638 an association list consisting of zero or more name-value groups (a description list). Each group must consist of one or more names (dt p157 elements) followed by one or more values (dd p157 elements). Within a single dl p155 element, there should not be more than one dt p157 element for each name. Name-value groups may be terms and definitions, metadata topics and values, or any other groups of name-value data. The values within a group are alternatives; multiple paragraphs forming part of the same value must all be given within the same dd p157 element. The order of the list of groups, and of the names and values within each group, may be significant. If a dl p155 element is empty, it contains no groups. If a dl p155 element contains non-whitespace p89 text nodes p27 , or elements other than dt p157 and dd p157 , then those elements or text nodes p27 do not form part of any groups in that dl p155 . If a dl p155 element contains only dt p157 elements, then it consists of one group with names but no values. If a dl p155 element contains only dd p157 elements, then it consists of one group with values but no names. If a dl p155 element starts with one or more dd p157 elements, then the first group has no associated name. If a dl p155 element ends with one or more dt p157 elements, then the last group has no associated value. 155 Note: When a dl p155 element doesn't match its content model, it is often due to accidentally using dd p157 elements in the place of dt p157 elements and vice versa. Conformance checkers can spot such mistakes and might be able to advise authors how to correctly use the markup. In the following example, one entry ("Authors") is linked to two values ("John" and "Luke").
    Authors John Luke Editor Frank In the following example, one definition is linked to two terms.
    color
    colour
    A sensation which (in humans) derives from the ability of the fine structure of the eye to distinguish three differently filtered analyses of a view.
    The following example illustrates the use of the dl p155 element to mark up metadata of sorts. At the end of the example, one group has two metadata labels ("Authors" and "Editors") and two values ("Robert Rothman" and "Daniel Jackson").
    Last modified time 2004-12-23T23:33Z Recommended update interval 60s Authors Editors Robert Rothman Daniel Jackson The following example shows the dl p155 element used to give a set of instructions. The order of the instructions here is important (in the other examples, the order of the blocks was not important).

    Determine the victory points as follows (use the first matching case):

    If you have exactly five gold coins
    You get five victory points
    If you have one or more gold coins, and you have one or more silver coins
    You get two victory points
    If you have one or more silver coins
    You get one victory point
    Otherwise
    You get no victory points
    The following snippet shows a dl p155 element being used as a glossary. Note the use of dfn p167 to indicate the word being defined.
    Apartment, n.
    An execution context grouping one or more threads with one or more COM objects.
    Flat, n.
    A deflated tire.
    Home, n.
    The user's login directory.
    Note: The dl p155 element is inappropriate for marking up dialogue. Examples of how to mark up dialogue p395 are shown below. 156 4.5.9 The dt element Categories None. Contexts in which this element may be used: Before dd p157 or dt p157 elements inside dl p155 elements. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The dt p157 element represents p638 the term, or name, part of a term-description group in a description list (dl p155 element). Note: The dt p157 element itself, when used in a dl p155 element, does not indicate that its contents are a term being defined, but this can be indicated using the dfn p167 element. This example shows a list of frequently asked questions (a FAQ) marked up using the dt p157 element for questions and the dd p157 element for answers.

    FAQ

    What do we want?
    Our data.
    When do we want it?
    Now.
    Where is it?
    We are not sure.
    4.5.10 The dd element Categories None. Contexts in which this element may be used: After dt p157 or dd p157 elements inside dl p155 elements. Content model: Flow content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The dd p157 element represents p638 the description, definition, or value, part of a term-description group in a description list (dl p155 element). A dl p155 can be used to define a vocabulary list, like in a dictionary. In the following example, each entry, given by a dt p157 with a dfn p167 , has several dd p157 s, showing the various parts of the definition.
    happiness
    /'hæ p. nes/
    n.
    The state of being happy.
    Good fortune; success. Oh happiness! It worked!
    rejoice
    /ri jois'/
    v.intr. To be delighted oneself.
    v.tr. To cause one to be 157 delighted.
    4.5.11 The figure element Categories Flow content p91 . Sectioning root p144 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Either: One figcaption p159 element followed by flow content p91 . Or: Flow content p91 followed by one figcaption p159 element. Or: Flow content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The figure p158 element represents p638 some flow content p91 , optionally with a caption, that is self-contained and is typically referenced as a single unit from the main flow of the document. The element can thus be used to annotate illustrations, diagrams, photos, code listings, etc, that are referred to from the main content of the document, but that could, without affecting the flow of the document, be moved away from that primary content, e.g. to the side of the page, to dedicated pages, or to an appendix. The first figcaption p159 element child of the element, if any, represents the caption of the figure p158 element's contents. If there is no child figcaption p159 element, then there is no caption. This example shows the figure p158 element to mark up a code listing.

    In listing 4 we see the primary core interface API declaration.

    Listing 4. The primary core interface API declaration.
    interface PrimaryCore {
    boolean verifyDataLine();
    void sendData(in sequence<byte> data);
    void initSelfDestruct();
    }

    The API is designed to use UTF-8.

    Here we see a figure p158 element to mark up a photo.
    Bubbles, sitting in his office chair, works on his
latest project intently.
    Bubbles at work
    In this example, we see an image that is not a figure, as well as an image and a video that are.

    Malinko's comics

    This case centered on some sort of "intellectual property" infringement related to a comic (see Exhibit A). The suit started after a trailer ending with these words:

    ROUGH COPY! Promblem-Packed Action!

    ...was aired. A lawyer, armed with a Bigger Notebook, launched a preemptive strike using snowballs. A complete copy of the trailer is included with Exhibit B. 158

    Two squiggles on a dirty piece of paper.
    Exhibit A. The alleged rough copy comic.
    Exhibit B. The Rough Copy trailer.

    The case was resolved out of court. Here, a part of a poem is marked up using figure p158 .

    'Twas brillig, and the slithy toves
    Did gyre and gimble in the wabe;
    All mimsy were the borogoves,
    And the mome raths outgrabe.

    Jabberwocky (first verse). Lewis Carroll, 1832-98
    In this example, which could be part of a much larger work discussing a castle, the figure has three images in it.
    The castle has one tower, and a tall wall around it. The castle now has two towers and two walls. The castle lies in ruins, the original tower all that remains in one
piece.
    The castle through the ages: 1423, 1858, and 1999 respectively.
    4.5.12 The figcaption element Categories None. Contexts in which this element may be used: As the first or last child of a figure p158 element. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The figcaption p159 element represents p638 a caption or legend for the rest of the contents of the figcaption p159 element's parent figure p158 element, if any. 4.5.13 The div element Categories Flow content p91 . formatBlock candidate p536 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Flow content p91 . 159 Content attributes: Global attributes p82 DOM interface: interface HTMLDivElement : HTMLElement {}; The div p159 element has no special meaning at all. It represents p638 its children. It can be used with the class p86 , lang p85 , and title p84 attributes to mark up semantics common to a group of consecutive elements. Note: Authors are strongly encouraged to view the div p159 element as an element of last resort, for when no other element is suitable. Use of the div p159 element instead of more appropriate elements leads to poor accessibility for readers and poor maintainability for authors. For example, a blog post would be marked up using article p136 , a chapter using section p133 , a page's navigation aids using nav p134 , and a group of form controls using fieldset p300 . On the other hand, div p159 elements can be useful for stylistic purposes or to wrap multiple paragraphs within a section that are all to be annotated in a similar way. In the following example, we see div p159 elements used as a way to set the language of two paragraphs at once, instead of setting the language on the two paragraph elements separately:

    My use of language and my cats

    My cat's behavior hasn't changed much since her absence, except that she plays her new physique to the neighbors regularly, in an attempt to get pets.

    My other cat, coloured black and white, is a sweetie. He followed us to the pool today, walking down the pavement with us. Yesterday he apparently visited our neighbours. I wonder if he recognises that their flat is a mirror image of ours.

    Hm, I just noticed that in the last paragraph I used British English. But I'm supposed to write in American English. So I shouldn't say "pavement" or "flat" or "colour"...

    I should say "sidewalk" and "apartment" and "color"!

    4.6 Text-level semantics 4.6.1 The a element Categories Flow content p91 . When the element only contains phrasing content p91 : phrasing content p91 . Interactive content p92 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Transparent p93 , but there must be no interactive content p92 descendant. Content attributes: Global attributes p82 href p383 target p384 ping p384 rel p384 media p384 hreflang p384 type p384 160 DOM interface: interface HTMLAnchorElement : HTMLElement { stringifier attribute DOMString href; attribute DOMString target; attribute DOMString ping; attribute readonly attribute attribute attribute attribute DOMString rel; DOMTokenList relList; DOMString media; DOMString hreflang; DOMString type; attribute DOMString text; // URL decomposition IDL attributes attribute DOMString protocol; attribute DOMString host; attribute DOMString hostname; attribute DOMString port; attribute DOMString pathname; attribute DOMString search; attribute DOMString hash; }; If the a p160 element has an href p383 attribute, then it represents p638 a hyperlink p383 (a hypertext anchor). If the a p160 element has no href p383 attribute, then the element represents p638 a placeholder for where a link might otherwise have been placed, if it had been relevant. The target p384 , ping p384 , rel p384 , media p384 , hreflang p384 , and type p384 attributes must be omitted if the href p383 attribute is not present. If a site uses a consistent navigation toolbar on every page, then the link that would normally link to the page itself could be marked up using an a p160 element: Home News Examples Legal The href p383 , target p384 and ping p384 attributes affect what happens when users follow hyperlinks p384 created using the a p160 element. The rel p384 , media p384 , hreflang p384 , and type p384 attributes may be used to indicate to the user the likely nature of the target resource before the user follows the link. The activation behavior p93 of a p160 elements that represent hyperlinks p383 is to run the following steps: 1. If the DOMActivate p31 event in question is not trusted p27 (i.e. a click() p508 method call was the reason for the event being dispatched), and the a p160 element's target p384 attribute is such that applying the rules for choosing a browsing context given a browsing context name p442 , using the value of the target p384 attribute as the browsing context name, would result in there not being a chosen browsing context, then raise an INVALID_ACCESS_ERR p70 exception and abort these steps. 2. If the target of the click p31 event is an img p186 element with an ismap p189 attribute specified, then server-side image map processing must be performed, as follows: 1. If the DOMActivate p31 event was dispatched as the result of a real pointing-device-triggered click p31 event on the img p186 element, then let x be the distance in CSS pixels from the left edge of the image's left border, if it has one, or the left edge of the image otherwise, to the location of the click, and let y be the distance in CSS pixels from the top edge of the image's top border, if it has one, or the top edge of the image otherwise, to the location of the click. Otherwise, let x and y be zero. 161 2. 3. Let the hyperlink suffix be a U+003F QUESTION MARK character, the value of x expressed as a base-ten integer using ASCII digits, a U+002C COMMA character (,), and the value of y expressed as a base-ten integer using ASCII digits. ASCII digits are the characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9). Finally, the user agent must follow the hyperlink p384 defined by the a p160 element. If the steps above defined a hyperlink suffix p162 , then take that into account when following the hyperlink. This box is non-normative. Implementation requirements are given below this box. a . text p162 Same as textContent p31 . The IDL attributes href, ping, target, rel, media, hreflang, and type, must reflect p57 the respective content attributes of the same name. The IDL attribute relList must reflect p57 the rel p384 content attribute. The text IDL attribute, on getting, must return the same value as the textContent p31 IDL attribute on the element, and on setting, must act as if the textContent p31 IDL attribute on the element had been set to the new value. The a p160 element also supports the complement of URL decomposition IDL attributes p53 , protocol, host, port, hostname, pathname, search, and hash. These must follow the rules given for URL decomposition IDL attributes, with the input p54 being the result of resolving p51 the element's href p383 attribute relative to the element, if there is such an attribute and resolving it is successful, or the empty string otherwise; and the common setter action p54 being the same as setting the element's href p383 attribute to the new output value. The a p160 element may be wrapped around entire paragraphs, lists, tables, and so forth, even entire sections, so long as there is no interactive content within (e.g. buttons or other links). This example shows how this can be used to make an entire advertising block into a link: 4.6.2 The em element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The em p162 element represents p638 stress emphasis of its contents. 162 The level of emphasis that a particular piece of content has is given by its number of ancestor em p162 elements. The placement of emphasis changes the meaning of the sentence. The element thus forms an integral part of the content. The precise way in which emphasis is used in this way depends on the language. These examples show how changing the emphasis changes the meaning. First, a general statement of fact, with no emphasis:

    Cats are cute animals.

    By emphasizing the first word, the statement implies that the kind of animal under discussion is in question (maybe someone is asserting that dogs are cute):

    Cats are cute animals.

    Moving the emphasis to the verb, one highlights that the truth of the entire sentence is in question (maybe someone is saying cats are not cute):

    Cats are cute animals.

    By moving it to the adjective, the exact nature of the cats is reasserted (maybe someone suggested cats were mean animals):

    Cats are cute animals.

    Similarly, if someone asserted that cats were vegetables, someone correcting this might emphasize the last word:

    Cats are cute animals.

    By emphasizing the entire sentence, it becomes clear that the speaker is fighting hard to get the point across. This kind of emphasis also typically affects the punctuation, hence the exclamation mark here.

    Cats are cute animals!

    Anger mixed with emphasizing the cuteness could lead to markup such as:

    Cats are cute animals!

    The em p162 element isn't a generic "italics" element. Sometimes, text is intended to stand out from the rest of the paragraph, as if it was in a different mood or voice. For this, the i p174 element is more appropriate. The em p162 element also isn't intended to convey importance; for that purpose, the strong p163 element is more appropriate. 4.6.3 The strong element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The strong p163 element represents p638 strong importance for its contents. The relative level of importance of a piece of content is given by its number of ancestor strong p163 elements; each strong p163 element increases the importance of its contents. Changing the importance of a piece of text with the strong p163 element does not change the meaning of the sentence. Here is an example of a warning notice in a game, with the various parts marked up according to how important they are: 163

    Warning. This dungeon is dangerous. Avoid the ducks. Take any gold you find. Do not take any of the diamonds, they are explosive and will destroy anything within ten meters. You have been warned.

    4.6.4 The small element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The small p164 element represents p638 side comments such as small print. Note: Small print typically features disclaimers, caveats, legal restrictions, or copyrights. Small print is also sometimes used for attribution, or for satisfying licensing requirements. Note: The small p164 element does not "de-emphasize" or lower the importance of text emphasized by the em p162 element or marked as important with the strong p163 element. To mark text as not emphasized or important, simply do not mark it up with the em p162 or strong p163 elements respectively. The small p164 element should not be used for extended spans of text, such as multiple paragraphs, lists, or sections of text. It is only intended for short runs of text. The text of a page listing terms of use, for instance, would not be a suitable candidate for the small p164 element: in such a case, the text is not a side comment, it is the main content of the page. In this example the footer contains contact information and a copyright notice.
    For more details, contact John Smith.

    © copyright 2038 Example Corp.

    In this second example, the small p164 element is used for a side comment in an article.

    Example Corp today announced record profits for the second quarter (Full Disclosure: Foo News is a subsidiary of Example Corp), leading to speculation about a third quarter merger with Demo Group.

    This is distinct from a sidebar, which might be multiple paragraphs long and is removed from the main flow of text. In the following example, we see a sidebar from the same article. This sidebar also has small print, indicating the source of the information in the sidebar. 164 In this last example, the small p164 element is marked as being important small print.

    Continued use of this service will result in a kiss.

    4.6.5 The cite element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The cite p165 element represents p638 the title of a work (e.g. a book, a paper, an essay, a poem, a score, a song, a script, a film, a TV show, a game, a sculpture, a painting, a theatre production, a play, an opera, a musical, an exhibition, a legal case report, etc). This can be a work that is being quoted or referenced in detail (i.e. a citation), or it can just be a work that is mentioned in passing. A person's name is not the title of a work — even if people call that person a piece of work — and the element must therefore not be used to mark up people's names. (In some cases, the b p175 element might be appropriate for names; e.g. in a gossip article where the names of famous people are keywords rendered with a different style to draw attention to them. In other cases, if an element is really needed, the span p180 element can be used.) This next example shows a typical use of the cite p165 element:

    My favorite book is The Reality Dysfunction by Peter F. Hamilton. My favorite comic is Pearls Before Swine by Stephan Pastis. My favorite track is Jive Samba by the Cannonball Adderley Sextet.

    This is correct usage:

    According to the Wikipedia article HTML, as it stood in mid-February 2008, leaving attribute values unquoted is unsafe. This is obviously an over-simplification.

    The following, however, is incorrect usage, as the cite p165 element here is containing far more than the title of the work:

    According to the Wikipedia article on HTML, as it stood in mid-February 2008, leaving attribute values unquoted is unsafe. This is obviously an over-simplification.

    The cite p165 element is obviously a key part of any citation in a bibliography, but it is only used to mark the title:

    Universal Declaration of Human Rights, United Nations, December 1948. Adopted by General Assembly resolution 217 A (III).

    Note: A citation is not a quote (for which the q p166 element is appropriate). This is incorrect usage, because cite p165 is not for quotes:

    This is wrong!, said Ian.

    This is also incorrect usage, because a person is not a work:

    This is still wrong!, said Ian.

    The correct usage does not use a cite p165 element:

    This is correct, said Ian.

    165 As mentioned above, the b p175 element might be relevant for marking names as being keywords in certain kinds of documents:

    And then Ian said this might be right, in a gossip column, maybe!.

    4.6.6 The q element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 cite p166 DOM interface: Uses HTMLQuoteElement p151 . The q p166 element represents p638 some phrasing content p91 quoted from another source. Quotation punctuation (such as quotation marks) that is quoting the contents of the element must not appear immediately before, after, or inside q p166 elements; they will be inserted into the rendering by the user agent. Content inside a q p166 element must be quoted from another source, whose address, if it has one, should be cited in the cite attribute. The source may be fictional, as when quoting characters in a novel or screenplay. If the cite p166 attribute is present, it must be a valid URL p51 . To obtain the corresponding citation link, the value of the attribute must be resolved p51 relative to the element. User agents should allow users to follow such citation links. The q p166 element must not be used in place of quotation marks that do not represent quotes; for example, it is inappropriate to use the q p166 element for marking up sarcastic statements. The use of q p166 elements to mark up quotations is entirely optional; using explicit quotation punctuation without q p166 elements is just as correct. Here is a simple example of the use of the q p166 element:

    The man said Things that are impossible just take longer. I disagreed with him.

    Here is an example with both an explicit citation link in the q p166 element, and an explicit citation outside:

    The W3C page About W3C says the W3C's mission is To lead the World Wide Web to its full potential by developing protocols and guidelines that ensure long-term growth for the Web. I disagree with this mission.

    In the following example, the quotation itself contains a quotation:

    In Example One, he writes The man said Things that are impossible just take longer. I disagreed with him. Well, I disagree even more!

    In the following example, quotation marks are used instead of the q p166 element:

    His best argument was ❝I disagree❞, which I thought was laughable.

    In the following example, there is no quote — the quotation marks are used to name a word. Use of the q p166 element in this case would be inappropriate.

    The word "ineffable" could have been used to describe the disaster resulting from the campaign's mismanagement.

    166 4.6.7 The dfn element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 , but there must be no dfn p167 element descendants. Content attributes: Global attributes p82 Also, the title p167 attribute has special semantics on this element. DOM interface: Uses HTMLElement p81 . The dfn p167 element represents p638 the defining instance of a term. The paragraph p93 , description list group p155 , or section p91 that is the nearest ancestor of the dfn p167 element must also contain the definition(s) for the term p167 given by the dfn p167 element. Defining term: If the dfn p167 element has a title attribute, then the exact value of that attribute is the term being defined. Otherwise, if it contains exactly one element child node and no child text nodes p27 , and that child element is an abbr p167 element with a title p167 attribute, then the exact value of that attribute is the term being defined. Otherwise, it is the exact textContent p31 of the dfn p167 element that gives the term being defined. If the title p167 attribute of the dfn p167 element is present, then it must contain only the term being defined. Note: The title p84 attribute of ancestor elements does not affect dfn p167 elements. An a p160 element that links to a dfn p167 element represents an instance of the term defined by the dfn p167 element. In the following fragment, the term "GDO" is first defined in the first paragraph, then used in the second.

    The GDO is a device that allows off-world teams to open the iris.

    Teal'c activated his GDO and so Hammond ordered the iris to be opened.

    With the addition of an a p160 element, the reference can be made explicit:

    The GDO is a device that allows off-world teams to open the iris.

    Teal'c activated his GDO and so Hammond ordered the iris to be opened.

    4.6.8 The abbr element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 Also, the title p167 attribute has special semantics on this element. DOM interface: Uses HTMLElement p81 . The abbr p167 element represents p638 an abbreviation or acronym, optionally with its expansion. The title attribute may be used to provide an expansion of the abbreviation. The attribute, if specified, must contain an expansion of the abbreviation, and nothing else. 167 The paragraph below contains an abbreviation marked up with the abbr p167 element. This paragraph defines the term p167 "Web Hypertext Application Technology Working Group".

    The WHATWG is a loose unofficial collaboration of Web browser manufacturers and interested parties who wish to develop new technologies designed to allow authors to write and deploy Applications over the World Wide Web.

    An alternative way to write this would be:

    The Web Hypertext Application Technology Working Group (WHATWG) is a loose unofficial collaboration of Web browser manufacturers and interested parties who wish to develop new technologies designed to allow authors to write and deploy Applications over the World Wide Web.

    This paragraph has two abbreviations. Notice how only one is defined; the other, with no expansion associated with it, does not use the abbr p167 element.

    The WHATWG started working on HTML5 in 2004.

    This paragraph links an abbreviation to its definition.

    The WHATWG community does not have much representation from Asia.

    This paragraph marks up an abbreviation without giving an expansion, possibly as a hook to apply styles for abbreviations (e.g. smallcaps).

    Philip` and Dashiva both denied that they were going to get the issue counts from past revisions of the specification to backfill the WHATWG issue graph.

    If an abbreviation is pluralized, the expansion's grammatical number (plural vs singular) must match the grammatical number of the contents of the element. Here the plural is outside the element, so the expansion is in the singular:

    Two WGs worked on this specification: the WHATWG and the HTMLWG.

    Here the plural is inside the element, so the expansion is in the plural:

    Two WGs worked on this specification: the WHATWG and the HTMLWG.

    Abbreviations do not have to be marked up using this element. It is expected to be useful in the following cases: • Abbreviations for which the author wants to give expansions, where using the abbr p167 element with a title p84 attribute is an alternative to including the expansion inline (e.g. in parentheses). • Abbreviations that are likely to be unfamiliar to the document's readers, for which authors are encouraged to either mark up the abbreviation using a abbr p167 element with a title p84 attribute or include the expansion inline in the text the first time the abbreviation is used. • Abbreviations whose presence needs to be semantically annotated, e.g. so that they can be identified from a style sheet and given specific styles, for which the abbr p167 element can be used without a title p84 attribute. Providing an expansion in a title p84 attribute once will not necessarily cause other abbr p167 elements in the same document with the same contents but without a title p84 attribute to behave as if they had the same expansion. Every abbr p167 element is independent. 4.6.9 The time element 168 Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 , but there must be no time p168 element descendants. Content attributes: Global attributes p82 datetime p169 pubdate p169 DOM interface: interface HTMLTimeElement : HTMLElement { attribute DOMString dateTime; attribute boolean pubDate; readonly attribute Date valueAsDate; }; The time p168 element represents p638 either a time on a 24 hour clock, or a precise date in the proleptic Gregorian calendar, optionally with a time and a time-zone offset. [GREGORIAN] p701 This element is intended as a way to encode modern dates and times in a machine-readable way so that, for example, user agents can offer to add birthday reminders or scheduled events to the user's calendar. The time p168 element is not intended for encoding times for which a precise date or time cannot be established. For example, it would be inappropriate for encoding times like "one millisecond after the big bang", "the early part of the Jurassic period", or "a winter around 250 BCE". For dates before the introduction of the Gregorian calendar, authors are encouraged to not use the time p168 element, or else to be very careful about converting dates and times from the period to the Gregorian calendar. This is complicated by the manner in which the Gregorian calendar was phased in, which occurred at different times in different countries, ranging from partway through the 16th century all the way to early in the 20th. The pubdate attribute is a boolean attribute p34 . If specified, it indicates that the date and time given by the element is the publication date and time of the nearest ancestor article p136 element, or, if the element has no ancestor article p136 element, of the document as a whole. If the element has a pubdate p169 attribute specified, then the element needs a date. For each article p136 element, there must no more than one time p168 element with a pubdate p169 attribute whose nearest ancestor is that article p136 element. Furthermore, for each Document p31 , there must be no more than one time p168 element with a pubdate p169 attribute that does not have an ancestor article p136 element. The datetime attribute, if present, gives the date or time being specified. Otherwise, the date or time is given by the element's contents. If the element needs a date p169 , and the datetime p169 attribute is present, then the attribute's value must be a valid date string with optional time p46 . If the element needs a date p169 , but the datetime p169 attribute is not present, then the element's textContent p31 must be a valid date string in content with optional time p46 . If the element does not need a date, and the datetime p169 attribute is present, then the attribute's value must be a valid date or time string p46 . If the element does not need a date, but the datetime p169 attribute is not present, then the element's textContent p31 must be a valid date or time string in content p46 . The date, if any, must be expressed using the Gregorian calendar. If the datetime p169 attribute is present, the user agent should convey the attribute's value to the user when rendering the element. The time p168 element can be used to encode dates, for example in Microformats. The following shows a hypothetical way of encoding an event using a variant on hCalendar that uses the time p168 element: 169
    http://www.web2con.com/ Web 2.0 Conference: , at the Argent Hotel, San Francisco, CA
    (The end date is encoded as one day after the last date of the event because in the iCalendar format, end dates are exclusive, not inclusive.) The time p168 element is not necessary for encoding dates or times. In the following snippet, the time is encoded using time p168 , so that it can be restyled (e.g. using XBL2) to match local conventions, while the year is not marked up at all, since marking it up would not be particularly useful.

    I usually have a snack at .

    I've liked model trains since at least 1983.

    Using a styling technology that supports restyling times, the first paragraph from the above snippet could be rendered as follows: I usually have a snack at 4pm. Or it could be rendered as follows: I usually have a snack at 16h00. The dateTime IDL attribute must reflect p57 the datetime p169 content attribute. The pubDate IDL attribute must reflect p57 the pubdate p169 content attribute. User agents, to obtain the date, time, and time-zone offset represented by a time p168 element, must follow these steps: 1. If the datetime p169 attribute is present, then use the rules to parse a date or time string p47 with the flag in attribute from the value of that attribute, and let the result be result. 2. Otherwise, use the rules to parse a date or time string p47 with the flag in content from the element's textContent p31 , and let the result be result. 3. If result is empty (because the parsing failed), then the date p170 is unknown, the time p170 is unknown, and the time-zone offset p170 is unknown. 4. Otherwise: if result contains a date, then that is the date p170 ; if result contains a time, then that is the time p170 ; and if result contains a time-zone offset, then the time-zone offset is the element's time-zone offset p170 . (A time-zone offset can only be present if both a date and a time are also present.) This box is non-normative. Implementation requirements are given below this box. time . valueAsDate p170 Returns a Date object representing the specified date and time. The valueAsDate IDL attribute must return either null or a new Date object initialised to the relevant value as defined by the following list: If the date p170 is known but the time p170 is not The time corresponding to midnight UTC (i.e. the first second) of the given date p170 . If the time p170 is known but the date p170 is not The time corresponding to the given time p170 of 1970-01-01, with the time zone UTC. If both the date p170 and the time p170 are known The time corresponding to the date p170 and time p170 , with the given time-zone offset p170 . If neither the date p170 nor the time p170 are known The null value. When a Date object is to be returned, a new one must be constructed. In the following snippet:

    Our first date was .

    170 ...the time p168 element's valueAsDate p170 attribute would have the value 1,158,969,600,000ms. In the following snippet:

    Many people get up at .

    ...the time p168 element's valueAsDate p170 attribute would have the value 28,800,000ms. In this example, an article's publication date is marked up using time p168 :

    Small tasks

    Published .

    I put a bike bell on his bike.

    Here is another way that could be marked up:

    Small tasks

    Published .

    I put a bike bell on his bike.

    Here is the same thing but with the time included. Because the element is empty, it will be replaced in the rendering with a more readable version of the date and time given.

    Small tasks

    Published .

    I put a bike bell on his bike.

    4.6.10 The code element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The code p171 element represents p638 a fragment of computer code. This could be an XML element name, a filename, a computer program, or any other string that a computer would recognize. Although there is no formal way to indicate the language of computer code being marked up, authors who wish to mark code p171 elements with the language used, e.g. so that syntax highlighting scripts can use the right rules, may do so by adding a class prefixed with "language-" to the element. The following example shows how the element can be used in a paragraph to mark up element names and computer code, including punctuation.

    The code element represents a fragment of computer code.

    When you call the activate() method on the robotSnowman object, the eyes glow.

    The example the start of a keyword, which (full stop) to below uses the begin keyword to indicate statement block. It is paired with an end is followed by the . punctuation character indicate the end of the program.

    171 The following example shows how a block of code could be marked up using the pre p150 and code p171 elements.
    var i: Integer;
    begin
    i := 1;
    end.
    A class is used in that example to indicate the language used. Note: See the pre p150 element for more details. 4.6.11 The var element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The var p172 element represents p638 a variable. This could be an actual variable in a mathematical expression or programming context, or it could just be a term used as a placeholder in prose. In the paragraph below, the letter "n" is being used as a variable in prose:

    If there are n pipes leading to the ice cream factory then I expect at least n flavors of ice cream to be available for purchase!

    For mathematics, in particular for anything beyond the simplest of expressions, MathML is more appropriate. However, the var p172 element can still be used to refer to specific variables that are then mentioned in MathML expressions. In this example, an equation is shown, with a legend that references the variables in the equation. The expression itself is marked up with MathML, but the variables are mentioned in the figure's legend using var p172 .
    a = b2 + c2
    Using Pythagoras' theorem to solve for the hypotenuse a of a triangle with sides b and c
    4.6.12 The samp element Categories Flow content p91 . Phrasing content p91 . 172 Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The samp p172 element represents p638 (sample) output from a program or computing system. Note: See the pre p150 and kbd p173 elements for more details. This example shows the samp p172 element being used inline:

    The computer said Too much cheese in tray two but I didn't know what that meant.

    This second example shows a block of sample output. Nested samp p172 and kbd p173 elements allow for the styling of specific elements of the sample output using a style sheet.
    jdoe@mowmow:~$ ssh demo.example.com
    Last login: Tue Apr 12 09:10:17 2005 from mowmow.example.com on pts/1
    Linux demo 2.6.10-grsec+gg3+e+fhs6b+nfs+gr0501+++p3+c4a+gr2b-reslog-v6.189 #1 SMP Tue
    Feb 1 11:22:36 PST 2005 i686 unknown
    jdoe@demo:~$ _
    4.6.13 The kbd element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The kbd p173 element represents p638 user input (typically keyboard input, although it may also be used to represent other input, such as voice commands). When the kbd p173 element is nested inside a samp p172 element, it represents the input as it was echoed by the system. When the kbd p173 element contains a samp p172 element, it represents input based on system output, for example invoking a menu item. When the kbd p173 element is nested inside another kbd p173 element, it represents an actual key or other single unit of input as appropriate for the input mechanism. Here the kbd p173 element is used to indicate keys to press:

    To make George eat an apple, press Shift+F3

    In this second example, the user is told to pick a particular menu item. The outer kbd p173 element marks up a block of input, with the inner kbd p173 elements representing each individual step of the input, and the samp p172 elements inside them indicating that the steps are input based on something being displayed by the system, in this case menu labels: 173

    To make George eat an apple, select File|Eat Apple...

    Such precision isn't necessary; the following is equally fine:

    To make George eat an apple, select File | Eat Apple...

    4.6.14 The sub and sup elements Categories Flow content p91 . Phrasing content p91 . Contexts in which these elements may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: Use HTMLElement p81 . The sup p174 element represents p638 a superscript and the sub p174 element represents p638 a subscript. These elements must be used only to mark up typographical conventions with specific meanings, not for typographical presentation for presentation's sake. For example, it would be inappropriate for the sub p174 and sup p174 elements to be used in the name of the LaTeX document preparation system. In general, authors should use these elements only if the absence of those elements would change the meaning of the content. In certain languages, superscripts are part of the typographical conventions for some abbreviations.

    The most beautiful women are Mlle Gwendoline and Mme Denise.

    The sub p174 element can be used inside a var p172 element, for variables that have subscripts. Here, the sub p174 element is used to represents the subscript that identifies the variable in a family of variables:

    The coordinate of the ith point is (xi, yi). For example, the 10th point has coordinate (x10, y10).

    Mathematical expressions often use subscripts and superscripts. Authors are encouraged to use MathML for marking up mathematics, but authors may opt to use sub p174 and sup p174 if detailed mathematical markup is not desired. [MATHML] p702 E=mc2 f(x, n) = log4xn 4.6.15 The i element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 174 DOM interface: Uses HTMLElement p81 . The i p174 element represents p638 a span of text in an alternate voice or mood, or otherwise offset from the normal prose, such as a taxonomic designation, a technical term, an idiomatic phrase from another language, a thought, a ship name, or some other prose whose typical typographic presentation is italicized. Terms in languages different from the main text should be annotated with lang p85 attributes (or, in XML, lang attributes in the XML namespace p85 ). The examples below show uses of the i p174 element:

    The Felis silvestris catus is cute.

    The term prose content is defined above.

    There is a certain je ne sais quoi in the air.

    In the following example, a dream sequence is marked up using i p174 elements.

    Raymond tried to sleep.

    The ship sailed away on Thursday, he dreamt. The ship had many people aboard, including a beautiful princess called Carey. He watched her, day-in, day-out, hoping she would notice him, but she never did.

    Finally one night he picked up the courage to speak with her—

    Raymond woke with a start as the fire alarm rang out.

    Authors are encouraged to use the class p86 attribute on the i p174 element to identify why the element is being used, so that if the style of a particular use (e.g. dream sequences as opposed to taxonomic terms) is to be changed at a later date, the author doesn't have to go through the entire document (or series of related documents) annotating each use. Similarly, authors are encouraged to consider whether other elements might be more applicable than the i p174 element, for instance the em p162 element for marking up stress emphasis, or the dfn p167 element to mark up the defining instance of a term. Note: Style sheets can be used to format i p174 elements, just like any other element can be restyled. Thus, it is not the case that content in i p174 elements will necessarily be italicized. 4.6.16 The b element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The b p175 element represents p638 a span of text to be stylistically offset from the normal prose without conveying any extra importance, such as key words in a document abstract, product names in a review, or other spans of text whose typical typographic presentation is boldened. The following example shows a use of the b p175 element to highlight key words without marking them up as important:

    The frobonitor and barbinator components are fried.

    In the following example, objects in a text adventure are highlighted as being special by use of the b p175 element.

    You enter a small room. Your sword glows brighter. A rat scurries past the corner wall.

    175 Another case where the b p175 element is appropriate is in marking up the lede (or lead) sentence or paragraph. The following example shows how a BBC article about kittens adopting a rabbit as their own could be marked up:

    Kittens 'adopted' by pet rabbit

    Six abandoned kittens have found an unexpected new mother figure — a pet rabbit.

    Veterinary nurse Melanie Humble took the three-week-old kittens to her Aberdeen home.

    [...] As with the i p174 element, authors are encouraged to use the class p86 attribute on the b p175 element to identify why the element is being used, so that if the style of a particular use is to be changed at a later date, the author doesn't have to go through annotating each use. The b p175 element should be used as a last resort when no other element is more appropriate. In particular, headings should use the h1 p139 to h6 p139 elements, stress emphasis should use the em p162 element, importance should be denoted with the strong p163 element, and text marked or highlighted should use the mark p176 element. The following would be incorrect usage:

    WARNING! Do not frob the barbinator!

    In the previous example, the correct element to use would have been strong p163 , not b p175 . Note: Style sheets can be used to format b p175 elements, just like any other element can be restyled. Thus, it is not the case that content in b p175 elements will necessarily be boldened. 4.6.17 The mark element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The mark p176 element represents p638 a run of text in one document marked or highlighted for reference purposes, due to its relevance in another context. When used in a quotation or other block of text referred to from the prose, it indicates a highlight that was not originally present but which has been added to bring the reader's attention to a part of the text that might not have been considered important by the original author when the block was originally written, but which is now under previously unexpected scrutiny. When used in the main prose of a document, it indicates a part of the document that has been highlighted due to its likely relevance to the user's current activity. This example shows how the mark p176 element can be used to bring attention to a particular part of a quotation:

    Consider the following quote:

    Look around and you will find, no-one's really colour blind.

    As we can tell from the spelling of the word, the person writing this quote is clearly not American.

    Another example of the mark p176 element is highlighting parts of a document that are matching some search string. If someone looked at a document, and the server knew that the user was searching for the word "kitten", then the server might return the document with one paragraph modified as follows: 176

    I also have some kittens who are visiting me these days. They're really cute. I think they like my garden! Maybe I should adopt a kitten.

    In the following snippet, a paragraph of text refers to a specific part of a code fragment.

    The highlighted part below is where the error lies:

    var i: Integer;
    begin
    i := 1.1;
    end.
    This is another example showing the use of mark p176 to highlight a part of quoted text that was originally not emphasized. In this example, common typographic conventions have led the author to explicitly style mark p176 elements in quotes to render in italics.

    She knew

    Did you notice the subtle joke in the joke on panel 4?

    I didn't want to believe. Of course on some level I realized it was a known-plaintext attack. But I couldn't admit it until I saw for myself.

    (Emphasis mine.) I thought that was great. It's so pedantic, yet it explains everything neatly.

    Note, incidentally, the distinction between the em p162 element in this example, which is part of the original text being quoted, and the mark p176 element, which is highlighting a part for comment. The following example shows the difference between denoting the importance of a span of text (strong p163 ) as opposed to denoting the relevance of a span of text (mark p176 ). It is an extract from a textbook, where the extract has had the parts relevant to the exam highlighted. The safety warnings, important though they may be, are apparently not relevant to the exam.

    Wormhole Physics Introduction

    A wormhole in normal conditions can be held open for a maximum of just under 39 minutes. Conditions that can increase the time include a powerful energy source coupled to one or both of the gates connecting the wormhole, and a large gravity well (such as a black hole).

    Momentum is preserved across the wormhole. Electromagnetic radiation can travel in both directions through a wormhole, but matter cannot.

    When a wormhole is created, a vortex normally forms. Warning: The vortex caused by the wormhole opening will annihilate anything in its path. Vortexes can be avoided when using sufficiently advanced dialing technology.

    An obstruction in a gate will prevent it from accepting a wormhole connection.

    4.6.18 The ruby element 177 Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: One or more groups of: phrasing content p91 followed either by a single rt p179 element, or an rp p179 element, an rt p179 element, and another rp p179 element. Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The ruby p177 element allows one or more spans of phrasing content to be marked with ruby annotations. Ruby annotations are short runs of text presented alongside base text, primarily used in East Asian typography as a guide for pronunciation or to include other annotations. In Japanese, this form of typography is also known as furigana. A ruby p177 element represents p638 the spans of phrasing content it contains, ignoring all the child rt p179 and rp p179 elements and their descendants. Those spans of phrasing content have associated annotations created using the rt p179 element. In this example, each ideograph in the Japanese text 漢字 is annotated with its reading in hiragana. ... かん ... This might be rendered as: In this example, each ideograph in the traditional Chinese text 漢字 is annotated with its bopomofo reading. ㄏㄢˋ ㄗˋ This might be rendered as: In this example, each ideograph in the simplified Chinese text 汉字 is annotated with its pinyin reading. ... hàn 178 ... This might be rendered as: 4.6.19 The rt element Categories None. Contexts in which this element may be used: As a child of a ruby p177 element. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The rt p179 element marks the ruby text component of a ruby annotation. An rt p179 element that is a child of a ruby p177 element represents p638 an annotation (given by its children) for the zero or more nodes of phrasing content that immediately precedes it in the ruby p177 element, ignoring rp p179 elements. An rt p179 element that is not a child of a ruby p177 element represents the same thing as its children. 4.6.20 The rp element Categories None. Contexts in which this element may be used: As a child of a ruby p177 element, either immediately before or immediately after an rt p179 element. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The rp p179 element can be used to provide parentheses around a ruby text component of a ruby annotation, to be shown by user agents that don't support ruby annotations. An rp p179 element that is a child of a ruby p177 element represents p638 nothing and its contents must be ignored. An rp p179 element whose parent element is not a ruby p177 element represents p638 its children. The example above, in which each ideograph in the text 漢字 is annotated with its kanji reading, could be expanded to use rp p179 so that in legacy user agents the readings are in parentheses: ... (かん)() ... 179 In conforming user agents the rendering would be as above, but in user agents that do not support ruby, the rendering would be: ... 漢 (かん) 字 (じ) ... 4.6.21 The bdo element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 Also, the dir p86 global attribute has special semantics on this element. DOM interface: Uses HTMLElement p81 . The bdo p180 element represents p638 explicit text directionality formatting control for its children. It allows authors to override the Unicode bidirectional algorithm by explicitly specifying a direction override. [BIDI] p700 Authors must specify the dir p86 attribute on this element, with the value ltr to specify a left-to-right override and with the value rtl to specify a right-to-left override. If the element has the dir p86 attribute set to the exact value ltr, then for the purposes of the bidi algorithm, the user agent must act as if there was a U+202D LEFT-TO-RIGHT OVERRIDE character at the start of the element, and a U+202C POP DIRECTIONAL FORMATTING at the end of the element. If the element has the dir p86 attribute set to the exact value rtl, then for the purposes of the bidi algorithm, the user agent must act as if there was a U+202E RIGHT-TO-LEFT OVERRIDE character at the start of the element, and a U+202C POP DIRECTIONAL FORMATTING at the end of the element. The requirements on handling the bdo p180 element for the bidi algorithm may be implemented indirectly through the style layer. For example, an HTML+CSS user agent should implement these requirements by implementing the CSS 'unicode-bidi' property. [CSS] p700 4.6.22 The span element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: interface HTMLSpanElement : HTMLElement {}; The span p180 element doesn't mean anything on its own, but can be useful when used together with other attributes, e.g. class p86 , lang p85 , or dir p86 . It represents p638 its children. In this example, a code fragment is marked up using span p180 elements and class p86 attributes so that its keywords and identifiers can be color-coded from CSS:
    for (j = 0; j < 256; j++) {
    i_t3 = (i_t3 & 0x1ffff) |
    (j << 17);
    
    180
    
    i_t6 = (((((((i_t3 >> 3) ^
    i_t3) >> 1) ^ i_t3) >> 8) ^
    i_t3) >> 5) & 0xff;
    if (i_t6 == i_t1)
    break;
    }
    4.6.23 The br element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Empty. Content attributes: Global attributes p82 DOM interface: interface HTMLBRElement : HTMLElement {}; The br p181 element represents p638 a line break. br p181 elements must be used only for line breaks that are actually part of the content, as in poems or addresses. The following example is correct usage of the br p181 element:

    P. Sherman
    42 Wallaby Way
    Sydney

    br p181 elements must not be used for separating thematic groups in a paragraph. The following examples are non-conforming, as they abuse the br p181 element:

    34 comments.
    Add a comment.


    Here are alternatives to the above, which are correct:

    34 comments.

    Add a comment.

    If a paragraph p93 consists of nothing but a single br p181 element, it represents a placeholder blank line (e.g. as in a template). Such blank lines must not be used for presentation purposes. Any content inside br p181 elements must not be considered part of the surrounding text. A br p181 element does not separate paragraphs for the purposes of the Unicode bidirectional algorithm. [BIDI] p700 4.6.24 The wbr element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Empty. 181 Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The wbr p181 element represents p638 a line break opportunity. In the following example, someone is quoted as saying something which, for effect, is written as one long word. However, to ensure that the text can be wrapped in a readable fashion, the individual words in the quote are separated using a wbr p181 element.

    So then he pointed at the tiger and screamed "thereisnowayyouareevergoingtocatchme"!

    Any content inside wbr p181 elements must not be considered part of the surrounding text. 4.6.25 Usage summary This section is non-normative. Element p160 Purpose Example Hyperlinks Visit my drinks page. em p162 Stress emphasis I must say I adore lemonade. strong p163 Importance This tea is very hot. small p164 Side comments These grapes are made into wine. Alcohol is addictive. cite p165 Titles of works The case Hugo v. Danielle is relevant here. q p166 Quotations The judge said You can drink water from the fish tank but advised against it. dfn p167 Defining instance The term organic food refers to food produced without synthetic chemicals. abbr p167 Abbreviations Organic food in Ireland is certified by the IOFGA. time p168 Date and/or time Published . code p171 Computer code The fruitdb program can be used for tracking fruit production. a p172 Variables If there are n fruit in the bowl, at least n÷2 will be ripe. samp p172 Computer output The computer said Unknown error -3. kbd p173 User input Hit F1 to continue. sub p174 Subscripts Water is H2O. sup p174 Superscripts The Hydrogen in heavy water is usually 2H. i p174 Alternative voice Lemonade consists primarily of Citrus limon. Keywords Take a lemon and squeeze it with a juicer. Highlight Elderflower cordial, with one part cordial to ten parts water, stands apart from the rest. ruby p177 , rt p179 , rp p179 Ruby annotations OJ (Orange Juice) bdo p180 Text directionality formatting The proposal is to write English, but in reverse order. "Juice" would become "Juice" span p180 Other In French we call it sirop de sureau. br p181 Line break Simply Orange Juice Company
    Apopka, FL 32703
    U.S.A. wbr p181 Line breaking opportunity www.simplyorangejuice.com var b p175 mark p176 4.7 Edits The ins p182 and del p183 elements represent edits to the document. 4.7.1 The ins element Categories Flow content p91 . When the element only contains phrasing content p91 : phrasing content p91 . 182 Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Transparent p93 . Content attributes: Global attributes p82 cite p184 datetime p184 DOM interface: Uses the HTMLModElement p184 interface. The ins p182 element represents p638 an addition to the document. The following represents the addition of a single paragraph: As does this, because everything in the aside p137 element here counts as phrasing content p91 and therefore there is just one paragraph p93 : ins p182 elements should not cross implied paragraph p93 boundaries. The following example represents the addition of two paragraphs, the second of which was inserted in two parts. The first ins p182 element in this example thus crosses a paragraph boundary, which is considered poor form. Here is a better way of marking this up. It uses more elements, but none of the elements cross implied paragraph boundaries. 4.7.2 The del element 183 Categories Flow content p91 . When the element only contains phrasing content p91 : phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Transparent p93 . Content attributes: Global attributes p82 cite p184 datetime p184 DOM interface: Uses the HTMLModElement p184 interface. The del p183 element represents p638 a removal from the document. del p183 elements should not cross implied paragraph p93 boundaries. The following shows a "to do" list where items that have been done are crossed-off with the date and time of their completion.

    To Do

    • Empty the dishwasher
    • Watch Walter Lewin's lectures
    • Download more tracks
    • Buy a printer
    4.7.3 Attributes common to ins p182 and del p183 elements The cite attribute may be used to specify the address of a document that explains the change. When that document is long, for instance the minutes of a meeting, authors are encouraged to include a fragment identifier pointing to the specific part of that document that discusses the change. If the cite p184 attribute is present, it must be a valid URL p51 that explains the change. To obtain the corresponding citation link, the value of the attribute must be resolved p51 relative to the element. User agents should allow users to follow such citation links. The datetime attribute may be used to specify the time and date of the change. If present, the datetime p184 attribute must be a valid global date and time string p44 value. User agents must parse the datetime p184 attribute according to the parse a global date and time string p44 algorithm. If that doesn't return a time, then the modification has no associated timestamp (the value is nonconforming; it is not a valid global date and time string p44 ). Otherwise, the modification is marked as having been made at the given datetime. User agents should use the associated time-zone offset information to determine which time zone to present the given datetime in. The ins p182 and del p183 elements must implement the HTMLModElement p184 interface: interface HTMLModElement : HTMLElement { attribute DOMString cite; attribute DOMString dateTime; }; The cite IDL attribute must reflect p57 the element's cite p184 content attribute. The dateTime IDL attribute must reflect p57 the element's datetime p184 content attribute. 4.7.4 Edits and paragraphs This section is non-normative. 184 Since the ins p182 and del p183 elements do not affect paragraphing p93 , it is possible, in some cases where paragraphs are implied p93 (without explicit p p148 elements), for an ins p182 or del p183 element to span both an entire paragraph or other non-phrasing content p91 elements and part of another paragraph. For example:

    This is a paragraph that was inserted.

    This is another paragraph whose first sentence was inserted at the same time as the paragraph above.
    This is a second sentence, which was there all along.
    By only wrapping some paragraphs in p p148 elements, one can even get the end of one paragraph, a whole second paragraph, and the start of a third paragraph to be covered by the same ins p182 or del p183 element (though this is very confusing, and not considered good practice):
    This is the first paragraph. This sentence was inserted.

    This second paragraph was inserted.

    This sentence was inserted too.
    This is the third paragraph in this example.
    However, due to the way implied paragraphs p93 are defined, it is not possible to mark up the end of one paragraph and the start of the very next one using the same ins p182 or del p183 element. You instead have to use one (or two) p p148 element(s) and two ins p182 or del p183 elements, as for example:

    This is the first paragraph. This sentence was deleted.

    This sentence was deleted too. That sentence needed a separate <del> element.

    Partly because of the confusion described above, authors are strongly encouraged to always mark up all paragraphs with the p p148 element, instead of having ins p182 or del p183 elements that cross implied paragraphs p93 boundaries. 4.7.5 Edits and lists This section is non-normative. The content models of the ol p152 and ul p153 elements do not allow ins p182 and del p183 elements as children. Lists always represent all their items, including items that would otherwise have been marked as deleted. To indicate that an item is inserted or deleted, an ins p182 or del p183 element can be wrapped around the contents of the li p154 element. To indicate that an item has been replaced by another, a single li p154 element can have one or more del p183 elements followed by one or more ins p182 elements. In the following example, a list that started empty had items added and removed from it over time. The bits in the example that have been emphasized show the parts that are the "current" state of the list. The list item numbers don't take into account the edits, though.

    Stop-ship bugs

    1. Bug 225: Rain detector doesn't work in snow
    2. Bug 228: Water buffer overflows in April
    3. Bug 230: Water heater doesn't use renewable fuels
    4. Bug 232: Carbon dioxide emissions detected after startup
    In the following example, a list that started with just fruit was replaced by a list with just colors. 185

    List of fruitscolors

    • LimeGreen
    • Apple
    • Orange
    • Pear
    • Teal
    • LemonYellow
    • Olive
    • Purple
    4.8 Embedded content 4.8.1 The img element Categories Flow content p91 . Phrasing content p91 . Embedded content p92 . If the element has a usemap p268 attribute: Interactive content p92 . Contexts in which this element may be used: Where embedded content p92 is expected. Content model: Empty. Content attributes: Global attributes p82 alt p186 src p186 usemap p268 ismap p189 width p271 height p271 DOM interface: [NamedConstructor=Image(), NamedConstructor=Image(in unsigned long width), NamedConstructor=Image(in unsigned long width, in unsigned long height)] interface HTMLImageElement : HTMLElement { attribute DOMString alt; attribute DOMString src; attribute DOMString useMap; attribute boolean isMap; attribute unsigned long width; attribute unsigned long height; readonly attribute unsigned long naturalWidth; readonly attribute unsigned long naturalHeight; readonly attribute boolean complete; }; An img p186 element represents an image. The image given by the src attribute is the embedded content, and the value of the alt attribute is the img p186 element's fallback content p92 . The src p186 attribute must be present, and must contain a valid non-empty URL p51 referencing a non-interactive, optionally animated, image resource that is neither paged nor scripted. Note: Images can thus be static bitmaps (e.g. PNGs, GIFs, JPEGs), single-page vector documents (single-page PDFs, XML files with an SVG root element), animated bitmaps (APNGs, animated GIFs), animated vector graphics (XML files with an SVG root element that use declarative SMIL animation), and so forth. However, this also precludes SVG files with script, multipage PDF files, interactive MNG files, HTML documents, plain text documents, and so forth. 186 The requirements on the alt p186 attribute's value are described in the next section p191 . The img p186 must not be used as a layout tool. In particular, img p186 elements should not be used to display transparent images, as they rarely convey meaning and rarely add anything useful to the document. Unless the user agent cannot support images, or its support for images has been disabled, or the user agent only fetches elements on demand, then, when an img p186 is created with a src p186 attribute, and whenever the src p186 attribute is set subsequently, the user agent must run the following steps: 1. If the element's src p186 attribute's value is the empty string, then queue a task p490 to fire a simple event p496 named error at the img p186 element, and abort these steps. 2. Otherwise, resolve p51 the value of that attribute, relative to the element, and if that is successful must then fetch p55 that resource. Fetching the image must delay the load event p619 of the element's document until the task p489 that is queued p490 by the networking task source p491 once the resource has been fetched p55 (defined below p187 ) has been run. ⚠Warning! This, unfortunately, can be used to perform a rudimentary port scan of the user's local network (especially in conjunction with scripting, though scripting isn't actually necessary to carry out such an attack). User agents may implement cross-origin p449 access control policies that mitigate this attack. If the image is in a supported image type and its dimensions are known, then the image is said to be available (this affects exactly what the element represents, as defined below). This can be true even before the image is completely downloaded, if the user agent supports incremental rendering of images; in such cases, each task p489 that is queued p490 by the networking task source p491 while the image is being fetched p55 must update the presentation of the image appropriately. It can also stop being true, e.g. if the user agent finds, after obtaining the image's dimensions, that the image data is actually fatally corrupted. If the image was not fetched (e.g. because the UA's image support is disabled, or because the src p186 attribute's value is the empty string, or if the conditions in the previous paragraph are not met, then the image is not available p187 . Whether the image is fetched successfully or not (e.g. whether the response code was a 2xx code or equivalent p56 ) must be ignored when determining the image's type and whether it is a valid image. Note: This allows servers to return images with error responses, and have them displayed. The user agents should apply the image sniffing rules p57 to determine the type of the image, with the image's associated Content-Type headers p57 giving the official type. If these rules are not applied, then the type of the image must be the type given by the image's associated Content-Type headers p57 . User agents must not support non-image resources with the img p186 element (e.g. XML files whose root element is an HTML element). User agents must not run executable code (e.g. scripts) embedded in the image resource. User agents must only display the first page of a multipage resource (e.g. a PDF file). User agents must not allow the resource to act in an interactive fashion, but should honor any animation in the resource. This specification does not specify which image types are to be supported. The task p489 that is queued p490 by the networking task source p491 once the resource has been fetched p55 , must act as appropriate given the following alternatives: p187 ↪ If the download was successful and the image is available Queue a task p490 to fire a simple event p496 named load at the img p186 element (this happens after complete p189 starts returning true). ↪ Otherwise (the fetching process failed without a response from the remote server, or completed but the image is not a supported image) Queue a task p490 to fire a simple event p496 named error on the img p186 element. The task source p490 for these tasks p489 is the DOM manipulation task source p491 . What an img p186 element represents depends on the src p186 attribute and the alt p186 attribute. p186 attribute is set and the alt p186 attribute is set to the empty string ↪ If the src The image is either decorative or supplemental to the rest of the content, redundant with some other information in the document. 187 If the image is available p187 and the user agent is configured to display that image, then the element represents p638 the image specified by the src p186 attribute. Otherwise, the element represents p638 nothing, and may be omitted completely from the rendering. User agents may provide the user with a notification that an image is present but has been omitted from the rendering. p186 attribute is set and the alt p186 attribute is set to a value that isn't empty ↪ If the src The image is a key part of the content; the alt p186 attribute gives a textual equivalent or replacement for the image. If the image is available p187 and the user agent is configured to display that image, then the element represents p638 the image specified by the src p186 attribute. Otherwise, the element represents p638 the text given by the alt p186 attribute. User agents may provide the user with a notification that an image is present but has been omitted from the rendering. p186 attribute is set and the alt p186 attribute is not ↪ If the src The image might be a key part of the content, and there is no textual equivalent of the image available. Note: In a conforming document, the absence of the alt p186 attribute indicates that the image is a key part of the content but that a textual replacement for the image was not available when the image was generated. If the image is available p187 , the element represents p638 the image specified by the src p186 attribute. If the image is not available p187 or if the user agent is not configured to display the image, then the user agent should display some sort of indicator that there is an image that is not being rendered, and may, if requested by the user, or if so configured, or when required to provide contextual information in response to navigation, provide caption information for the image, derived as follows: 1. If the image has a title p84 attribute whose value is not the empty string, then the value of that attribute is the caption information; abort these steps. 2. If the image is the child of a figure p158 element that has a child figcaption p159 element, then the contents of the first such figcaption p159 element are the caption information; abort these steps. 3. Run the algorithm to create the outline p145 for the document. 4. If the img p186 element did not end up associated with a heading in the outline, or if there are any other images that are lacking an alt p186 attribute and that are associated with the same heading in the outline as the img p186 element in question, then there is no caption information; abort these steps. 5. The caption information is the heading with which the image is associated according to the outline. p186 attribute is not set and either the alt p186 attribute is set to the empty string or the ↪ If the src alt p186 attribute is not set at all The element represents p638 nothing. ↪ Otherwise The element represents p638 the text given by the alt p186 attribute. The alt p186 attribute does not represent advisory information. User agents must not present the contents of the alt p186 attribute in the same way as content of the title p84 attribute. User agents may always provide the user with the option to display any image, or to prevent any image from being displayed. User agents may also apply heuristics to help the user make use of the image when the user is unable to see it, e.g. due to a visual disability or because they are using a text terminal with no graphics capabilities. Such heuristics could include, for instance, optical character recognition (OCR) of text found within the image. ⚠Warning! While user agents are encouraged to repair cases of missing alt p186 attributes, authors must not rely on such behavior. Requirements for providing text to act as an alternative for images p191 are described in detail below. The contents of img p186 elements, if any, are ignored for the purposes of rendering. The usemap p268 attribute, if present, can indicate that the image has an associated image map p268 . 188 The ismap attribute, when used on an element that is a descendant of an a p160 element with an href p383 attribute, indicates by its presence that the element provides access to a server-side image map. This affects how events are handled on the corresponding a p160 element. The ismap p189 attribute is a boolean attribute p34 . The attribute must not be specified on an element that does not have an ancestor a p160 element with an href p383 attribute. The img p186 element supports dimension attributes p271 . The IDL attributes alt, src, useMap, and isMap each must reflect p57 the respective content attributes of the same name. This box is non-normative. Implementation requirements are given below this box. image . width p189 [ = value ] image . height p189 [ = value ] These attributes return the actual rendered dimensions of the image, or zero if the dimensions are not known. They can be set, to change the corresponding content attributes. image . naturalWidth p189 image . naturalHeight p189 These attributes return the intrinsic dimensions of the image, or zero if the dimensions are not known. image . complete p189 Returns true if the image has been downloaded, decoded, and found to be valid; otherwise, returns false. image = new Image p189 ( [ width [, height ] ] ) Returns a new img p186 element, with the width p271 and height p271 attributes set to the values passed in the relevant arguments, if applicable. The IDL attributes width and height must return the rendered width and height of the image, in CSS pixels, if the image is being rendered p638 , and is being rendered to a visual medium; or else the intrinsic width and height of the image, in CSS pixels, if the image is available p187 but not being rendered to a visual medium; or else 0, if the image is not available p187 . [CSS] p700 On setting, they must act as if they reflected p57 the respective content attributes of the same name. The IDL attributes naturalWidth and naturalHeight must return the intrinsic width and height of the image, in CSS pixels, if the image is available p187 , or else 0. [CSS] p700 The IDL attribute complete must return true if the user agent has fetched the image specified in the src p186 attribute, and it is in a supported image type (i.e. it was decoded without fatal errors), even if the final task p489 queued by the networking task source p491 for the fetching p55 of the image resource has not yet been processed. Otherwise, the attribute must return false. Note: The value of complete p189 can thus change while a script p487 is executing. Three constructors are provided for creating HTMLImageElement p186 objects (in addition to the factory methods from DOM Core such as createElement()): Image(), Image(width), and Image(width, height). When invoked as constructors, these must return a new HTMLImageElement p186 object (a new img p186 element). If the width argument is present, the new object's width p271 content attribute must be set to width. If the height argument is also present, the new object's height p271 content attribute must be set to height. The element's document must be the active document p439 of the browsing context p439 of the Window p443 object on which the interface object of the invoked constructor is found. A single image can have different appropriate alternative text depending on the context. In each of the following cases, the same image is used, yet the alt p186 text is different each time. The image is the coat of arms of the Carouge municipality in the canton Geneva in Switzerland. Here it is used as a supplementary icon:

    I lived in Carouge.

    Here it is used as an icon representing the town:

    Home town: Carouge

    189 Here it is used as part of a text on the town:

    Carouge has a coat of arms.

    The coat of arms depicts a lion, sitting in front of a
tree.

    It is used as decoration all over the town.

    Here it is used as a way to support a similar text where the description is given as well as, instead of as an alternative to, the image:

    Carouge has a coat of arms.

    The coat of arms depicts a lion, sitting in front of a tree. It is used as decoration all over the town.

    Here it is used as part of a story:

    He picked up the folder and a piece of paper fell out.

    Shaped like a shield, the paper had a
red background, a green tree, and a yellow lion with its tongue
hanging out and whose tail was shaped like an S.

    He stared at the folder. S! The answer he had been looking for all this time was simply the letter S! How had he not seen that before? It all came together now. The phone call where Hector had referred to a lion's tail, the time Marco had stuck his tongue out...

    Here it is not known at the time of publication what the image will be, only that it will be a coat of arms of some kind, and thus no replacement text can be provided, and instead only a brief caption for the image is provided, in the title p84 attribute:

    The last user to have uploaded a coat of arms uploaded this one:

    Ideally, the author would find a way to provide real replacement text even in this case, e.g. by asking the previous user. Not providing replacement text makes the document more difficult to use for people who are unable to view images, e.g. blind users, or users or very low-bandwidth connections or who pay by the byte, or users who are forced to use a text-only Web browser. Here are some more examples showing the same picture used in different contexts, with different appropriate alternate texts each time.

    My cats

    Fluffy

    Fluffy is my favorite.

    She likes playing with a ball of yarn.

    She's just too cute.

    Miles

    My other cat, Miles just eats and sleeps.

    Photography

    Shooting moving targets indoors

    The trick here is to know how to anticipate; to know at what speed and what distance the subject will pass by.

    A cat flying by, chasing a ball of yarn, can be
photographed quite nicely using this technique.

    Nature by night

    To achieve this, you'll need either an extremely sensitive film, or immense flash lights.

    About me

    My pets

    I've got a cat named Fluffy and a dog named Miles.

    Fluffy, my cat, tends to keep itself busy.

    My dog Miles and I like go on long walks together.

    music

    After our walks, having emptied my mind, I like listening to Bach.

    Fluffy and the Yarn

    Fluffy was a cat who liked to play with yarn. He also liked to jump.

    190

    He would play in the morning, he would play in the evening.

    4.8.1.1 Requirements for providing text to act as an alternative for images Except where otherwise specified, the alt p186 attribute must be specified and its value must not be empty; the value must be an appropriate replacement for the image. The specific requirements for the alt p186 attribute depend on what the image is intended to represent, as described in the following sections. 4.8.1.1.1 A link or button containing nothing but the image When an a p160 element that is a hyperlink p383 , or a button p332 element, has no textual content but contains one or more images, the alt p186 attributes must contain text that together convey the purpose of the link or button. In this example, a user is asked to pick his preferred color from a list of three. Each color is given by an image, but for users who have configured their user agent not to display images, the color names are used instead:

    Pick your color

    • Green
    • Blue
    • Red
    In this example, each button has a set of images to indicate the kind of color output desired by the user. The first image is used in each case to give the alternative text. Since each image represents one part of the text, it could also be written like this: However, with other alternative text, this might not work, and putting all the alternative text into one image in each case might make more sense: 4.8.1.1.2 A phrase or paragraph with an alternative graphical representation: charts, diagrams, graphs, maps, illustrations Sometimes something can be more clearly stated in graphical form, for example as a flowchart, a diagram, a graph, or a simple map showing directions. In such cases, an image can be given using the img p186 element, but the lesser textual version must still be given, so that users who are unable to view the image (e.g. because they have a very slow connection, or because they are using a text-only browser, or because they are listening to the page being read out by a hands-free automobile voice Web browser, or simply because they are blind) are still able to understand the message being conveyed. The text must be given in the alt p186 attribute, and must convey the same message as the image specified in the src p186 attribute. It is important to realize that the alternative text is a replacement for the image, not a description of the image. In the following example we have a flowchart in image form, with text in the alt p186 attribute rephrasing the flowchart in prose form:

    In the common case, the data handled by the tokenization stage comes from the network, but it can also come from script.

    The network
passes data to the Tokenizer stage, which passes data to the Tree
Construction stage. From there, data goes to both the DOM and to

191

Script Execution. Script Execution is linked to the DOM, and, using
document.write(), passes data to the Tokenizer.

    Here's another example, showing a good solution and a bad solution to the problem of including an image in a description. First, here's the good solution. This sample shows how the alternative text should just be what you would have put in the prose if the image had never existed.

    You are standing in an open field west of a house. The house is white, with a boarded front door. There is a small mailbox here.

    Second, here's the bad solution. In this incorrect way of doing things, the alternative text is simply a description of the image, instead of a textual replacement for the image. It's bad because when the image isn't shown, the text doesn't flow as well as in the first example.

    You are standing in an open field west of a house. A white house, with a boarded front door. There is a small mailbox here.

    Text such as "Photo of white house with boarded door" would be equally bad alternative text (though it could be suitable for the title p84 attribute or in the figcaption p159 element of a figure p158 with this image). 4.8.1.1.3 A short phrase or label with an alternative graphical representation: icons, logos A document can contain information in iconic form. The icon is intended to help users of visual browsers to recognize features at a glance. In some cases, the icon is supplemental to a text label conveying the same meaning. In those cases, the alt p186 attribute must be present but must be empty. Here the icons are next to text that conveys the same meaning, so they have an empty alt p186 attribute: In other cases, the icon has no text next to it describing what it means; the icon is supposed to be selfexplanatory. In those cases, an equivalent textual label must be given in the alt p186 attribute. Here, posts on a news site are labeled with an icon indicating their topic.

    Ratatouille wins Best Movie of the Year award

    Movies

    Pixar has won yet another Best Movie of the Year award, making this its 8th win in the last 12 years.

    Latest TWiT episode is online

    Podcasts

    The latest TWiT episode has been posted, in which we hear several tech news stories as well as learning much more about the iPhone. This week, the panelists compare how reflective their iPhones' Apple logos are.

    192 Many pages include logos, insignia, flags, or emblems, which stand for a particular entity such as a company, organization, project, band, software package, country, or some such. If the logo is being used to represent the entity, e.g. as a page heading, the alt p186 attribute must contain the name of the entity being represented by the logo. The alt p186 attribute must not contain text like the word "logo", as it is not the fact that it is a logo that is being conveyed, it's the entity itself. If the logo is being used next to the name of the entity that it represents, then the logo is supplemental, and its alt p186 attribute must instead be empty. If the logo is merely used as decorative material (as branding, or, for example, as a side image in an article that mentions the entity to which the logo belongs), then the entry below on purely decorative images applies. If the logo is actually being discussed, then it is being used as a phrase or paragraph (the description of the logo) with an alternative graphical representation (the logo itself), and the first entry above applies. In the following snippets, all four of the above cases are present. First, we see a logo used to represent a company:

    The XYZ company

    Next, we see a paragraph which uses a logo right next to the company name, and so doesn't have any alternative text:

    News

    We have recently been looking at buying the ΑΒΓ company, a small Greek company specializing in our type of product.

    In this third snippet, we have a logo being used in an aside, as part of the larger article discussing the acquisition:

    The ΑΒΓ company has had a good quarter, and our pie chart studies of their accounts suggest a much bigger blue slice than its green and orange slices, which is always a good sign.

    Finally, we have an opinion piece talking about a logo, and the logo is therefore described in detail in the alternative text.

    Consider for a moment their logo:

    It consists of a green circle with a
green question mark centered inside it.

    How unoriginal can you get? I mean, oooooh, a question mark, how revolutionary, how utterly ground-breaking, I'm sure everyone will rush to adopt those specifications now! They could at least have tried for some sort of, I don't know, sequence of rounded squares with varying shades of green and bold white outlines, at least that would look good on the cover of a blue book.

    This example shows how the alternative text should be written such that if the image isn't available p187 , and the text is used instead, the text flows seamlessly into the surrounding text, as if the image had never been there in the first place. 4.8.1.1.4 Text that has been rendered to a graphic for typographical effect Sometimes, an image just consists of text, and the purpose of the image is not to highlight the actual typographic effects used to render the text, but just to convey the text itself. In such cases, the alt p186 attribute must be present but must consist of the same text as written in the image itself. Consider a graphic containing the text "Earth Day", but with the letters all decorated with flowers and plants. If the text is merely being used as a heading, to spice up the page for graphical users, then the correct alternative text is just the same text "Earth Day", and no mention need be made of the decorations:

    Earth Day

    193 4.8.1.1.5 A graphical representation of some of the surrounding text In many cases, the image is actually just supplementary, and its presence merely reinforces the surrounding text. In these cases, the alt p186 attribute must be present but its value must be the empty string. In general, an image falls into this category if removing the image doesn't make the page any less useful, but including the image makes it a lot easier for users of visual browsers to understand the concept. A flowchart that repeats the previous paragraph in graphical form:

    The network passes data to the Tokenizer stage, which passes data to the Tree Construction stage. From there, data goes to both the DOM and to Script Execution. Script Execution is linked to the DOM, and, using document.write(), passes data to the Tokenizer.

    In these cases, it would be wrong to include alternative text that consists of just a caption. If a caption is to be included, then either the title p84 attribute can be used, or the figure p158 and figcaption p159 elements can be used. In the latter case, the image would in fact be a phrase or paragraph with an alternative graphical representation, and would thus require alternative text.

    The network passes data to the Tokenizer stage, which passes data to the Tree Construction stage. From there, data goes to both the DOM and to Script Execution. Script Execution is linked to the DOM, and, using document.write(), passes data to the Tokenizer.

    The network passes data to the Tokenizer stage, which passes data to the Tree Construction stage. From there, data goes to both the DOM and to Script Execution. Script Execution is linked to the DOM, and, using document.write(), passes data to the Tokenizer.

    The Network leads
to the Tokenizer, which leads to the Tree Construction. The Tree
Construction leads to two items. The first is Script Execution, which
leads via document.write() back to the Tokenizer. The second item
from which Tree Construction leads is the DOM. The DOM is related to
the Script Execution.
    Flowchart representation of the parsing model.

    The network passes data to the Tokenizer stage, which passes data to the Tree Construction stage. From there, data goes to both the DOM and to Script Execution. Script Execution is linked to the DOM, and, using document.write(), passes data to the Tokenizer.

    Flowchart representation of the parsing model.

    A graph that repeats the previous paragraph in graphical form:

    According to a study covering several billion pages, about 62% of documents on the Web in 2007 triggered the Quirks rendering mode of Web browsers, about 30% triggered the Almost Standards mode, and about 9% triggered the Standards mode.

    4.8.1.1.6 A purely decorative image that doesn't add any information In general, if an image is decorative but isn't especially page-specific, for example an image that forms part of a site-wide design scheme, the image should be specified in the site's CSS, not in the markup of the document. However, a decorative image that isn't discussed by the surrounding text but still has some relevance can be included in a page using the img p186 element. Such images are decorative, but still form part of the content. In these cases, the alt p186 attribute must be present but its value must be the empty string. 194 Examples where the image is purely decorative despite being relevant would include things like a photo of the Black Rock City landscape in a blog post about an event at Burning Man, or an image of a painting inspired by a poem, on a page reciting that poem. The following snippet shows an example of the latter case (only the first verse is included in this snippet):

    The Lady of Shalott

    On either side the river lie
    Long fields of barley and of rye,
    That clothe the wold and meet the sky;
    And through the field the road run by
    To many-tower'd Camelot;
    And up and down the people go,
    Gazing where the lilies blow
    Round an island there below,
    The island of Shalott.

    4.8.1.1.7 A group of images that form a single larger picture with no links When a picture has been sliced into smaller image files that are then displayed together to form the complete picture again, one of the images must have its alt p186 attribute set as per the relevant rules that would be appropriate for the picture as a whole, and then all the remaining images must have their alt p186 attribute set to the empty string. In the following example, a picture representing a company logo for XYZ Corp has been split into two pieces, the first containing the letters "XYZ" and the second with the word "Corp". The alternative text ("XYZ Corp") is all in the first image.

    XYZ Corp

    In the following example, a rating is shown as three filled stars and two empty stars. While the alternative text could have been "★★★☆☆", the author has instead decided to more helpfully give the rating in the form "3 out of 5". That is the alternative text of the first image, and the rest have blank alternative text.

    Rating: 3 out of 5

    4.8.1.1.8 A group of images that form a single larger picture with links Generally, image maps p268 should be used instead of slicing an image for links. However, if an image is indeed sliced and any of the components of the sliced picture are the sole contents of links, then one image per link must have alternative text in its alt p186 attribute representing the purpose of the link. In the following example, a picture representing the flying spaghetti monster emblem, with each of the left noodly appendages and the right noodly appendages in different images, so that the user can pick the left side or the right side in an adventure.

    The Church

    You come across a flying spaghetti monster. Which side of His Noodliness do you wish to reach out for?

    Left side. Right side.

    4.8.1.1.9 A key part of the content In some cases, the image is a critical part of the content. This could be the case, for instance, on a page that is part of a photo gallery. The image is the whole point of the page containing it. How to provide alternative text for an image that is a key part of the content depends on the image's provenance. The general case When it is possible for detailed alternative text to be provided, for example if the image is part of a series of screenshots in a magazine review, or part of a comic strip, or is a photograph in a blog entry about that photograph, text that can serve as a substitute for the image must be given as the contents of the alt p186 attribute. A screenshot in a gallery of screenshots for a new OS, with some alternative text: 195
    The desktop is blue, with icons along the left hand side in
two columns, reading System, Home, K-Mail, etc. A window is
open showing that menus wrap to a second line if they
cannot fit in the window. The window has a list of icons
along the top, with an address bar below it, a list of
icons for tabs along the left edge, a status bar on the
bottom, and two panes in the middle. The desktop has a bar
at the bottom of the screen with a few buttons, a pager, a
list of open applications, and a clock.
    Screenshot of a KDE desktop.
    A graph in a financial report: From 1998 to 2005, sales increased by the following percentages
with each year: 624%, 75%, 138%, 40%, 35%, 9%, 21% Note that "sales graph" would be inadequate alternative text for a sales graph. Text that would be a good caption is not generally suitable as replacement text. Images that defy a complete description In certain cases, the nature of the image might be such that providing thorough alternative text is impractical. For example, the image could be indistinct, or could be a complex fractal, or could be a detailed topographical map. In these cases, the alt p186 attribute must contain some suitable alternative text, but it may be somewhat brief. Sometimes there simply is no text that can do justice to an image. For example, there is little that can be said to usefully describe a Rorschach inkblot test. However, a description, even if brief, is still better than nothing:
    A shape with left-right
symmetry with indistinct edges, with a small gap in the center, two
larger gaps offset slightly from the center, with two similar gaps
under them. The outline is wider in the top half than the bottom
half, with the sides extending upwards higher than the center, and
the center extending below the sides.
    A black outline of the first of the ten cards in the Rorschach inkblot test.
    Note that the following would be a very bad use of alternative text:
    A black outline
of the first of the ten cards in the Rorschach inkblot test.
    A black outline of the first of the ten cards in the Rorschach inkblot test.
    Including the caption in the alternative text like this isn't useful because it effectively duplicates the caption for users who don't have images, taunting them twice yet not helping them any more than if they had only read or heard the caption once. Another example of an image that defies full description is a fractal, which, by definition, is infinite in detail. The following example shows one possible way of providing alternative text for the full view of an image of the Mandelbrot set. The Mandelbrot set appears as a cardioid with
its cusp on the real axis in the positive direction, with a smaller
bulb aligned along the same center line, touching it in the negative
direction, and with these two shapes being surrounded by smaller bulbs
of various sizes. Images whose contents are not known In some unfortunate cases, there might be no alternative text available at all, either because the image is obtained in some automated fashion without any associated alternative text (e.g. a Webcam), or because 196 the page is being generated by a script using user-provided images where the user did not provide suitable or usable alternative text (e.g. photograph sharing sites), or because the author does not himself know what the images represent (e.g. a blind photographer sharing an image on his blog). In such cases, the alt p186 attribute's value may be omitted, but one of the following conditions must be met as well: • The title p84 attribute is present and has a non-empty value. • The img p186 element is in a figure p158 element that contains a figcaption p159 element that contains content other than inter-element whitespace p89 . • The img p186 element is part of the only paragraph p93 directly in its section p145 , and is the only img p186 element without an alt p186 attribute in its section, and its section p145 has an associated heading. Note: Such cases are to be kept to an absolute minimum. If there is even the slightest possibility of the author having the ability to provide real alternative text, then it would not be acceptable to omit the alt p186 attribute. A photo on a photo-sharing site, if the site received the image with no metadata other than the caption:
    Bubbles traveled everywhere with us.
    It could also be marked up like this:

    Bubbles traveled everywhere with us.

    In either case, though, it would be better if a detailed description of the important parts of the image obtained from the user and included on the page. A blind user's blog in which a photo taken by the user is shown. Initially, the user might not have any idea what the photo he took shows:

    I took a photo

    I went out today and took a photo!

    A photograph taken blindly from my front porch.
    Eventually though, the user might obtain a description of the image from his friends and could then include alternative text:

    I took a photo

    I went out today and took a photo!

    The photograph shows my hummingbird
feeder hanging from the edge of my roof. It is half full, but there
are no birds around. In the background, out-of-focus trees fill the
shot. The feeder is made of wood with a metal grate, and it contains
peanuts. The edge of the roof is wooden too, and is painted white
with light blue streaks.
    A photograph taken blindly from my front porch.
    Sometimes the entire point of the image is that a textual description is not available, and the user is to provide the description. For instance, the point of a CAPTCHA image is to see if the user can literally read the graphic. Here is one way to mark up a CAPTCHA (note the title p84 attribute):

    (If you cannot see the image, you can use an audio test instead.)

    197 Another example would be software that displays images and asks for alternative text precisely for the purpose of then writing a page with correct alternative text. Such a page could have a table of images, like this:
    , this would be flagged as an error and the author could correct the typo immediately. Errors that allow for new syntax in future In order to allow us to extend the language syntax in the future, certain otherwise harmless features are disallowed. For example, "attributes" in end tags are ignored currently, but they are invalid, in case a future change to the language makes use of that syntax feature without conflicting with already-deployed (and valid!) content. Some authors find it helpful to be in the practice of always quoting all attributes and always including all optional tags, preferring the consistency derived from such custom over the minor benefits of terseness afforded by making use of the flexibility of the HTML syntax. To aid such authors, conformance checkers can provide modes of operation wherein such conventions are enforced. 1.10.3 Restrictions on content models and on attribute values This section is non-normative. Beyond the syntax of the language, this specification also places restrictions on how elements and attributes can be specified. These restrictions are present for similar reasons: Errors that flag content with dubious semantics To avoid misuse of elements with defined meanings, content models are defined that restrict how elements can be nested when such nestings would be of dubious value. For example, this specification disallows nesting a section p133 element inside a kbd p173 element, since it is highly unlikely for an author to indicate that an entire section should be keyed in. Errors that indicate a conflict in expressed semantics Similarly, to draw the author's attention to mistakes in the use of elements, clear contradictions in the semantics expressed are also considered conformance errors. 23 In the fragments below, for example, the semantics are nonsensical: a row cannot simultaneously be a cell, nor can a radio button be a progress bar.
    Image Description
    Notice that even in this example, as much useful information as possible is still included in the title p84 attribute. Note: Since some users cannot use images at all (e.g. because they have a very slow connection, or because they are using a text-only browser, or because they are listening to the page being read out by a hands-free automobile voice Web browser, or simply because they are blind), the alt p186 attribute is only allowed to be omitted rather than being provided with replacement text when no alternative text is available and none can be made available, as in the above examples. Lack of effort from the part of the author is not an acceptable reason for omitting the alt p186 attribute. 4.8.1.1.10 An image not intended for the user Generally authors should avoid using img p186 elements for purposes other than showing images. If an img p186 element is being used for purposes other than showing an image, e.g. as part of a service to count page views, then the alt p186 attribute must be the empty string. In such cases, the width p271 and height p271 attributes should both be set to zero. 4.8.1.1.11 An image in an e-mail or private document intended for a specific person who is known to be able to view images This section does not apply to documents that are publicly accessible, or whose target audience is not necessarily personally known to the author, such as documents on a Web site, e-mails sent to public mailing lists, or software documentation. When an image is included in a private communication (such as an HTML e-mail) aimed at a specific person who is known to be able to view images, the alt p186 attribute may be omitted. However, even in such cases it is strongly recommended that alternative text be included (as appropriate according to the kind of image involved, as described in the above entries), so that the e-mail is still usable should the user use a mail client that does not support images, or should the document be forwarded on to other users whose abilities might not include easily seeing images. 4.8.1.1.12 General guidelines The most general rule to consider when writing alternative text is the following: the intent is that replacing every image with the text of its alt p186 attribute not change the meaning of the page. So, in general, alternative text can be written by considering what one would have written had one not been able to include the image. A corollary to this is that the alt p186 attribute's value should never contain text that could be considered the image's caption, title, or legend. It is supposed to contain replacement text that could be used by users instead of the image; it is not meant to supplement the image. The title p84 attribute can be used for supplemental information. Note: One way to think of alternative text is to think about how you would read the page containing the image to someone over the phone, without mentioning that there is an image present. Whatever you say instead of the image is typically a good start for writing the alternative text. 198 4.8.1.1.13 Guidance for markup generators Markup generators (such as WYSIWYG authoring tools) should, wherever possible, obtain alternative text from their users. However, it is recognized that in many cases, this will not be possible. For images that are the sole contents of links, markup generators should examine the link target to determine the title of the target, or the URL of the target, and use information obtained in this manner as the alternative text. As a last resort, implementors should either set the alt p186 attribute to the empty string, under the assumption that the image is a purely decorative image that doesn't add any information but is still specific to the surrounding content, or omit the alt p186 attribute altogether, under the assumption that the image is a key part of the content. Markup generators should generally avoid using the image's own file name as the alternative text. Similarly, markup generators should avoid generating alternative text from any content that will be equally available to presentation user agents (e.g. Web browsers). Note: This is because once a page is generated, it will typically not be updated, whereas the browsers that later read the page can be updated by the user, therefore the browser is likely to have more up-to-date and finely-tuned heuristics than the markup generator did when generating the page. 4.8.1.1.14 Guidance for conformance checkers A conformance checker must report the lack of an alt p186 attribute as an error unless one of the conditions listed below applies: • The title p84 attribute is present and has a non-empty value (as described above p196 ). • The img p186 element is in a figure p158 element that contains a figcaption p159 element that contains content other than inter-element whitespace p89 (as described above p196 ). • The img p186 element is part of the only paragraph p93 directly in its section p145 , and is the only img p186 element without an alt p186 attribute in its section, and its section p145 has an associated heading (as described above p196 ). • The conformance checker has been configured to assume that the document is an e-mail or document intended for a specific person who is known to be able to view images. • The document has a meta p112 element with a name p113 attribute whose value is an ASCII caseinsensitive p33 match for the string "generator p114 ". (This case does not represent a case where the document is conforming, only that the generator could not determine appropriate alternative text — validators are required to not show an error in this case to discourage markup generators from including bogus alternative text purely in an attempt to silence validators.) 4.8.2 The iframe element Categories Flow content p91 . Phrasing content p91 . Embedded content p92 . Interactive content p92 . Contexts in which this element may be used: Where embedded content p92 is expected. Content model: Text that conforms to the requirements given in the prose. Content attributes: Global attributes p82 src p200 srcdoc p200 name p202 sandbox p202 seamless p204 width p271 height p271 199 DOM interface: interface HTMLIFrameElement : HTMLElement { attribute DOMString src; attribute DOMString srcdoc; attribute DOMString name; [PutForwards=value] readonly attribute DOMSettableTokenList sandbox; attribute boolean seamless; attribute DOMString width; attribute DOMString height; readonly attribute Document contentDocument; readonly attribute WindowProxy contentWindow; }; The iframe p199 element represents p638 a nested browsing context p439 . The src attribute gives the address of a page that the nested browsing context p439 is to contain. The attribute, if present, must be a valid non-empty URL p51 . The srcdoc attribute gives the content of the page that the nested browsing context p439 is to contain. The value of the attribute in is an iframe srcdoc document. For iframe p199 elements in HTML documents p71 , the attribute, if present, must have a value using the HTML syntax p547 that consists of the following syntactic components, in the given order: 1. Any number of comments p554 and space characters p34 . 2. Optionally, a DOCTYPE p547 . 3. Any number of comments p554 and space characters p34 . 4. The root element, in the form of an html p106 element p548 . 5. Any number of comments p554 and space characters p34 . For iframe p199 elements in XML documents p71 , the attribute, if present, must have a value that matches the production labeled document p31 in the XML specification. [XML] p705 If the src p200 attribute and the srcdoc p200 attribute are both specified together, the srcdoc p200 attribute takes priority. This allows authors to provide a fallback URL p51 for legacy user agents that do not support the srcdoc p200 attribute. When an iframe p199 element is first inserted into a document p27 , the user agent must create a nested browsing context p439 , and then process the iframe attributes p200 for the first time. Whenever an iframe p199 element with a nested browsing context p439 has its srcdoc p200 attribute set or changed, the user agent must process the iframe attributes p200 . Similarly, whenever an iframe p199 element with a nested browsing context p439 but with no srcdoc p200 attribute specified has its src p200 attribute set or changed, the user agent must process the iframe attributes p200 . When the user agent is to process the iframe attributes, it must run the first appropriate steps from the following list: p200 attribute is specified ↪ If the srcdoc Navigate p459 the element's browsing context p439 to a resource whose Content-Type p57 is text/html p678 , whose URL p51 is about:srcdoc p52 , and whose data consists of the value of the attribute. p200 attribute is specified but the srcdoc p200 attribute is not ↪ If the src 200 1. If the value of the src p200 attribute is the empty string, jump to the empty step below. 2. Resolve p51 the value of the src p200 attribute, relative to the iframe p199 element. 3. If that is not successful, then jump to the empty step below. 4. If the resulting absolute URL p52 is an ASCII case-insensitive p33 match for the string "about:blank p56 ", and the user agent is processing this iframe p199 's attributes for the first time, then jump to the empty step below. (In cases other than the first time, about:blank p56 is loaded normally.) 5. Navigate p459 the element's browsing context p439 to the resulting absolute URL p52 . Empty: When the steps above require the user agent to jump to the empty step, if the user agent is processing this iframe p199 's attributes for the first time, then the user agent must queue a task p490 to fire a simple event p496 named load at the iframe p199 element. (After jumping to this step, the above steps are not resumed.) ↪ Otherwise Queue a task p490 to fire a simple event p496 named load at the iframe p199 element. Any navigation p459 required of the user agent in the process the iframe attributes p200 algorithm must be completed with the iframe p199 element's document's browsing context p439 as the source browsing context p459 . Furthermore, if the process the iframe attributes p200 algorithm was invoked for the first time for this element (i.e. as a result of the element being inserted into a document p27 ), then any navigation p459 required of the user agent in that algorithm must be completed with replacement enabled p466 . Note: If, when the element is created, the srcdoc p200 attribute is not set, and the src p200 attribute is either also not set or set but its value cannot be resolved p51 , the browsing context will remain at the initial about:blank p56 page. Note: If the user navigates p459 away from this page, the iframe p199 's corresponding WindowProxy p449 object will proxy new Window p443 objects for new Document p31 objects, but the src p200 attribute will not change. Here a blog uses the srcdoc p200 attribute in conjunction with the sandbox p202 and seamless p204 attributes described below to provide users of user agents that support this feature with an extra layer of protection from script injection in the blog post comments:

    I got my own magazine!

    After much effort, I've finally found a publisher, and so now I have my own magazine! Isn't that awesome?! The first issue will come out in September, and we have articles about getting food, and about getting in boxes, it's going to be great!

    Written by cap.

    At , ch writes:
    At , cap writes:
    At , ch writes:
    Notice the way that quotes have to be escaped (otherwise the sandbox p202 attribute would end prematurely), and the way raw ampersands (e.g. in URLs or in prose) mentioned in the sandboxed content have to be doubly escaped — once so that the ampersand is preserved when originally parsing the sandbox p202 attribute, and once more to prevent the ampersand from being misinterpreted when parsing the sandboxed content. Note: In the HTML syntax p547 , authors need only remember to use U+0022 QUOTATION MARK characters (") to wrap the attribute contents and then to escape all U+0022 QUOTATION MARK (") and U+0026 AMPERSAND (&) characters, and to specify the sandbox p202 attribute, to ensure safe embedding of content. Note: Due to restrictions of the XML syntax, in XML a number of other characters need to be escaped also to ensure correctness. 201 The name attribute, if present, must be a valid browsing context name p442 . The given value is used to name the nested browsing context p439 . When the browsing context is created, if the attribute is present, the browsing context name p442 must be set to the value of this attribute; otherwise, the browsing context name p442 must be set to the empty string. Whenever the name p202 attribute is set, the nested browsing context p439 's name p442 must be changed to the new value. If the attribute is removed, the browsing context name p442 must be set to the empty string. When content loads in an iframe p199 , after any load events are fired within the content itself, the user agent must queue a task p490 to fire a simple event p496 named load at the iframe p199 element. When content whose URL p51 has the same origin p451 as the iframe p199 element's Document p31 fails to load (e.g. due to a DNS error, network error, or if the server returned a 4xx or 5xx status code or equivalent p56 ), then the user agent must queue a task p490 to fire a simple event p496 named error at the element instead. (This event does not fire for parse errors p554 , script errors, or any errors for cross-origin resources.) The task source p490 for these tasks p489 is the DOM manipulation task source p491 . Note: A load event is also fired at the iframe p199 element when it is created if no other data is loaded in it. When there is an active parser p75 in the iframe p199 , and when anything in the iframe p199 is delaying the load event p619 of the iframe p199 's browsing context p439 's active document p439 , the iframe p199 must delay the load event p619 of its document. Note: If, during the handling of the load event, the browsing context p439 in the iframe p199 is again navigated p459 , that will further delay the load event p619 . The sandbox attribute, when specified, enables a set of extra restrictions on any content hosted by the iframe p199 . Its value must be an unordered set of unique space-separated tokens p49 . The allowed values are allow-sameorigin p203 , allow-top-navigation p202 , allow-forms p203 , and allow-scripts p203 . When the attribute is set, the content is treated as being from a unique origin p449 , forms and scripts are disabled, links are prevented from targeting other browsing contexts p439 , and plugins are disabled. The allow-same-origin p203 keyword allows the content to be treated as being from the same origin instead of forcing it into a unique origin, the allow-topnavigation p202 keyword allows the content to navigate p459 its top-level browsing context p439 , and the allowforms p203 and allow-scripts p203 keywords re-enable forms and scripts respectively (though scripts are still prevented from creating popups). ⚠Warning! Setting both the allow-scripts p203 and allow-same-origin p203 keywords together when the embedded page has the same origin p451 as the page containing the iframe p199 allows the embedded page to simply remove the sandbox p202 attribute. ⚠Warning! Sandboxing hostile content is of minimal help if an attacker can convince the user to just visit the hostile content directly, rather than in the iframe p199 . To limit the damage that can be caused by hostile HTML content, it should be served using the text/html-sandboxed p679 MIME type. While the sandbox p202 attribute is specified, the iframe p199 element's nested browsing context p439 must have the flags given in the following list set. In addition, any browsing contexts nested p439 within an iframe p199 , either directly or indirectly, must have all the flags set on them as were set on the iframe p199 's Document p31 's browsing context p439 when the iframe p199 's Document p31 was created. The sandboxed navigation browsing context flag This flag prevents content from navigating browsing contexts other than the sandboxed browsing context itself p459 (or browsing contexts further nested inside it), and the top-level browsing context p439 (which is protected by the sandboxed top-level navigation browsing context flag p202 defined next). This flag also prevents content from creating new auxiliary browsing contexts p442 , e.g. using the target p384 attribute or the window.open() p445 method. The sandboxed top-level navigation browsing context flag, unless the sandbox p202 attribute's value, when split on spaces p49 , is found to have the allow-top-navigation keyword set This flag prevents content from navigating their top-level browsing context p459 . When the allow-top-navigation p202 is set, content can navigate its top-level browsing context p439 , but other browsing contexts p439 are still protected by the sandboxed navigation browsing context flag p202 defined above. The sandboxed plugins browsing context flag This flag prevents content from instantiating plugins p27 , whether using the embed element p206 , the object element p211 , the applet element p665 , or through navigation p464 of a nested browsing context p439 . 202 The sandboxed seamless iframes flag This flag prevents content from using the seamless p204 attribute on descendant iframe p199 elements. Note: This prevents a page inserted using the allow-same-origin p203 keyword from using a CSS-selector-based method of probing the DOM of other pages on the same site (in particular, pages that contain user-sensitive information). The sandboxed origin browsing context flag, unless the sandbox p202 attribute's value, when split on spaces p49 , is found to have the allow-same-origin keyword set This flag forces content into a unique origin p450 , thus preventing it from accessing other content from the same origin p449 . This flag also prevents script from reading from or writing to the document.cookie IDL attribute p74 , and blocks access to localStorage and openDatabase(). [WEBSTORAGE] p704 [WEBSQL] p704 The allow-same-origin p203 attribute is intended for two cases. First, it can be used to allow content from the same site to be sandboxed to disable scripting, while still allowing access to the DOM of the sandboxed content. Second, it can be used to embed content from a third-party site, sandboxed to prevent that site from opening popup windows, etc, without preventing the embedded page from communicating back to its originating site, using the database APIs to store data, etc. The sandboxed forms browsing context flag, unless the sandbox p202 attribute's value, when split on spaces p49 , is found to have the allow-forms keyword set This flag blocks form submission p361 . The sandboxed scripts browsing context flag, unless the sandbox p202 attribute's value, when split on spaces p49 , is found to have the allow-scripts keyword set This flag blocks script execution p487 . The sandboxed automatic features browsing context flag, unless the sandbox p202 attribute's value, when split on spaces p49 , is found to have the allow-scripts p203 keyword (defined above) set This flag blocks features that trigger automatically, such as automatically playing a video p231 or automatically focusing a form control p354 . It is relaxed by the same flag as scripts, because when scripts are enabled these features are trivially possible anyway, and it would be unfortunate to force authors to use script to do them when sandboxed rather than allowing them to use the declarative features. These flags must not be set unless the conditions listed above define them as being set. ⚠Warning! These flags only take effect when the nested browsing context p439 of the iframe p199 is navigated p459 . Removing then, or removing the entire sandbox p202 attribute, has no effect on an already-loaded page. In this example, some completely-unknown, potentially hostile, user-provided HTML content is embedded in a page. Because it is sandboxed, it is treated by the user agent as being from a unique origin, despite the content being served from the same site. Thus it is affected by all the normal cross-site restrictions. In addition, the embedded page has scripting disabled, plugins disabled, forms disabled, and it cannot navigate any frames or windows other than itself (or any frames or windows it itself embeds).

    We're not scared of you! Here is your content, unedited:

    Note that cookies are still sent to the server in the getusercontent.cgi request, though they are not visible in the document.cookie p74 IDL attribute. ⚠Warning! It is important that the server serve the user-provided HTML using the text/htmlsandboxed p679 MIME type so that if the attacker convinces the user to visit that page directly, the page doesn't run in the context of the site's origin, which would make the user vulnerable to any attack found in the page. In this example, a gadget from another site is embedded. The gadget has scripting and forms enabled, and the origin sandbox restrictions are lifted, allowing the gadget to communicate with its originating server. The sandbox is still useful, however, as it disables plugins and popups, thus reducing the risk of the user being exposed to malware and other annoyances. Suppose a file A contained the following fragment: 203 Suppose that file B contained an iframe also: Further, suppose that file C contained a link: Link For this example, suppose all the files were served as text/html p678 . Page C in this scenario has all the sandboxing flags set. Scripts are disabled, because the iframe p199 in A has scripts disabled, and this overrides the allow-scripts p203 keyword set on the iframe p199 in B. Forms are also disabled, because the inner iframe p199 (in B) does not have the allow-forms p203 keyword set. Suppose now that a script in A removes all the sandbox p202 attributes in A and B. This would change nothing immediately. If the user clicked the link in C, loading page D into the iframe p199 in B, page D would now act as if the iframe p199 in B had the allow-same-origin p203 and allow-forms p203 keywords set, because that was the state of the nested browsing context p439 in the iframe p199 in A when page B was loaded. Generally speaking, dynamically removing or changing the sandbox p202 attribute is ill-advised, because it can make it quite hard to reason about what will be allowed and what will not. Note: Potentially hostile files can be served from the same server as the file containing the iframe p199 element by labeling them as text/html-sandboxed p679 instead of text/html p678 . This ensures that scripts in the files are unable to attack the site (as if they were actually served from another server), even if the user is tricked into visiting those pages directly, without the protection of the sandbox p202 attribute. ⚠Warning! If the allow-scripts p203 keyword is set along with allow-same-origin p203 keyword, and the file is from the same origin p451 as the iframe p199 's Document p31 , then a script in the "sandboxed" iframe could just reach out, remove the sandbox p202 attribute, and then reload itself, effectively breaking out of the sandbox altogether. The seamless attribute is a boolean attribute p34 . When specified, it indicates that the iframe p199 element's browsing context p439 is to be rendered in a manner that makes it appear to be part of the containing document (seamlessly included in the parent document). Specifically, when the attribute is set on an iframe p199 element whose owner Document p31 's browsing context p439 did not have the sandboxed seamless iframes flag p203 set when that Document p31 was created, and while either the browsing context p439 's active document p439 has the same origin p451 as the iframe p199 element's document, or the browsing context p439 's active document p439 's address p71 has the same origin p451 as the iframe p199 element's document, the following requirements apply: • The user agent must set the seamless browsing context flag to true for that browsing context p439 . This will cause links to open in the parent browsing context p459 . • In a CSS-supporting user agent: the user agent must add all the style sheets that apply to the iframe p199 element to the cascade of the active document p439 of the iframe p199 element's nested browsing context p439 , at the appropriate cascade levels, before any style sheets specified by the document itself. • In a CSS-supporting user agent: the user agent must, for the purpose of CSS property inheritance only, treat the root element of the active document p439 of the iframe p199 element's nested browsing context p439 as being a child of the iframe p199 element. (Thus inherited properties on the root element of the document in the iframe p199 will inherit the computed values of those properties on the iframe p199 element instead of taking their initial values.) • In visual media, in a CSS-supporting user agent: the user agent should set the intrinsic width of the iframe p199 to the width that the element would have if it was a non-replaced block-level element with 'width: auto'. • In visual media, in a CSS-supporting user agent: the user agent should set the intrinsic height of the iframe p199 to the height of the bounding box around the content rendered in the iframe p199 at its current width (as given in the previous bullet point), as it would be if the scrolling position was such that the top of the viewport for the content rendered in the iframe p199 was aligned with the origin of that content's canvas. • In visual media, in a CSS-supporting user agent: the user agent must force the height of the initial containing block of the active document p439 of the nested browsing context p439 of the iframe p199 to zero. Note: This is intended to get around the otherwise circular dependency of percentage dimensions that depend on the height of the containing block, thus affecting the 204 height of the document's bounding box, thus affecting the height of the viewport, thus affecting the size of the initial containing block. • In speech media, the user agent should render the nested browsing context p439 without announcing that it is a separate document. • User agents should, in general, act as if the active document p439 of the iframe p199 's nested browsing context p439 was part of the document that the iframe p199 is in. For example if the user agent supports listing all the links in a document, links in "seamlessly" nested documents would be included in that list without being significantly distinguished from links in the document itself. If the attribute is not specified, or if the origin p449 conditions listed above are not met, then the user agent should render the nested browsing context p439 in a manner that is clearly distinguishable as a separate browsing context p439 , and the seamless browsing context flag p204 must be set to false for that browsing context p439 . ⚠Warning! It is important that user agents recheck the above conditions whenever the active document p439 of the nested browsing context p439 of the iframe p199 changes, such that the seamless browsing context flag p204 gets unset if the nested browsing context p439 is navigated p459 to another origin. Note: The attribute can be set or removed dynamically, with the rendering updating in tandem. In this example, the site's navigation is embedded using a client-side include using an iframe p199 . Any links in the iframe p199 will, in new user agents, be automatically opened in the iframe p199 's parent browsing context; for legacy user agents, the site could also include a base p108 element with a target p109 attribute with the value _parent. Similarly, in new user agents the styles of the parent page will be automatically applied to the contents of the frame, but to support legacy user agents authors might wish to include the styles explicitly. The iframe p199 element supports dimension attributes p271 for cases where the embedded content has specific dimensions (e.g. ad units have well-defined dimensions). An iframe p199 element never has fallback content p92 , as it will always create a nested browsing context p439 , regardless of whether the specified initial contents are successfully used. Descendants of iframe p199 elements represent nothing. (In legacy user agents that do not support iframe p199 elements, the contents would be parsed as markup that could act as fallback content.) When used in HTML documents p71 , the allowed content model of iframe p199 elements is text, except that invoking the HTML fragment parsing algorithm p626 with the iframe p199 element as the context element and the text contents as the input must result in a list of nodes that are all phrasing content p91 , with no parse errors p554 having occurred, with no script p122 elements being anywhere in the list or as descendants of elements in the list, and with all the elements in the list (including their descendants) being themselves conforming. The iframe p199 element must be empty in XML documents p71 . Note: The HTML parser p554 treats markup inside iframe p199 elements as text. The IDL attributes src, srcdoc, name, sandbox, and seamless must reflect p57 the respective content attributes of the same name. The contentDocument IDL attribute must return the Document p31 object of the active document p439 of the iframe p199 element's nested browsing context p439 . The contentWindow IDL attribute must return the WindowProxy p449 object of the iframe p199 element's nested browsing context p439 . Here is an example of a page using an iframe p199 to include advertising from an advertising broker: 4.8.3 The embed element 205 Categories Flow content p91 . Phrasing content p91 . Embedded content p92 . Interactive content p92 . Contexts in which this element may be used: Where embedded content p92 is expected. Content model: Empty. Content attributes: Global attributes p82 src p206 type p206 width p271 height p271 Any other attribute that has no namespace (see prose). DOM interface: interface HTMLEmbedElement : HTMLElement { attribute DOMString src; attribute DOMString type; attribute DOMString width; attribute DOMString height; }; Depending on the type of content instantiated by the embed p205 element, the node may also support other interfaces. The embed p205 element represents p638 an integration point for an external (typically non-HTML) application or interactive content. The src attribute gives the address of the resource being embedded. The attribute, if present, must contain a valid non-empty URL p51 . The type attribute, if present, gives the MIME type p26 by which the plugin to instantiate is selected. The value must be a valid MIME type p26 . If both the type p206 attribute and the src p206 attribute are present, then the type p206 attribute must specify the same type as the explicit Content-Type metadata p57 of the resource given by the src p206 attribute. When the element is created with neither a src p206 attribute nor a type p206 attribute, and when attributes are removed such that neither attribute is present on the element anymore, and when the element has a media element p219 ancestor, and when the element has an ancestor object p208 element that is not showing its fallback content p92 , any plugins instantiated for the element must be removed, and the embed p205 element represents nothing. If either: • the sandboxed plugins browsing context flag p202 was set on the browsing context p439 for which the embed p205 element's Document p31 is the active document p439 when that Document p31 was created, or • the embed p205 element's Document p31 was parsed from a resource whose sniffed type p57 as determined during navigation p459 is text/html-sandboxed p679 ...then the user agent must render the embed p205 element in a manner that conveys that the plugin p27 was disabled. The user agent may offer the user the option to override the sandbox and instantiate the plugin p27 anyway; if the user invokes such an option, the user agent must act as if the conditions above did not apply for the purposes of this element. ⚠Warning! Plugins are disabled in sandboxed browsing contexts because they might not honor the restrictions imposed by the sandbox (e.g. they might allow scripting even when scripting in the sandbox is disabled). User agents should convey the danger of overriding the sandbox to the user if an option to do so is provided. An embed p205 element is said to be potentially active when the following conditions are all met simultaneously: • • 206 The element is in a Document p27 . The element's Document p31 is fully active p440 . • • • • • • The element has either a src p206 attribute set or a type p206 attribute set (or both). The element's src p206 attribute is either absent or its value is the empty string. The element is not in a Document p31 whose browsing context p439 had the sandboxed plugins browsing context flag p202 set when the Document p31 was created (unless this has been overridden as described above). The element's Document p31 was not parsed from a resource whose sniffed type p57 as determined during navigation p459 is text/html-sandboxed p679 (unless this has been overridden as described above). The element is not a descendant of a media element p219 . The element is not a descendant of an object p208 element that is not showing its fallback content p92 . Whenever an embed p205 element that was not potentially active p206 becomes potentially active p206 , and whenever a potentially active p206 embed p205 element's src p206 attribute is set, changed, or removed, and whenever a potentially active p206 embed p205 element's type p206 attribute is set, changed, or removed, the appropriate set of steps from the following is then applied: p206 attribute set ↪ If the element has a src The user agent must resolve p51 the value of the element's src p206 attribute, relative to the element. If that is successful, the user agent should fetch p55 the resulting absolute URL p52 , from the element's browsing context scope origin p441 if it has one. The task p489 that is queued p490 by the networking task source p491 once the resource has been fetched p55 must find and instantiate an appropriate plugin p27 based on the content's type p207 , and hand that plugin p27 the content of the resource, replacing any previously instantiated plugin for the element. Fetching the resource must delay the load event p619 of the element's document. p206 attribute set ↪ If the element has no src The user agent should find and instantiate an appropriate plugin p27 based on the value of the type p206 attribute. Whenever an embed p205 element that was potentially active p206 stops being potentially active p206 , any plugin p27 that had been instantiated for that element must be unloaded. Note: The embed p205 element is unaffected by the CSS 'display' property. The selected plugin is instantiated even if the element is hidden with a 'display:none' CSS style. The type of the content being embedded is defined as follows: 1. If the element has a type p206 attribute, and that attribute's value is a type that a plugin p27 supports, then the value of the type p206 attribute is the content's type p207 . 2. Otherwise, if the p51 component of the URL p51 of the specified resource (after any redirects) matches a pattern that a plugin p27 supports, then the content's type p207 is the type that that plugin can handle. For example, a plugin might say that it can handle resources with p51 components that end with the four character string ".swf". 3. Otherwise, if the specified resource has explicit Content-Type metadata p57 , then that is the content's type p207 . 4. Otherwise, the content has no type and there can be no appropriate plugin p27 for it. The embed p205 element has no fallback content p92 . If the user agent can't find a suitable plugin, then the user agent must use a default plugin. (This default could be as simple as saying "Unsupported Format".) Whether the resource is fetched successfully or not (e.g. whether the response code was a 2xx code or equivalent p56 ) must be ignored when determining the resource's type and when handing the resource to the plugin. Note: This allows servers to return data for plugins even with error responses (e.g. HTTP 500 Internal Server Error codes can still contain plugin data). Any namespace-less attribute other than name p662 , align p664 , hspace p664 , and vspace p664 may be specified on the embed p205 element, so long as its name is XML-compatible p27 and contains no characters in the range U+0041 to U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z). These attributes are then passed as parameters to the plugin p27 . Note: All attributes in HTML documents p71 get lowercased automatically, so the restriction on uppercase letters doesn't affect such documents. 207 Note: The four exceptions are to exclude legacy attributes that have side-effects beyond just sending parameters to the plugin p27 . The user agent should pass the names and values of all the attributes of the embed p205 element that have no namespace to the plugin p27 used, when it is instantiated. If the plugin p27 instantiated for the embed p205 element supports a scriptable interface, the HTMLEmbedElement p206 object representing the element should expose that interface while the element is instantiated. The embed p205 element supports dimension attributes p271 . The IDL attributes src and type each must reflect p57 the respective content attributes of the same name. Here's a way to embed a resource that requires a proprietary plug-in, like Flash: If the user does not have the plug-in (for example if the plug-in vendor doesn't support the user's platform), then the user will be unable to use the resource. To pass the plugin a parameter "quality" with the value "high", an attribute can be specified: This would be equivalent to the following, when using an object p208 element instead: 4.8.4 The object element Categories Flow content p91 . Phrasing content p91 . Embedded content p92 . If the element has a usemap p268 attribute: Interactive content p92 . Listed p297 , submittable p297 , form-associated element p297 . Contexts in which this element may be used: Where embedded content p92 is expected. Content model: Zero or more param p213 elements, then, transparent p93 . Content attributes: Global attributes p82 data p209 type p209 name p209 usemap p268 form p353 width p271 height p271 DOM interface: interface HTMLObjectElement : HTMLElement { attribute DOMString data; attribute DOMString type; attribute DOMString name; attribute DOMString useMap; readonly attribute HTMLFormElement form; attribute DOMString width; attribute DOMString height; readonly attribute Document contentDocument; readonly attribute WindowProxy contentWindow; readonly attribute boolean willValidate; readonly attribute ValidityState validity; readonly attribute DOMString validationMessage; 208 boolean checkValidity(); void setCustomValidity(in DOMString error); }; Depending on the type of content instantiated by the object p208 element, the node also supports other interfaces. The object p208 element can represent an external resource, which, depending on the type of the resource, will either be treated as an image, as a nested browsing context p439 , or as an external resource to be processed by a plugin p27 . The data attribute, if present, specifies the address of the resource. If present, the attribute must be a valid nonempty URL p51 . The type attribute, if present, specifies the type of the resource. If present, the attribute must be a valid MIME type p26 . At least one of either the data p209 attribute or the type p209 attribute must be present. The name attribute, if present, must be a valid browsing context name p442 . The given value is used to name the nested browsing context p439 , if applicable. When the element is created, when it is popped off the stack of open elements p563 of an HTML parser p554 or XML parser p635 , and subsequently whenever the element is inserted into a document p27 or removed from a document p27 ; and whenever the element's Document p31 changes whether it is fully active p440 ; and whenever an ancestor object p208 element changes to or from showing its fallback content p92 ; and whenever the element's classid p662 attribute is set, changed, or removed; and, when its classid p662 attribute is not present, whenever its data p209 attribute is set, changed, or removed; and, when neither its classid p662 attribute nor its data p209 attribute are present, whenever its type p209 attribute is set, changed, or removed: the user agent must queue a task p490 to run the following steps to (re)determine what the object p208 element represents. The task source p490 for this task p489 is the DOM manipulation task source p491 . 1. If the user has indicated a preference that this object p208 element's fallback content p92 be shown instead of the element's usual behavior, then jump to the last step in the overall set of steps (fallback). Note: For example, a user could ask for the element's fallback content p92 to be shown because that content uses a format that the user finds more accessible. 2. If the element has an ancestor media element p219 , or has an ancestor object p208 element that is not showing its fallback content p92 , or if the element is not in a Document p27 with a browsing context p439 , or if the element's Document p31 is not fully active p440 , or if the element is still in the stack of open elements p563 of an HTML parser p554 or XML parser p635 , then jump to the last step in the overall set of steps (fallback). 3. If the classid p662 attribute is present, and has a value that isn't the empty string, then: if the user agent can find a plugin p27 suitable according to the value of the classid p662 attribute, and plugins aren't being sandboxed p211 , then that plugin p27 should be used p211 , and the value of the data p209 attribute, if any, should be passed to the plugin p27 . If no suitable plugin p27 can be found, or if the plugin p27 reports an error, jump to the last step in the overall set of steps (fallback). 4. If the data p209 attribute is present and its value is not the empty string, then: 1. If the type p209 attribute is present and its value is not a type that the user agent supports, and is not a type that the user agent can find a plugin p27 for, then the user agent may jump to the last step in the overall set of steps (fallback) without fetching the content to examine its real type. 2. Resolve p51 the URL p51 specified by the data p209 attribute, relative to the element. 3. If that failed, fire a simple event p496 named error at the element, then jump to the last step in the overall set of steps (fallback). 4. Fetch p55 the resulting absolute URL p52 , from the element's browsing context scope origin p441 if it has one. Fetching the resource must delay the load event p619 of the element's document until the task p489 that is queued p490 by the networking task source p491 once the resource has been fetched p55 (defined next) has been run. 209 5. If the resource is not yet available (e.g. because the resource was not available in the cache, so that loading the resource required making a request over the network), then jump to the last step in the overall set of steps (fallback). The task p489 that is queued p490 by the networking task source p491 once the resource is available must restart this algorithm from this step. Resources can load incrementally; user agents may opt to consider a resource "available" whenever enough data has been obtained to begin processing the resource. 6. If the load failed (e.g. there was an HTTP 404 error, there was a DNS error), fire a simple event p496 named error at the element, then jump to the last step in the overall set of steps (fallback). 7. Determine the resource type, as follows: 1. Let the resource type be unknown. 2. Let the sniffed flag be false. 3. If the user agent is configured to strictly obey Content-Type headers for this resource, and the resource has associated Content-Type metadata p57 , then let the resource type be the type specified in the resource's Content-Type metadata p57 , and abort these substeps. 4. If there is a type p209 attribute present on the object p208 element, and that attribute's value is not a type that the user agent supports, but it is a type that a plugin p27 supports, then let the resource type be the type specified in that type p209 attribute. 5. Otherwise, if the resource type is unknown, and the resource has associated Content-Type metadata p57 , then let the resource type be the type specified in the resource's Content-Type metadata p57 . If this results in the resource type being "text/plain", then let the resource type be the result of applying the rules for distingushing if a resource is text or binary p57 to the resource instead, and then set the sniffed flag to true. 6. If the resource type is unknown or "application/octet-stream" at this point and there is a type p209 attribute present on the object p208 element, then change the resource type to instead be the type specified in that type p209 attribute. Otherwise, if the resource type is "application/octet-stream" but there is no type p209 attribute on the object p208 element, then change the resource type to be unknown, so that the sniffing rules in the following steps are invoked. 7. If the resource type is still unknown at this point, but the p51 component of the URL p51 of the specified resource (after any redirects) matches a pattern that a plugin p27 supports, then let resource type be the type that that plugin can handle. For example, a plugin might say that it can handle resources with p51 components that end with the four character string ".swf". 8. If the resource type is still unknown, and the sniffed flag is false, then change the resource type to instead be the sniffed type of the resource p57 . Otherwise, if the resource type is still unknown, and the sniffed flag is true, then change the resource type back to text/plain. 8. Handle the content as given by the first of the following cases that matches: ↪ If the resource type is not a type that the user agent supports, but it is a type that a plugin p27 supports If plugins are being sandboxed p211 , jump to the last step in the overall set of steps (fallback). Otherwise, the user agent should use the plugin that supports resource type p211 and pass the content of the resource to that plugin p27 . If the plugin p27 reports an error, then jump to the last step in the overall set of steps (fallback). p27 ↪ If the resource type is an XML MIME type , or if the resource type does not start with "image/" The object p208 element must be associated with a newly created nested browsing context p439 , if it does not already have one. If the URL p51 of the given resource is not about:blank p56 , the element's nested browsing context p439 must then be navigated p459 to that resource, with replacement 210 enabled p466 , and with the object p208 element's document's browsing context p439 as the source browsing context p459 . (The data p209 attribute of the object p208 element doesn't get updated if the browsing context gets further navigated to other locations.) If the URL p51 of the given resource is about:blank p56 , then, instead, the user agent must queue a task p490 to fire a simple event p496 named load at the object p208 element. The object p208 element represents p638 the nested browsing context p439 . If the name p209 attribute is present, the browsing context name p442 must be set to the value of this attribute; otherwise, the browsing context name p442 must be set to the empty string. Note: It's possible that the navigation p459 of the browsing context p439 will actually obtain the resource from a different application cache p471 . Even if the resource is then found to have a different type, it is still used as part of a nested browsing context p439 ; this algorithm doesn't restart with the new resource. ↪ If the resource type starts with "image/", and support for images has not been disabled Apply the image sniffing p57 rules to determine the type of the image. The object p208 element represents p638 the specified image. The image is not a nested browsing context p439 . If the image cannot be rendered, e.g. because it is malformed or in an unsupported format, jump to the last step in the overall set of steps (fallback). ↪ Otherwise The given resource type is not supported. Jump to the last step in the overall set of steps (fallback). 9. 10. The element's contents are not part of what the object p208 element represents. Once the resource is completely loaded, queue a task p490 to fire a simple event p496 named load at the element. The task source p490 for this task is the DOM manipulation task source p491 . 5. If the data p209 attribute is absent but the type p209 attribute is present, plugins aren't being sandboxed p211 , and the user agent can find a plugin p27 suitable according to the value of the type p209 attribute, then that plugin p27 should be used p211 . If no suitable plugin p27 can be found, or if the plugin p27 reports an error, jump to the next step (fallback). 6. (Fallback.) The object p208 element represents p638 the element's children, ignoring any leading param p213 element children. This is the element's fallback content p92 . If the element has an instantiated plugin p27 , then unload it. When the algorithm above instantiates a plugin p27 , the user agent should pass to the plugin p27 used the names and values of all the attributes on the element, in the order they were added to the element, with the attributes added by the parser being ordered in source order, followed by a parameter named "PARAM" whose value is null, followed by all the names and values of parameters p213 given by param p213 elements that are children of the object p208 element, in tree order p27 . If the plugin p27 supports a scriptable interface, the HTMLObjectElement p208 object representing the element should expose that interface. The object p208 element represents p638 the plugin p27 . The plugin p27 is not a nested browsing context p439 . If either: • the sandboxed plugins browsing context flag p202 was set on the object p208 element's Document p31 's browsing context p439 when the Document p31 was created, or • the object p208 element's Document p31 was parsed from a resource whose sniffed type p57 as determined during navigation p459 is text/html-sandboxed p679 ...then the steps above must always act as if they had failed to find a plugin p27 , even if one would otherwise have been used. 211 Note: The above algorithm is independent of CSS properties (including 'display', 'overflow', and 'visibility'). For example, it runs even if the element is hidden with a 'display:none' CSS style, and does not run again if the element's visibility changes. Due to the algorithm above, the contents of object p208 elements act as fallback content p92 , used only when referenced resources can't be shown (e.g. because it returned a 404 error). This allows multiple object p208 elements to be nested inside each other, targeting multiple user agents with different capabilities, with the user agent picking the first one it supports. Whenever the name p209 attribute is set, if the object p208 element has a nested browsing context p439 , its name p442 must be changed to the new value. If the attribute is removed, if the object p208 element has a browsing context p439 , the browsing context name p442 must be set to the empty string. The usemap p268 attribute, if present while the object p208 element represents an image, can indicate that the object has an associated image map p268 . The attribute must be ignored if the object p208 element doesn't represent an image. The form p353 attribute is used to explicitly associate the object p208 element with its form owner p353 . Constraint validation: object p208 elements are always barred from constraint validation p356 . The object p208 element supports dimension attributes p271 . The IDL attributes data, type, name, and useMap each must reflect p57 the respective content attributes of the same name. The contentDocument IDL attribute must return the Document p31 object of the active document p439 of the object p208 element's nested browsing context p439 , if it has one; otherwise, it must return null. The contentWindow IDL attribute must return the WindowProxy p449 object of the object p208 element's nested browsing context p439 , if it has one; otherwise, it must return null. The willValidate p358 , validity p359 , and validationMessage p359 attributes, and the checkValidity() p359 and setCustomValidity() p358 methods, are part of the constraint validation API p358 . In the following example, a Java applet is embedded in a page using the object p208 element. (Generally speaking, it is better to avoid using applets like these and instead use native JavaScript and HTML to provide the functionality, since that way the application will work on all Web browsers without requiring a third-party plugin. Many devices, especially embedded devices, do not support third-party technologies like Java.)

    You do not have Java available, or it is disabled.

    My Java Clock
    In this example, an HTML page is embedded in another using the object p208 element.
    My HTML Clock
    The following example shows how a plugin can be used in HTML (in this case the Flash plugin, to show a video file). Fallback is provided for users who do not have Flash enabled, in this case using the video p213 element to show the video for those using user agents that support video p213 , and finally providing a link to the video for those who have neither Flash nor a video p213 -capable browser.

    Look at my video:

    212 4.8.5 The param element Categories None. Contexts in which this element may be used: As a child of an object p208 element, before any flow content p91 . Content model: Empty. Content attributes: Global attributes p82 name p213 value p213 DOM interface: interface HTMLParamElement : HTMLElement { attribute DOMString name; attribute DOMString value; }; The param p213 element defines parameters for plugins invoked by object p208 elements. It does not represent p638 anything on its own. The name attribute gives the name of the parameter. The value attribute gives the value of the parameter. Both attributes must be present. They may have any value. If both attributes are present, and if the parent element of the param p213 is an object p208 element, then the element defines a parameter with the given name/value pair. The IDL attributes name and value must both reflect p57 the respective content attributes of the same name. The following example shows how the param p213 element can be used to pass a parameter to a plugin, in this case the O3D plugin. O3D test page

    This page requires the use of a proprietary technology. Since you have not installed the software product required to view this page, you should try visiting another site that instead uses open vendor-neutral technologies.

    4.8.6 The video element Categories Flow content p91 . Phrasing content p91 . Embedded content p92 . If the element has a controls p235 attribute: Interactive content p92 . Contexts in which this element may be used: Where embedded content p92 is expected. Content model: If the element has a src p220 attribute: transparent p93 , but with no media element p219 descendants. 213 If the element does not have a src p220 attribute: one or more source p217 elements, then, transparent p93 , but with no media element p219 descendants. Content attributes: Global attributes p82 src p220 poster p214 preload p227 autoplay p231 loop p229 controls p235 width p271 height p271 DOM interface: interface HTMLVideoElement : HTMLMediaElement { attribute DOMString width; attribute DOMString height; readonly attribute unsigned long videoWidth; readonly attribute unsigned long videoHeight; attribute DOMString poster; }; A video p213 element is used for playing videos or movies. Content may be provided inside the video p213 element. User agents should not show this content to the user; it is intended for older Web browsers which do not support video p213 , so that legacy video plugins can be tried, or to show text to the users of these older browsers informing them of how to access the video contents. Note: In particular, this content is not intended to address accessibility concerns. To make video content accessible to the blind, deaf, and those with other physical or cognitive disabilities, authors are expected to provide alternative media streams and/or to embed accessibility aids (such as caption or subtitle tracks, audio description tracks, or signlanguage overlays) into their media streams. The video p213 element is a media element p219 whose media data p219 is ostensibly video data, possibly with associated audio data. The src p220 , preload p227 , autoplay p231 , loop p229 , and controls p235 attributes are the attributes common to all media elements p219 . The poster attribute gives the address of an image file that the user agent can show while no video data is available. The attribute, if present, must contain a valid non-empty URL p51 . If the specified resource is to be used, then, when the element is created or when the poster p214 attribute is set, if its value is not the empty string, its value must be resolved p51 relative to the element, and if that is successful, the resulting absolute URL p52 must be fetched p55 , from the element's Document p31 's origin p449 ; this must delay the load event p619 of the element's document. The poster frame is then the image obtained from that resource, if any. Note: The image given by the poster p214 attribute, the poster frame p214 , is intended to be a representative frame of the video (typically one of the first non-blank frames) that gives the user an idea of what the video is like. The poster IDL attribute must reflect p57 the poster p214 content attribute. When no video data is available (the element's readyState p231 attribute is either HAVE_NOTHING p229 , or HAVE_METADATA p229 but no video data has yet been obtained at all), the video p213 element represents p638 either the poster frame p214 , or nothing. When a video p213 element is paused p231 and the current playback position p229 is the first frame of video, the element represents p638 either the frame of video corresponding to the current playback position p229 or the poster frame p214 , at the discretion of the user agent. Notwithstanding the above, the poster frame p214 should be preferred over nothing, but the poster frame p214 should not be shown again after a frame of video has been shown. 214 When a video p213 element is paused p231 at any other position, the element represents p638 the frame of video corresponding to the current playback position p229 , or, if that is not yet available (e.g. because the video is seeking or buffering), the last frame of the video to have been rendered. When a video p213 element is potentially playing p231 , it represents p638 the frame of video at the continuously increasing "current" position p229 . When the current playback position p229 changes such that the last frame rendered is no longer the frame corresponding to the current playback position p229 in the video, the new frame must be rendered. Similarly, any audio associated with the video must, if played, be played synchronized with the current playback position p229 , at the specified volume p236 with the specified mute state p236 . When a video p213 element is neither potentially playing p231 nor paused p231 (e.g. when seeking or stalled), the element represents p638 the last frame of the video to have been rendered. Note: Which frame in a video stream corresponds to a particular playback position is defined by the video stream's format. In addition to the above, the user agent may provide messages to the user (such as "buffering", "no video loaded", "error", or more detailed information) by overlaying text or icons on the video or other areas of the element's playback area, or in another appropriate manner. User agents that cannot render the video may instead make the element represent p638 a link to an external video playback utility or to the video data itself. This box is non-normative. Implementation requirements are given below this box. video . videoWidth p215 video . videoHeight p215 These attributes return the intrinsic dimensions of the video, or zero if the dimensions are not known. The intrinsic width and intrinsic height of the media resource p219 are the dimensions of the resource in CSS pixels after taking into account the resource's dimensions, aspect ratio, clean aperture, resolution, and so forth, as defined for the format used by the resource. If an anamorphic format does not define how to apply the aspect ratio to the video data's dimensions to obtain the "correct" dimensions, then the user agent must apply the ratio by increasing one dimension and leaving the other unchanged. The videoWidth IDL attribute must return the intrinsic width p215 of the video in CSS pixels. The videoHeight IDL attribute must return the intrinsic height p215 of the video in CSS pixels. If the element's readyState p231 attribute is HAVE_NOTHING p229 , then the attributes must return 0. The video p213 element supports dimension attributes p271 . Video content should be rendered inside the element's playback area such that the video content is shown centered in the playback area at the largest possible size that fits completely within it, with the video content's aspect ratio being preserved. Thus, if the aspect ratio of the playback area does not match the aspect ratio of the video, the video will be shown letterboxed or pillarboxed. Areas of the element's playback area that do not contain the video represent nothing. The intrinsic width of a video p213 element's playback area is the intrinsic width p215 of the video resource, if that is available; otherwise it is the intrinsic width of the poster frame p214 , if that is available; otherwise it is 300 CSS pixels. The intrinsic height of a video p213 element's playback area is the intrinsic height p215 of the video resource, if that is available; otherwise it is the intrinsic height of the poster frame p214 , if that is available; otherwise it is 150 CSS pixels. User agents should provide controls to enable or disable the display of closed captions, audio description tracks, and other additional data associated with the video stream, though such features should, again, not interfere with the page's normal rendering. User agents may allow users to view the video content in manners more suitable to the user (e.g. full-screen or in an independent resizable window). As for the other user interface features, controls to enable this should not interfere with the page's normal rendering unless the user agent is exposing a user interface p235 . In such an independent context, however, user agents may make full user interfaces visible, with, e.g., play, pause, seeking, and volume controls, even if the controls p235 attribute is absent. User agents may allow video playback to affect system features that could interfere with the user's experience; for example, user agents could disable screensavers while video playback is in progress. ⚠Warning! User agents should not provide a public API to cause videos to be shown full-screen. A script, combined with a carefully crafted video file, could trick the user into thinking a system-modal 215 dialog had been shown, and prompt the user for a password. There is also the danger of "mere" annoyance, with pages launching full-screen videos when links are clicked or pages navigated. Instead, user-agent-specific interface features may be provided to easily allow the user to obtain a full-screen playback mode. This example shows how to detect when a video has failed to play correctly:

    Download the video file.

    4.8.7 The audio element Categories Flow content p91 . Phrasing content p91 . Embedded content p92 . If the element has a controls p235 attribute: Interactive content p92 . Contexts in which this element may be used: Where embedded content p92 is expected. Content model: If the element has a src p220 attribute: transparent p93 , but with no media element p219 descendants. If the element does not have a src p220 attribute: one or more source p217 elements, then, transparent p93 , but with no media element p219 descendants. Content attributes: Global attributes p82 src p220 preload p227 autoplay p231 loop p229 controls p235 DOM interface: [NamedConstructor=Audio(), NamedConstructor=Audio(in DOMString src)] interface HTMLAudioElement : HTMLMediaElement {}; An audio p216 element represents p638 a sound or audio stream. Content may be provided inside the audio p216 element. User agents should not show this content to the user; it is intended for older Web browsers which do not support audio p216 , so that legacy audio plugins can be tried, or to show text to the users of these older browsers informing them of how to access the audio contents. 216 Note: In particular, this content is not intended to address accessibility concerns. To make audio content accessible to the deaf or to those with other physical or cognitive disabilities, authors are expected to provide alternative media streams and/or to embed accessibility aids (such as transcriptions) into their media streams. The audio p216 element is a media element p219 whose media data p219 is ostensibly audio data. The src p220 , preload p227 , autoplay p231 , loop p229 , and controls p235 attributes are the attributes common to all media elements p219 . When an audio p216 element is potentially playing p231 , it must have its audio data played synchronized with the current playback position p229 , at the specified volume p236 with the specified mute state p236 . When an audio p216 element is not potentially playing p231 , audio must not play for the element. This box is non-normative. Implementation requirements are given below this box. audio = new Audio p217 ( [ url ] ) Returns a new audio p216 element, with the src p220 attribute set to the value passed in the argument, if applicable. Two constructors are provided for creating HTMLAudioElement p216 objects (in addition to the factory methods from DOM Core such as createElement()): Audio() and Audio(src). When invoked as constructors, these must return a new HTMLAudioElement p216 object (a new audio p216 element). The element must have its preload p227 attribute set to the literal value "auto p227 ". If the src argument is present, the object created must have its src p220 content attribute set to the provided value, and the user agent must invoke the object's resource selection algorithm p223 before returning. The element's document must be the active document p439 of the browsing context p439 of the Window p443 object on which the interface object of the invoked constructor is found. 4.8.8 The source element Categories None. Contexts in which this element may be used: As a child of a media element p219 , before any flow content p91 . Content model: Empty. Content attributes: Global attributes p82 src p217 type p217 media p218 DOM interface: interface HTMLSourceElement : HTMLElement { attribute DOMString src; attribute DOMString type; attribute DOMString media; }; The source p217 element allows authors to specify multiple alternative media resources p219 for media elements p219 . It does not represent p638 anything on its own. The src attribute gives the address of the media resource p219 . The value must be a valid non-empty URL p51 . This attribute must be present. The type attribute gives the type of the media resource p219 , to help the user agent determine if it can play this media resource p219 before fetching it. If specified, its value must be a valid MIME type p26 . The codecs parameter may be specified and might be necessary to specify exactly how the resource is encoded. [RFC4281] p703 The following list shows some examples of how to use the codecs= MIME parameter in the type p217 attribute. 217 H.264 Simple baseline profile video (main and extended video compatible) level 3 and LowComplexity AAC audio in MP4 container H.264 Extended profile video (baseline-compatible) level 3 and Low-Complexity AAC audio in MP4 container H.264 Main profile video level 3 and Low-Complexity AAC audio in MP4 container H.264 'High' profile video (incompatible with main, baseline, or extended profiles) level 3 and Low-Complexity AAC audio in MP4 container MPEG-4 Visual Simple Profile Level 0 video and Low-Complexity AAC audio in MP4 container MPEG-4 Advanced Simple Profile Level 0 video and Low-Complexity AAC audio in MP4 container MPEG-4 Visual Simple Profile Level 0 video and AMR audio in 3GPP container Theora video and Vorbis audio in Ogg container Theora video and Speex audio in Ogg container Vorbis audio alone in Ogg container Speex audio alone in Ogg container FLAC audio alone in Ogg container Dirac video and Vorbis audio in Ogg container Theora video and Vorbis audio in Matroska container The media attribute gives the intended media type of the media resource p219 , to help the user agent determine if this media resource p219 is useful to the user before fetching it. Its value must be a valid media query p51 . The default, if the media attribute is omitted, is "all", meaning that by default the media resource p219 is suitable for all media. If a source p217 element is inserted as a child of a media element p219 that has no src p220 attribute and whose networkState p222 has the value NETWORK_EMPTY p222 , the user agent must invoke the media element p219 's resource selection algorithm p223 . The IDL attributes src, type, and media must reflect p57 the respective content attributes of the same name. If the author isn't sure if the user agents will all be able to render the media resources provided, the author can listen to the error event on the last source p217 element and trigger fallback behavior: 4.8.9 Media elements Media elements implement the following interface: interface HTMLMediaElement : HTMLElement { // error state readonly attribute MediaError error; // network state attribute DOMString src; readonly attribute DOMString currentSrc; const unsigned short NETWORK_EMPTY = 0; const unsigned short NETWORK_IDLE = 1; const unsigned short NETWORK_LOADING = 2; const unsigned short NETWORK_NO_SOURCE = 3; readonly attribute unsigned short networkState; attribute DOMString preload; readonly attribute TimeRanges buffered; void load(); DOMString canPlayType(in DOMString type); // ready state const unsigned short HAVE_NOTHING = 0; const unsigned short HAVE_METADATA = 1; const unsigned short HAVE_CURRENT_DATA = 2; const unsigned short HAVE_FUTURE_DATA = 3; const unsigned short HAVE_ENOUGH_DATA = 4; readonly attribute unsigned short readyState; readonly attribute boolean seeking; // playback state attribute readonly attribute readonly attribute readonly attribute attribute attribute readonly attribute readonly attribute readonly attribute attribute attribute void play(); void pause(); float currentTime; float startTime; float duration; boolean paused; float defaultPlaybackRate; float playbackRate; TimeRanges played; TimeRanges seekable; boolean ended; boolean autoplay; boolean loop; // controls attribute boolean controls; attribute float volume; attribute boolean muted; }; The media element attributes, src p220 , preload p227 , autoplay p231 , loop p229 , and controls p235 , apply to all media elements p219 . They are defined in this section. Media elements p219 are used to present audio data, or video and audio data, to the user. This is referred to as media data in this section, since this section applies equally to media elements p219 for audio or for video. The term media resource is used to refer to the complete set of media data, e.g. the complete video file, or complete audio file. Except where otherwise specified, the task source p490 for all the tasks queued p490 in this section and its subsections is the media element event task source. 219 4.8.9.1 Error codes This box is non-normative. Implementation requirements are given below this box. media . error p220 Returns a MediaError p220 object representing the current error state of the element. Returns null if there is no error. All media elements p219 have an associated error status, which records the last error the element encountered since its resource selection algorithm p223 was last invoked. The error attribute, on getting, must return the MediaError p220 object created for this last error, or null if there has not been an error. interface MediaError { const unsigned short MEDIA_ERR_ABORTED = 1; const unsigned short MEDIA_ERR_NETWORK = 2; const unsigned short MEDIA_ERR_DECODE = 3; const unsigned short MEDIA_ERR_SRC_NOT_SUPPORTED = 4; readonly attribute unsigned short code; }; This box is non-normative. Implementation requirements are given below this box. media . error p220 . code p220 Returns the current error's error code, from the list below. The code attribute of a MediaError p220 object must return the code for the error, which must be one of the following: MEDIA_ERR_ABORTED (numeric value 1) The fetching process for the media resource p219 was aborted by the user agent at the user's request. MEDIA_ERR_NETWORK (numeric value 2) A network error of some description caused the user agent to stop fetching the media resource p219 , after the resource was established to be usable. MEDIA_ERR_DECODE (numeric value 3) An error of some description occurred while decoding the media resource p219 , after the resource was established to be usable. MEDIA_ERR_SRC_NOT_SUPPORTED (numeric value 4) The media resource p219 indicated by the src p220 attribute was not suitable. 4.8.9.2 Location of the media resource The src content attribute on media elements p219 gives the address of the media resource (video, audio) to show. The attribute, if present, must contain a valid non-empty URL p51 . If a src p220 attribute of a media element p219 is set or changed, the user agent must invoke the media element p219 's media element load algorithm p222 . (Removing the src p220 attribute does not do this, even if there are source p217 elements present.) The src IDL attribute on media elements p219 must reflect p57 the content attribute of the same name. This box is non-normative. Implementation requirements are given below this box. media . currentSrc p220 Returns the address of the current media resource p219 . Returns the empty string when there is no media resource p219 . The currentSrc IDL attribute is initially the empty string. Its value is changed by the resource selection algorithm p223 defined below. 220 Note: There are two ways to specify a media resource p219 , the src p220 attribute, or source p217 elements. The attribute overrides the elements. 4.8.9.3 MIME types A media resource p219 can be described in terms of its type, specifically a MIME type p26 , optionally with a codecs parameter. [RFC4281] p703 Types are usually somewhat incomplete descriptions; for example "video/mpeg" doesn't say anything except what the container type is, and even a type like "video/mp4; codecs="avc1.42E01E, mp4a.40.2"" doesn't include information like the actual bitrate (only the maximum bitrate). Thus, given a type, a user agent can often only know whether it might be able to play media of that type (with varying levels of confidence), or whether it definitely cannot play media of that type. A type that the user agent knows it cannot render is one that describes a resource that the user agent definitely does not support, for example because it doesn't recognize the container type, or it doesn't support the listed codecs. The MIME type p26 "application/octet-stream" with no parameters is never a type that the user agent knows it cannot render p221 . User agents must treat that type as equivalent to the lack of any explicit Content-Type metadata p57 when it is used to label a potential media resource p219 . Note: In the absence of a specification to the contrary, the MIME type p26 "application/octetstream" when used with parameters, e.g. "application/octet-stream;codecs=theora", is a type that the user agent knows it cannot render p221 . This box is non-normative. Implementation requirements are given below this box. media . canPlayType p221 (type) Returns the empty string (a negative response), "maybe", or "probably" based on how confident the user agent is that it can play media resources of the given type. The canPlayType(type) method must return the empty string if type is a type that the user agent knows it cannot render p221 ; it must return "probably" if the user agent is confident that the type represents a media resource p219 that it can render if used in with this audio p216 or video p213 element; and it must return "maybe" otherwise. Implementors are encouraged to return "maybe" unless the type can be confidently established as being supported or not. Generally, a user agent should never return "probably" if the type doesn't have a codecs parameter. This script tests to see if the user agent supports a (fictional) new format to dynamically decide whether to use a video p213 element or a plugin:

    Download video

    221 Note: The type p217 attribute of the source p217 element allows the user agent to avoid downloading resources that use formats it cannot render. 4.8.9.4 Network states This box is non-normative. Implementation requirements are given below this box. media . networkState p222 Returns the current state of network activity for the element, from the codes in the list below. As media elements p219 interact with the network, their current network activity is represented by the networkState attribute. On getting, it must return the current network state of the element, which must be one of the following values: NETWORK_EMPTY (numeric value 0) The element has not yet been initialized. All attributes are in their initial states. NETWORK_IDLE (numeric value 1) The element's resource selection algorithm p223 is active and has selected a resource p219 , but it is not actually using the network at this time. NETWORK_LOADING (numeric value 2) The user agent is actively trying to download data. NETWORK_NO_SOURCE (numeric value 3) The element's resource selection algorithm p223 is active, but it has failed to find a resource p219 to use. The resource selection algorithm p223 defined below describes exactly when the networkState p222 attribute changes value and what events fire to indicate changes in this state. 4.8.9.5 Loading the media resource This box is non-normative. Implementation requirements are given below this box. media . load p222 () Causes the element to reset and start selecting and loading a new media resource p219 from scratch. All media elements p219 have an autoplaying flag, which must begin in the true state, and a delaying-the-loadevent flag, which must begin in the false state. While the delaying-the-load-event flag p222 is true, the element must delay the load event p619 of its document. When the load() method on a media element p219 is invoked, the user agent must run the media element load algorithm p222 . The media element load algorithm consists of the following steps. 1. Abort any already-running instance of the resource selection algorithm p223 for this element. 2. If there are any tasks p489 from the media element p219 's media element event task source p219 in one of the task queues p489 , then remove those tasks. Note: Basically, pending events and callbacks for the media element are discarded when the media element starts loading a new resource. 222 3. If the media element p219 's networkState p222 is set to NETWORK_LOADING p222 or NETWORK_IDLE p222 , queue a task p490 to fire a simple event p496 named abort p237 at the media element p219 . 4. If the media element p219 's networkState p222 is not set to NETWORK_EMPTY p222 , then run these substeps: 1. If a fetching process is in progress for the media element p219 , the user agent should stop it. 2. Set the networkState p222 attribute to NETWORK_EMPTY p222 . 3. If readyState p231 is not set to HAVE_NOTHING p229 , then set it to that state. 4. If the paused p231 attribute is false, then set to true. 5. If seeking p234 is true, set it to false. 6. Set the current playback position p229 to 0. 7. Queue a task p490 to fire a simple event p496 named emptied p237 at the media element p219 . 5. Set the playbackRate p232 attribute to the value of the defaultPlaybackRate p232 attribute. 6. Set the error p220 attribute to null and the autoplaying flag p222 to true. 7. Invoke the media element p219 's resource selection algorithm p223 . 8. Note: Playback of any previously playing media resource p219 for this element stops. The resource selection algorithm for a media element p219 is as follows. This algorithm is always invoked synchronously, but one of the first steps in the algorithm is to return and continue running the remaining steps asynchronously, meaning that it runs in the background with scripts and other tasks p489 running in parallel. In addition, this algorithm interacts closely with the event loop p489 mechanism; in particular, it has synchronous sections p490 (which are triggered as part of the event loop p489 algorithm). Steps in such sections are marked with ?. 1. Set the networkState p222 to NETWORK_NO_SOURCE p222 . 2. Asynchronously await a stable state p490 , allowing the task p489 that invoked this algorithm to continue. The synchronous section p490 consists of all the remaining steps of this algorithm until the algorithm says the synchronous section p490 has ended. (Steps in synchronous sections p490 are marked with ?.) 3. ? If the media element p219 has a src p220 attribute, then let mode be attribute. ? Otherwise, if the media element p219 does not have a src p220 attribute but has a source p217 element child, then let mode be children and let candidate be the first such source p217 element child in tree order p27 . ? Otherwise the media element p219 has neither a src p220 attribute nor a source p217 element child: set the networkState p222 to NETWORK_EMPTY p222 , and abort these steps; the synchronous section p490 ends. 4. ? Set the media element p219 's delaying-the-load-event flag p222 to true (this delays the load event p619 ), and set its networkState p222 to NETWORK_LOADING p222 . 5. ? Queue a task p490 to fire a simple event p496 named loadstart p237 at the media element p219 . 6. If mode is attribute, then run these substeps: 1. ? Process candidate: If the src p220 attribute's value is the empty string, then end the synchronous section p490 , and jump down to the failed step below. 2. ? Let absolute URL be the absolute URL p52 that would have resulted from resolving p51 the URL p51 specified by the src p220 attribute's value relative to the media element p219 when the src p220 attribute was last changed. 3. ? If absolute URL was obtained successfully, set the currentSrc p220 attribute to absolute URL. 4. End the synchronous section p490 , continuing the remaining steps asynchronously. 5. If absolute URL was obtained successfully, run the resource fetch algorithm p225 with absolute URL. If that algorithm returns without aborting this one, then the load failed. 6. Failed: Reaching this step indicates that the media resource failed to load or that the given URL p51 could not be resolved p51 . Set the error p220 attribute to a new MediaError p220 object whose code p220 attribute is set to MEDIA_ERR_SRC_NOT_SUPPORTED p220 . 7. Set the element's networkState p222 attribute to the NETWORK_NO_SOURCE p222 value. 8. Queue a task p490 to fire a simple event p496 named error p237 at the media element p219 . 9. Set the element's delaying-the-load-event flag p222 to false. This stops delaying the load event p619 . 10. Abort these steps. Until the load() p222 method is invoked or the src p220 attribute is changed, the element won't attempt to load another resource. Otherwise, the source p217 elements will be used; run these substeps: 1. ? Let pointer be a position defined by two adjacent nodes in the media element p219 's child list, treating the start of the list (before the first child in the list, if any) and end of the list (after the last child in the list, if any) as nodes in their own right. One node is the node before pointer, 223 and the other node is the node after pointer. Initially, let pointer be the position between the candidate node and the next node, if there are any, or the end of the list, if it is the last node. As nodes are inserted and removed into the media element p219 , pointer must be updated as follows: If a new node is inserted between the two nodes that define pointer Let pointer be the point between the node before pointer and the new node. In other words, insertions at pointer go after pointer. If the node before pointer is removed Let pointer be the point between the node after pointer and the node before the node after pointer. In other words, pointer doesn't move relative to the remaining nodes. If the node after pointer is removed Let pointer be the point between the node before pointer and the node after the node before pointer. Just as with the previous case, pointer doesn't move relative to the remaining nodes. Other changes don't affect pointer. 224 2. ? Process candidate: If candidate does not have a src p217 attribute, or if its src p217 attribute's value is the empty string, then end the synchronous section p490 , and jump down to the failed step below. 3. ? Let absolute URL be the absolute URL p52 that would have resulted from resolving p51 the URL p51 specified by candidate's src p217 attribute's value relative to the candidate when the src p217 attribute was last changed. 4. ? If absolute URL was not obtained successfully, then end the synchronous section p490 , and jump down to the failed step below. 5. ? If candidate has a type p217 attribute whose value, when parsed as a MIME type p26 (including any codecs described by the codecs parameter), represents a type that the user agent knows it cannot render p221 , then end the synchronous section p490 , and jump down to the failed step below. 6. ? If candidate has a media p218 attribute whose value does not match the environment p51 , then end the synchronous section p490 , and jump down to the failed step below. 7. ? Set the currentSrc p220 attribute to absolute URL. 8. End the synchronous section p490 , continuing the remaining steps asynchronously. 9. Run the resource fetch algorithm p225 with absolute URL. If that algorithm returns without aborting this one, then the load failed. 10. Failed: Queue a task p490 to fire a simple event p496 named error at the candidate element, in the context of the fetching process p55 that was used to try to obtain candidate's corresponding media resource p219 in the resource fetch algorithm p225 . 11. Asynchronously await a stable state p490 . The synchronous section p490 consists of all the remaining steps of this algorithm until the algorithm says the synchronous section p490 has ended. (Steps in synchronous sections p490 are marked with ?.) 12. ? Find next candidate: Let candidate be null. 13. ? Search loop: If the node after pointer is the end of the list, then jump to the waiting step below. 14. ? If the node after pointer is a source p217 element, let candidate be that element. 15. ? Advance pointer so that the node before pointer is now the node that was after pointer, and the node after pointer is the node after the node that used to be after pointer, if any. 16. ? If candidate is null, jump back to the search loop step. Otherwise, jump back to the process candidate step. 17. ? Waiting: Set the element's networkState p222 attribute to the NETWORK_NO_SOURCE p222 value. 18. ? Set the element's delaying-the-load-event flag p222 to false. This stops delaying the load event p619 . 19. End the synchronous section p490 , continuing the remaining steps asynchronously. 20. Wait until the node after pointer is a node other than the end of the list. (This step might wait forever.) 21. Asynchronously await a stable state p490 . The synchronous section p490 consists of all the remaining steps of this algorithm until the algorithm says the synchronous section p490 has ended. (Steps in synchronous sections p490 are marked with ?.) 22. ? Set the element's delaying-the-load-event flag p222 back to true (this delays the load event p619 again, in case it hasn't been fired yet). 23. ? Set the networkState p222 back to NETWORK_LOADING p222 . 24. ? Jump back to the find next candidate step above. The resource fetch algorithm for a media element p219 and a given absolute URL p52 is as follows: 1. Let the current media resource be the resource given by the absolute URL p52 passed to this algorithm. This is now the element's media resource p219 . 2. Begin to fetch p55 the current media resource, from the media element p219 's Document p31 's origin p449 . Every 350ms (±200ms) or for every byte received, whichever is least frequent, queue a task p490 to fire a simple event p496 named progress p237 at the element. If at any point the user agent has received no data for more than about three seconds, then queue a task p490 to fire a simple event p496 named stalled p237 at the element. User agents may allow users to selectively block or slow media data p219 downloads. When a media element p219 's download has been blocked altogether, the user agent must act as if it was stalled (as opposed to acting as if the connection was closed). The rate of the download may also be throttled automatically by the user agent, e.g. to balance the download with other connections sharing the same bandwidth. User agents may decide to not download more content at any time, e.g. after buffering five minutes of a one hour media resource, while waiting for the user to decide whether to play the resource or not, or while waiting for user input in an interactive resource. When a media element p219 's download has been suspended, the user agent must set the networkState p222 to NETWORK_IDLE p222 and queue a task p490 to fire a simple event p496 named suspend p237 at the element. If and when downloading of the resource resumes, the user agent must set the networkState p222 to NETWORK_LOADING p222 . Note: The preload p227 attribute provides a hint regarding how much buffering the author thinks is advisable, even in the absence of the autoplay p231 attribute. When a user agent decides to completely stall a download, e.g. if it is waiting until the user starts playback before downloading any further content, the element's delaying-the-load-event flag p222 must be set to false. This stops delaying the load event p619 . The user agent may use whatever means necessary to fetch the resource (within the constraints put forward by this and other specifications); for example, reconnecting to the server in the face of network errors, using HTTP range retrieval requests, or switching to a streaming protocol. The user agent must consider a resource erroneous only if it has given up trying to fetch it. The networking task source p491 tasks p489 to process the data as it is being fetched must, when appropriate, include the relevant substeps from the following list: p219 cannot be fetched at all, due to network errors, causing the user ↪ If the media data agent to give up trying to fetch the resource p219 is found to have Content-Type metadata p57 that, when parsed as ↪ If the media resource a MIME type p26 (including any codecs described by the codecs parameter), represents a type that the user agent knows it cannot render p221 (even if the actual media data p219 is in a supported format) p219 can be fetched but is found by inspection to be in an unsupported ↪ If the media data format, or can otherwise not be rendered at all DNS errors, HTTP 4xx and 5xx errors (and equivalents in other protocols), and other fatal network errors that occur before the user agent has established whether the current media resource is usable, as well as the file using an unsupported container format, or using unsupported codecs for all the data, must cause the user agent to execute the following steps: 1. The user agent should cancel the fetching process. 2. Abort this subalgorithm, returning to the resource selection algorithm p223 . 225 p219 has been fetched to determine the duration of the ↪ Once enough of the media data p219 media resource , its dimensions, and other metadata This indicates that the resource is usable. The user agent must follow these substeps: 1. Set the current playback position p229 to the earliest possible position p229 . 2. Set the readyState p231 attribute to HAVE_METADATA p229 . 3. For video p213 elements, set the videoWidth p215 and videoHeight p215 attributes. 4. Set the duration p228 attribute to the duration of the resource. Note: The user agent will p229 queue a task p490 to fire a simple event p496 named durationchange p238 at the element at this point. 5. Queue a task p490 to fire a simple event p496 named loadedmetadata p237 at the element. Note: Before this task is run, as part of the event loop mechanism, the rendering will have been updated to resize the video p213 element if appropriate. 6. If either the media resource p219 or the address of the current media resource indicate a particular start time, then seek p234 to that time. Ignore any resulting exceptions (if the position is out of range, it is effectively ignored). For example, a fragment identifier could be used to indicate a start position. 7. Once the readyState p231 attribute reaches HAVE_CURRENT_DATA p230 , after the loadeddata event has been fired p230 , set the element's delaying-the-load-event flag p222 to false. This stops delaying the load event p619 . Note: A user agent that is attempting to reduce network usage while still fetching the metadata for each media resource p219 would also stop buffering at this point, causing the networkState p222 attribute to switch to the NETWORK_IDLE p222 value. Note: The user agent is required to determine the duration of the media resource p219 and go through this step before playing. p219 has been fetched p55 (but potentially before any of it ↪ Once the entire media resource has been decoded) Queue a task p490 to fire a simple event p496 named progress p237 at the media element p219 . ↪ If the connection is interrupted, causing the user agent to give up trying to fetch the resource Fatal network errors that occur after the user agent has established whether the current media resource is usable must cause the user agent to execute the following steps: 1. The user agent should cancel the fetching process. 2. Set the error p220 attribute to a new MediaError p220 object whose code p220 attribute is set to MEDIA_ERR_NETWORK p220 . 3. Queue a task p490 to fire a simple event p496 named error p237 at the media element p219 . 4. Set the element's networkState p222 attribute to the NETWORK_EMPTY p222 value and queue a task p490 to fire a simple event p496 named emptied p237 at the element. 5. Set the element's delaying-the-load-event flag p222 to false. This stops delaying the load event p619 . 6. Abort the overall resource selection algorithm p223 . p219 is corrupted ↪ If the media data Fatal errors in decoding the media data p219 that occur after the user agent has established whether the current media resource is usable must cause the user agent to execute the following steps: 1. 226 The user agent should cancel the fetching process. 2. Set the error p220 attribute to a new MediaError p220 object whose code p220 attribute is set to MEDIA_ERR_DECODE p220 . 3. Queue a task p490 to fire a simple event p496 named error p237 at the media element p219 . 4. Set the element's networkState p222 attribute to the NETWORK_EMPTY p222 value and queue a task p490 to fire a simple event p496 named emptied p237 at the element. 5. Set the element's delaying-the-load-event flag p222 to false. This stops delaying the load event p619 . 6. Abort the overall resource selection algorithm p223 . p219 fetching process is aborted by the user ↪ If the media data The fetching process is aborted by the user, e.g. because the user navigated the browsing context to another page, the user agent must execute the following steps. These steps are not followed if the load() p222 method itself is invoked while these steps are running, as the steps above handle that particular kind of abort. 1. The user agent should cancel the fetching process. 2. Set the error p220 attribute to a new MediaError p220 object whose code p220 attribute is set to MEDIA_ERR_ABORTED p220 . 3. Queue a task p490 to fire a simple event p496 named abort p237 at the media element p219 . 4. If the media element p219 's readyState p231 attribute has a value equal to HAVE_NOTHING p229 , set the element's networkState p222 attribute to the NETWORK_EMPTY p222 value and queue a task p490 to fire a simple event p496 named emptied p237 at the element. Otherwise, set the element's networkState p222 attribute to the NETWORK_IDLE p222 value. 5. Set the element's delaying-the-load-event flag p222 to false. This stops delaying the load event p619 . 6. Abort the overall resource selection algorithm p223 . p219 can be fetched but has non-fatal errors or uses, in part, codecs that ↪ If the media data are unsupported, preventing the user agent from rendering the content completely correctly but not preventing playback altogether The server returning data that is partially usable but cannot be optimally rendered must cause the user agent to render just the bits it can handle, and ignore the rest. When the networking task source p491 has queued p490 the last task p489 as part of fetching p55 the media resource p219 (i.e. once the download has completed), if the fetching process completes without errors, including decoding the media data, and if all of the data is available to the user agent without network access, then, the user agent must move on to the next step. This might never happen, e.g. when streaming an infinite resource such as Web radio, or if the resource is longer than the user agent's ability to cache data. While the user agent might still need network access to obtain parts of the media resource p219 , the user agent must remain on this step. For example, if the user agent has discarded the first half of a video, the user agent will remain at this step even once the playback has ended p231 , because there is always the chance the user will seek back to the start. In fact, in this situation, once playback has ended p231 , the user agent will end up dispatching a stalled p237 event, as described earlier. 3. If the user agent ever reaches this step (which can only happen if the entire resource gets loaded and kept available): abort the overall resource selection algorithm p223 . The preload attribute is an enumerated attribute p34 . The following table lists the keywords and states for the attribute — the keywords in the left column map to the states in the cell in the second column on the same row as the keyword. Keyword none State None metadata Metadata auto Brief description Hints to the user agent that either the author does not expect the user to need the media resource, or that the server wants to minimise unnecessary traffic. Hints to the user agent that the author does not expect the user to need the media resource, but that fetching the resource metadata (dimensions, first frame, track list, duration, etc) is reasonable. Automatic Hints to the user agent that the user agent can put the user's needs first without risk to the server, up to and including optimistically downloading the entire resource. 227 The empty string is also a valid keyword, and maps to the Automatic p227 state. The attribute's missing value default is user-agent defined, though the Metadata p227 state is suggested as a compromise between reducing server load and providing an optimal user experience. The preload p227 attribute is intended to provide a hint to the user agent about what the author thinks will lead to the best user experience. The attribute may be ignored altogether, for example based on explicit user preferences or based on the available connectivity. The preload IDL attribute must reflect p57 the content attribute of the same name. Note: The autoplay p231 attribute can overrride the preload p227 attribute (since if the media plays, it naturally has to buffer first, regardless of the hint given by the preload p227 attribute). Including both is not an error, however. This box is non-normative. Implementation requirements are given below this box. media . buffered p228 Returns a TimeRanges p236 object that represents the ranges of the media resource p219 that the user agent has buffered. The buffered attribute must return a new static normalized TimeRanges object p236 that represents the ranges of the media resource p219 , if any, that the user agent has buffered, at the time the attribute is evaluated. Users agents must accurately determine the ranges available, even for media streams where this can only be determined by tedious inspection. Note: Typically this will be a single range anchored at the zero point, but if, e.g. the user agent uses HTTP range requests in response to seeking, then there could be multiple ranges. User agents may discard previously buffered data. Note: Thus, a time position included within a range of the objects return by the buffered p228 attribute at one time can end up being not included in the range(s) of objects returned by the same attribute at later times. 4.8.9.6 Offsets into the media resource This box is non-normative. Implementation requirements are given below this box. media . duration p228 Returns the length of the media resource p219 , in seconds. Returns NaN if the duration isn't available. Returns Infinity for unbounded streams. media . currentTime p229 [ = value ] Returns the current playback position p229 , in seconds. Can be set, to seek to the given time. Will throw an INVALID_STATE_ERR p70 exception if there is no selected media resource p219 . Will throw an INDEX_SIZE_ERR p70 exception if the given time is not within the ranges to which the user agent can seek. media . startTime p229 Returns the earliest possible position p229 , in seconds. This is the time for the start of the current clip. It might not be zero if the clip's timeline is not zero-based, or if the resource is a streaming resource (in which case it gives the earliest time that the user agent is able to seek back to). The duration attribute must return the length of the media resource p219 , in seconds. If no media data p219 is available, then the attributes must return the Not-a-Number (NaN) value. If the media resource p219 is known to be unbounded (e.g. a streaming radio), then the attribute must return the positive Infinity value. The user agent must determine the duration of the media resource p219 before playing any part of the media data p219 and before setting readyState p231 to a value equal to or greater than HAVE_METADATA p229 , even if doing so requires seeking to multiple parts of the resource. 228 When the length of the media resource p219 changes (e.g. from being unknown to known, or from a previously established length to a new length) the user agent must queue a task p490 to fire a simple event p496 named durationchange p238 at the media element p219 . If an "infinite" stream ends for some reason, then the duration would change from positive Infinity to the time of the last frame or sample in the stream, and the durationchange p238 event would be fired. Similarly, if the user agent initially estimated the media resource p219 's duration instead of determining it precisely, and later revises the estimate based on new information, then the duration would change and the durationchange p238 event would be fired. Media elements p219 have a current playback position, which must initially be zero. The current position is a time. The currentTime attribute must, on getting, return the current playback position p229 , expressed in seconds. On setting, the user agent must seek p234 to the new value (which might raise an exception). If the media resource p219 is a streaming resource, then the user agent might be unable to obtain certain parts of the resource after it has expired from its buffer. Similarly, some media resources p219 might have a timeline that doesn't start at zero. The earliest possible position is the earliest position in the stream or resource that the user agent can ever obtain again. The startTime attribute must, on getting, return the earliest possible position p229 , expressed in seconds. When the earliest possible position p229 changes, then: if the current playback position p229 is before the earliest possible position p229 , the user agent must seek p234 to the earliest possible position p229 ; otherwise, if the user agent has not fired a timeupdate p237 event at the element in the past 15 to 250ms and is not still running event handlers for such an event, then the user agent must queue a task p490 to fire a simple event p496 named timeupdate p237 at the element. Note: Because of the above requirement and the requirement in the resource fetch algorithm p225 that kicks in when the metadata of the clip becomes known p226 , the current playback position p229 can never be less than the earliest possible position p229 . User agents must act as if the timeline of the media resource p219 increases linearly starting from the earliest possible position p229 , even if the underlying media data p219 has out-of-order or even overlapping time codes. For example, if two clips have been concatenated into one video file, but the video format exposes the original times for the two clips, the video data might expose a timeline that goes, say, 00:15..00:29 and then 00:05..00:38. However, the user agent would not expose those times; it would instead expose the times as 00:15..00:29 and 00:29..01:02, as a single video. The loop attribute is a boolean attribute p34 that, if specified, indicates that the media element p219 is to seek back to the start of the media resource p219 upon reaching the end. The loop IDL attribute must reflect p57 the content attribute of the same name. 4.8.9.7 The ready states This box is non-normative. Implementation requirements are given below this box. media . readyState p231 Returns a value that expresses the current state of the element with respect to rendering the current playback position p229 , from the codes in the list below. Media elements p219 have a ready state, which describes to what degree they are ready to be rendered at the current playback position p229 . The possible values are as follows; the ready state of a media element at any particular time is the greatest value describing the state of the element: HAVE_NOTHING (numeric value 0) No information regarding the media resource p219 is available. No data for the current playback position p229 is available. Media elements p219 whose networkState p222 attribute is NETWORK_EMPTY p222 are always in the HAVE_NOTHING p229 state. HAVE_METADATA (numeric value 1) Enough of the resource has been obtained that the duration of the resource is available. In the case of a video p213 element, the dimensions of the video are also available. The API will no longer raise an exception when seeking. No media data p219 is available for the immediate current playback position p229 . 229 HAVE_CURRENT_DATA (numeric value 2) Data for the immediate current playback position p229 is available, but either not enough data is available that the user agent could successfully advance the current playback position p229 in the direction of playback p232 at all without immediately reverting to the HAVE_METADATA p229 state, or there is no more data to obtain in the direction of playback p232 . For example, in video this corresponds to the user agent having data from the current frame, but not the next frame; and to when playback has ended p231 . HAVE_FUTURE_DATA (numeric value 3) Data for the immediate current playback position p229 is available, as well as enough data for the user agent to advance the current playback position p229 in the direction of playback p232 at least a little without immediately reverting to the HAVE_METADATA p229 state. For example, in video this corresponds to the user agent having data for at least the current frame and the next frame. The user agent cannot be in this state if playback has ended p231 , as the current playback position p229 can never advance in this case. HAVE_ENOUGH_DATA (numeric value 4) All the conditions described for the HAVE_FUTURE_DATA p230 state are met, and, in addition, the user agent estimates that data is being fetched at a rate where the current playback position p229 , if it were to advance at the rate given by the defaultPlaybackRate p232 attribute, would not overtake the available data before playback reaches the end of the media resource p219 . When the ready state of a media element p219 whose networkState p222 is not NETWORK_EMPTY p222 changes, the user agent must follow the steps given below: p229 , and the new ready state is HAVE_METADATA p229 ↪ If the previous ready state was HAVE_NOTHING Note: A loadedmetadata p237 DOM event will be fired p226 as part of the load() p222 algorithm. p229 and the new ready state is HAVE_CURRENT_DATA p230 ↪ If the previous ready state was HAVE_METADATA or greater If this is the first time this occurs for this media element p219 since the load() p222 algorithm was last invoked, the user agent must queue a task p490 to fire a simple event p496 named loadeddata p237 at the element. If the new ready state is HAVE_FUTURE_DATA p230 or HAVE_ENOUGH_DATA p230 , then the relevant steps below must then be run also. p230 or more, and the new ready state is ↪ If the previous ready state was HAVE_FUTURE_DATA p230 HAVE_CURRENT_DATA or less Note: A waiting p237 DOM event can be fired p232 , depending on the current state of playback. p230 or less, and the new ready state is ↪ If the previous ready state was HAVE_CURRENT_DATA p230 HAVE_FUTURE_DATA The user agent must queue a task p490 to fire a simple event p496 named canplay p237 . If the element is potentially playing p231 , the user agent must queue a task p490 to fire a simple event p496 named playing p237 . p230 ↪ If the new ready state is HAVE_ENOUGH_DATA If the previous ready state was HAVE_CURRENT_DATA p230 or less, the user agent must queue a task p490 to fire a simple event p496 named canplay p237 , and, if the element is also potentially playing p231 , queue a task p490 to fire a simple event p496 named playing p237 . If the autoplaying flag p222 is true, and the paused p231 attribute is true, and the media element p219 has an autoplay p231 attribute specified, and the media element p219 is in a Document p31 whose browsing context p439 did not have the sandboxed automatic features browsing context flag p203 set when the Document p31 was created, then the user agent may also set the paused p231 attribute to false, queue a task p490 to fire a simple event p496 named play p237 , and queue a task p490 to fire a simple event p496 named playing p237 . Note: User agents are not required to autoplay, and it is suggested that user agents honor user preferences on the matter. Authors are urged to use the autoplay p231 attribute rather than using script to force the video to play, so as to allow the user to override the behavior if so desired. In any case, the user agent must finally queue a task p490 to fire a simple event p496 named canplaythrough p237 . 230 Note: It is possible for the ready state of a media element to jump between these states discontinuously. For example, the state of a media element can jump straight from HAVE_METADATA p229 to HAVE_ENOUGH_DATA p230 without passing through the HAVE_CURRENT_DATA p230 and HAVE_FUTURE_DATA p230 states. The readyState IDL attribute must, on getting, return the value described above that describes the current ready state of the media element p219 . The autoplay attribute is a boolean attribute p34 . When present, the user agent (as described in the algorithm described herein) will automatically begin playback of the media resource p219 as soon as it can do so without stopping. Note: Authors are urged to use the autoplay p231 attribute rather than using script to trigger automatic playback, as this allows the user to override the automatic playback when it is not desired, e.g. when using a screen reader. Authors are also encouraged to consider not using the automatic playback behavior at all, and instead to let the user agent wait for the user to start playback explicitly. The autoplay IDL attribute must reflect p57 the content attribute of the same name. 4.8.9.8 Playing the media resource This box is non-normative. Implementation requirements are given below this box. media . paused p231 Returns true if playback is paused; false otherwise. media . ended p232 Returns true if playback has reached the end of the media resource p219 . media . defaultPlaybackRate p232 [ = value ] Returns the default rate of playback, for when the user is not fast-forwarding or reversing through the media resource p219 . Can be set, to change the default rate of playback. The default rate has no direct effect on playback, but if the user switches to a fast-forward mode, when they return to the normal playback mode, it is expected that the rate of playback will be returned to the default rate of playback. media . playbackRate p232 [ = value ] Returns the current rate playback, where 1.0 is normal speed. Can be set, to change the rate of playback. media . played p232 Returns a TimeRanges p236 object that represents the ranges of the media resource p219 that the user agent has played. media . play p232 () Sets the paused p231 attribute to false, loading the media resource p219 and beginning playback if necessary. If the playback had ended, will restart it from the start. media . pause p233 () Sets the paused p231 attribute to true, loading the media resource p219 if necessary. The paused attribute represents whether the media element p219 is paused or not. The attribute must initially be true. A media element p219 is said to be potentially playing when its paused p231 attribute is false, the readyState p231 attribute is either HAVE_FUTURE_DATA p230 or HAVE_ENOUGH_DATA p230 , the element has not ended playback p231 , playback has not stopped due to errors p232 , and the element has not paused for user interaction p232 . A media element p219 is said to have ended playback when the element's readyState p231 attribute is HAVE_METADATA p229 or greater, and either the current playback position p229 is the end of the media resource p219 and the direction of playback p232 is forwards and the media element p219 does not have a loop p229 attribute specified, or the current playback position p229 is the earliest possible position p229 and the direction of playback p232 is backwards. 231 The ended attribute must return true if the media element p219 has ended playback p231 and the direction of playback p232 is forwards, and false otherwise. A media element p219 is said to have stopped due to errors when the element's readyState p231 attribute is HAVE_METADATA p229 or greater, and the user agent encounters a non-fatal error p227 during the processing of the media data p219 , and due to that error, is not able to play the content at the current playback position p229 . A media element p219 is said to have paused for user interaction when its paused p231 attribute is false, the readyState p231 attribute is either HAVE_FUTURE_DATA p230 or HAVE_ENOUGH_DATA p230 and the user agent has reached a point in the media resource p219 where the user has to make a selection for the resource to continue. It is possible for a media element p219 to have both ended playback p231 and paused for user interaction p232 at the same time. When a media element p219 that is potentially playing p231 stops playing because it has paused for user interaction p232 , the user agent must queue a task p490 to fire a simple event p496 named timeupdate p237 at the element. When a media element p219 that is potentially playing p231 stops playing because its readyState p231 attribute changes to a value lower than HAVE_FUTURE_DATA p230 , without the element having ended playback p231 , or playback having stopped due to errors p232 , or playback having paused for user interaction p232 , or the seeking algorithm p234 being invoked, the user agent must queue a task p490 to fire a simple event p496 named timeupdate p237 at the element, and queue a task p490 to fire a simple event p496 named waiting p237 at the element. When the current playback position p229 reaches the end of the media resource p219 when the direction of playback p232 is forwards, then the user agent must follow these steps: 1. If the media element p219 has a loop p229 attribute specified, then seek p234 to the earliest possible position p229 of the media resource p219 and abort these steps. 2. Stop playback. Note: The ended p232 attribute becomes true. 3. The user agent must queue a task p490 to fire a simple event p496 named timeupdate p237 at the element. 4. The user agent must queue a task p490 to fire a simple event p496 named ended p238 at the element. When the current playback position p229 reaches the earliest possible position p229 of the media resource p219 when the direction of playback p232 is backwards, then the user agent must follow these steps: 1. Stop playback. 2. The user agent must queue a task p490 to fire a simple event p496 named timeupdate p237 at the element. The defaultPlaybackRate attribute gives the desired speed at which the media resource p219 is to play, as a multiple of its intrinsic speed. The attribute is mutable: on getting it must return the last value it was set to, or 1.0 if it hasn't yet been set; on setting the attribute must be set to the new value. The playbackRate attribute gives the speed at which the media resource p219 plays, as a multiple of its intrinsic speed. If it is not equal to the defaultPlaybackRate p232 , then the implication is that the user is using a feature such as fast forward or slow motion playback. The attribute is mutable: on getting it must return the last value it was set to, or 1.0 if it hasn't yet been set; on setting the attribute must be set to the new value, and the playback must change speed (if the element is potentially playing p231 ). If the playbackRate p232 is positive or zero, then the direction of playback is forwards. Otherwise, it is backwards. The "play" function in a user agent's interface must set the playbackRate p232 attribute to the value of the defaultPlaybackRate p232 attribute before invoking the play() p232 method's steps. Features such as fast-forward or rewind must be implemented by only changing the playbackRate p232 attribute. When the defaultPlaybackRate p232 or playbackRate p232 attributes change value (either by being set by script or by being changed directly by the user agent, e.g. in response to user control) the user agent must queue a task p490 to fire a simple event p496 named ratechange p238 at the media element p219 . The played attribute must return a new static normalized TimeRanges object p236 that represents the ranges of the media resource p219 , if any, that the user agent has so far rendered, at the time the attribute is evaluated. When the play() method on a media element p219 is invoked, the user agent must run the following steps. 1. 232 If the media element p219 's networkState p222 attribute has the value NETWORK_EMPTY p222 , invoke the media element p219 's resource selection algorithm p223 . 2. If the playback has ended p231 and the direction of playback p232 is forwards, seek p234 to the earliest possible position p229 of the media resource p219 . Note: This will cause p234 the user agent to queue a task p490 to fire a simple event p496 named timeupdate p237 at the media element p219 . 3. 4. If the media element p219 's paused p231 attribute is true, run the following substeps: 1. Change the value of paused p231 to false. 2. Queue a task p490 to fire a simple event p496 named play p237 at the element. 3. If the media element p219 's readyState p231 attribute has the value HAVE_NOTHING p229 , HAVE_METADATA p229 , or HAVE_CURRENT_DATA p230 , queue a task p490 to fire a simple event p496 named waiting p237 at the element. 4. Otherwise, the media element p219 's readyState p231 attribute has the value HAVE_FUTURE_DATA p230 or HAVE_ENOUGH_DATA p230 ; queue a task p490 to fire a simple event p496 named playing p237 at the element. Set the media element p219 's autoplaying flag p222 to false. When the pause() method is invoked, the user agent must run the following steps: 1. If the media element p219 's networkState p222 attribute has the value NETWORK_EMPTY p222 , invoke the media element p219 's resource selection algorithm p223 . 2. Set the media element p219 's autoplaying flag p222 to false. 3. If the media element p219 's paused p231 attribute is false, run the following steps: 1. Change the value of paused p231 to true. 2. Queue a task p490 to fire a simple event p496 named timeupdate p237 at the element. 3. Queue a task p490 to fire a simple event p496 named pause p237 at the element. When a media element p219 is potentially playing p231 and its Document p31 is a fully active p440 Document p31 , its current playback position p229 must increase monotonically at playbackRate p232 units of media time per unit time of wall clock time. Note: This specification doesn't define how the user agent achieves the appropriate playback rate — depending on the protocol and media available, it is plausible that the user agent could negotiate with the server to have the server provide the media data at the appropriate rate, so that (except for the period between when the rate is changed and when the server updates the stream's playback rate) the client doesn't actually have to drop or interpolate any frames. When the playbackRate p232 is negative (playback is backwards), any corresponding audio must be muted. When the playbackRate p232 is so low or so high that the user agent cannot play audio usefully, the corresponding audio must also be muted. If the playbackRate p232 is not 1.0, the user agent may apply pitch adjustments to the audio as necessary to render it faithfully. The playbackRate p232 can be 0.0, in which case the current playback position p229 doesn't move, despite playback not being paused (paused p231 doesn't become true, and the pause p237 event doesn't fire). Media elements p219 that are potentially playing p231 while not in a Document p27 must not play any video, but should play any audio component. Media elements must not stop playing just because all references to them have been removed; only once a media element to which no references exist has reached a point where no further audio remains to be played for that element (e.g. because the element is paused, or because the end of the clip has been reached, or because its playbackRate p232 is 0.0) may the element be garbage collected. When the current playback position p229 of a media element p219 changes (e.g. due to playback or seeking), the user agent must run the following steps. If the current playback position p229 changes while the steps are running, then the user agent must wait for the steps to complete, and then must immediately rerun the steps. (These steps are thus run as often as possible or needed — if one iteration takes a long time, this can cause certain ranges to be skipped over as the user agent rushes ahead to "catch up".) 1. If the time was reached through the usual monotonic increase of the current playback position during normal playback, and if the user agent has not fired a timeupdate p237 event at the element in the past 15 to 250ms and is not still running event handlers for such an event, then the user agent must queue a 233 task p490 to fire a simple event p496 named timeupdate p237 at the element. (In the other cases, such as explicit seeks, relevant events get fired as part of the overall process of changing the current playback position.) Note: The event thus is not to be fired faster than about 66Hz or slower than 4Hz (assuming the event handlers don't take longer than 250ms to run). User agents are encouraged to vary the frequency of the event based on the system load and the average cost of processing the event each time, so that the UI updates are not any more frequent than the user agent can comfortably handle while decoding the video. When a media element p219 is removed from a Document p27 , if the media element p219 's networkState p222 attribute has a value other than NETWORK_EMPTY p222 then the user agent must act as if the pause() p233 method had been invoked. Note: If the media element p219 's Document p31 stops being a fully active p440 document, then the playback will stop p233 until the document is active again. 4.8.9.9 Seeking This box is non-normative. Implementation requirements are given below this box. media . seeking p234 Returns true if the user agent is currently seeking. media . seekable p235 Returns a TimeRanges p236 object that represents the ranges of the media resource p219 to which it is possible for the user agent to seek. The seeking attribute must initially have the value false. When the user agent is required to seek to a particular new playback position in the media resource p219 , it means that the user agent must run the following steps. This algorithm interacts closely with the event loop p489 mechanism; in particular, it has a synchronous section p490 (which is triggered as part of the event loop p489 algorithm). Steps in that section are marked with ?. 1. If the media element p219 's readyState p231 is HAVE_NOTHING p229 , then raise an INVALID_STATE_ERR p70 exception (if the seek was in response to a DOM method call or setting of an IDL attribute), and abort these steps. 2. If the element's seeking p234 IDL attribute is true, then another instance of this algorithm is already running. Abort that other instance of the algorithm without waiting for the step that it is running to complete. 3. Set the seeking p234 IDL attribute to true. 4. Queue a task p490 to fire a simple event p496 named timeupdate p237 at the element. 5. If the seek was in response to a DOM method call or setting of an IDL attribute, then continue the script. The remainder of these steps must be run asynchronously. With the exception of the steps marked with ?, they could be aborted at any time by another instance of this algorithm being invoked. 6. If the new playback position is later than the end of the media resource p219 , then let it be the end of the media resource p219 instead. 7. If the new playback position is less than the earliest possible position p229 , let it be that position instead. 8. If the (possibly now changed) new playback position is not in one of the ranges given in the seekable p235 attribute, then let it be the position in one of the ranges given in the seekable p235 attribute that is the nearest to the new playback position. If two positions both satisfy that constraint (i.e. the new playback position is exactly in the middle between two ranges in the seekable p235 attribute) then use the position that is closest to the current playback position p229 . If there are no ranges given in the seekable p235 attribute then set the seeking p234 IDL attribute to false and abort these steps. 9. Set the current playback position p229 to the given new playback position. 10. 234 If the media element p219 was potentially playing p231 immediately before it started seeking, but seeking caused its readyState p231 attribute to change to a value lower than HAVE_FUTURE_DATA p230 , then queue a task p490 to fire a simple event p496 named waiting p237 at the element. 11. If, when it reaches this step, the user agent has still not established whether or not the media data p219 for the new playback position is available, and, if it is, decoded enough data to play back that position, then queue a task p490 to fire a simple event p496 named seeking p237 at the element. 12. Wait until it has established whether or not the media data p219 for the new playback position is available, and, if it is, until it has decoded enough data to play back that position. 13. Await a stable state p490 . The synchronous section p490 consists of all the remaining steps of this algorithm. (Steps in the synchronous section p490 are marked with ?.) 14. ? Set the seeking p234 IDL attribute to false. 15. ? Queue a task p490 to fire a simple event p496 named seeked p237 at the element. The seekable attribute must return a new static normalized TimeRanges object p236 that represents the ranges of the media resource p219 , if any, that the user agent is able to seek to, at the time the attribute is evaluated. Note: If the user agent can seek to anywhere in the media resource p219 , e.g. because it a simple movie file and the user agent and the server support HTTP Range requests, then the attribute would return an object with one range, whose start is the time of the first frame (typically zero), and whose end is the same as the time of the first frame plus the duration p228 attribute's value (which would equal the time of the last frame). Note: The range might be continuously changing, e.g. if the user agent is buffering a sliding window on an infinite stream. This is the behavior seen with DVRs viewing live TV, for instance. Media resources p219 might be internally scripted or interactive. Thus, a media element p219 could play in a nonlinear fashion. If this happens, the user agent must act as if the algorithm for seeking p234 was used whenever the current playback position p229 changes in a discontinuous fashion (so that the relevant events fire). 4.8.9.10 User interface The controls attribute is a boolean attribute p34 . If present, it indicates that the author has not provided a scripted controller and would like the user agent to provide its own set of controls. If the attribute is present, or if scripting is disabled p487 for the media element p219 , then the user agent should expose a user interface to the user. This user interface should include features to begin playback, pause playback, seek to an arbitrary position in the content (if the content supports arbitrary seeking), change the volume, change the display of closed captions or embedded sign-language tracks, select different audio tracks or turn on audio descriptions, and show the media content in manners more suitable to the user (e.g. full-screen video or in an independent resizable window). Other controls may also be made available. Even when the attribute is absent, however, user agents may provide controls to affect playback of the media resource (e.g. play, pause, seeking, and volume controls), but such features should not interfere with the page's normal rendering. For example, such features could be exposed in the media element p219 's context menu. Where possible (specifically, for starting, stopping, pausing, and unpausing playback, for muting or changing the volume of the audio, and for seeking), user interface features exposed by the user agent must be implemented in terms of the DOM API described above, so that, e.g., all the same events fire. The controls IDL attribute must reflect p57 the content attribute of the same name. This box is non-normative. Implementation requirements are given below this box. media . volume p236 [ = value ] Returns the current playback volume, as a number in the range 0.0 to 1.0, where 0.0 is the quietest and 1.0 the loudest. Can be set, to change the volume. Throws an INDEX_SIZE_ERR p70 if the new value is not in the range 0.0 .. 1.0. media . muted p236 [ = value ] Returns true if audio is muted, overriding the volume p236 attribute, and false if the volume p236 attribute is being honored. Can be set, to change whether the audio is muted or not. 235 The volume attribute must return the playback volume of any audio portions of the media element p219 , in the range 0.0 (silent) to 1.0 (loudest). Initially, the volume must be 1.0, but user agents may remember the last set value across sessions, on a per-site basis or otherwise, so the volume may start at other values. On setting, if the new value is in the range 0.0 to 1.0 inclusive, the attribute must be set to the new value and the playback volume must be correspondingly adjusted as soon as possible after setting the attribute, with 0.0 being silent, and 1.0 being the loudest setting, values in between increasing in loudness. The range need not be linear. The loudest setting may be lower than the system's loudest possible setting; for example the user could have set a maximum volume. If the new value is outside the range 0.0 to 1.0 inclusive, then, on setting, an INDEX_SIZE_ERR p70 exception must be raised instead. The muted attribute must return true if the audio channels are muted and false otherwise. Initially, the audio channels should not be muted (false), but user agents may remember the last set value across sessions, on a persite basis or otherwise, so the muted state may start as muted (true). On setting, the attribute must be set to the new value; if the new value is true, audio playback for this media resource p219 must then be muted, and if false, audio playback must then be enabled. Whenever either the muted p236 or volume p236 attributes are changed, the user agent must queue a task p490 to fire a simple event p496 named volumechange p238 at the media element p219 . 4.8.9.11 Time ranges Objects implementing the TimeRanges p236 interface represent a list of ranges (periods) of time. interface TimeRanges { readonly attribute unsigned long length; float start(in unsigned long index); float end(in unsigned long index); }; This box is non-normative. Implementation requirements are given below this box. media . length p236 Returns the number of ranges in the object. time = media . start p236 (index) Returns the time for the start of the range with the given index. Throws an INDEX_SIZE_ERR p70 if the index is out of range. time = media . end p236 (index) Returns the time for the end of the range with the given index. Throws an INDEX_SIZE_ERR p70 if the index is out of range. The length IDL attribute must return the number of ranges represented by the object. The start(index) method must return the position of the start of the indexth range represented by the object, in seconds measured from the start of the timeline that the object covers. The end(index) method must return the position of the end of the indexth range represented by the object, in seconds measured from the start of the timeline that the object covers. These methods must raise INDEX_SIZE_ERR p70 exceptions if called with an index argument greater than or equal to the number of ranges represented by the object. When a TimeRanges p236 object is said to be a normalized TimeRanges object, the ranges it represents must obey the following criteria: • The start of a range must be greater than the end of all earlier ranges. • The start of a range must be less than the end of that same range. In other words, the ranges in such an object are ordered, don't overlap, aren't empty, and don't touch (adjacent ranges are folded into one bigger range). The timelines used by the objects returned by the buffered p228 , seekable p235 and played p232 IDL attributes of media elements p219 must be the same as that element's media resource p219 's timeline. 236 4.8.9.12 Event summary This section is non-normative. The following events fire on media elements p219 as part of the processing model described above: Event name Interface Dispatched when... Preconditions loadstart Event p31 The user agent begins looking for media data p219 , as part of the resource selection algorithm p223 . networkState p222 equals NETWORK_LOADING p222 progress Event p31 The user agent is fetching media data p219 . networkState p222 equals NETWORK_LOADING p222 The user agent is intentionally not currently fetching media data p219 , but does not have the entire media resource p219 downloaded. networkState p222 equals NETWORK_IDLE p222 p31 suspend Event abort Event p31 The user agent stops fetching the media data p219 before it is completely downloaded, but not due to an error. error p220 is an object with the code MEDIA_ERR_ABORTED p220 . networkState p222 equals either NETWORK_EMPTY p222 or NETWORK_IDLE p222 , depending on when the download was aborted. error Event p31 An error occurs while fetching the media data p219 . error p220 is an object with the code MEDIA_ERR_NETWORK p220 or higher. networkState p222 equals either NETWORK_EMPTY p222 or NETWORK_IDLE p222 , depending on when the download was aborted. emptied Event p31 A media element p219 whose networkState p222 networkState p222 is NETWORK_EMPTY p222 ; all the IDL was previously not in the NETWORK_EMPTY p222 attributes are in their initial states. state has just switched to that state (either because of a fatal error during load that's about to be reported, or because the load() p222 method was invoked while the resource selection algorithm p223 was already running). stalled Event p31 The user agent is trying to fetch media data p219 , but data is unexpectedly not forthcoming. networkState p222 is NETWORK_LOADING p222 . play Event p31 Playback has begun. Fired after the play() p232 method has returned. paused p231 is newly false. pause Event p31 Playback has been paused. Fired after the pause p233 method has returned. paused p231 is newly true. The user agent has just determined the duration and dimensions of the media resource p219 . readyState p231 is newly equal to HAVE_METADATA p229 or greater for the first time. loadedmetadata Event p31 loadeddata Event p31 The user agent can render the media data p219 readyState p231 newly increased to HAVE_CURRENT_DATA p230 or greater for the first time. at the current playback position p229 for the first time. waiting Event p31 Playback has stopped because the next frame is not available, but the user agent expects that frame to become available in due course. readyState p231 is newly equal to or less than HAVE_CURRENT_DATA p230 , and paused p231 is false. Either seeking p234 is true, or the current playback position p229 is not contained in any of the ranges in buffered p228 . It is possible for playback to stop for two other reasons without paused p231 being false, but those two reasons do not fire this event: maybe playback ended p231 , or playback stopped due to errors p232 . playing Event p31 Playback has started. readyState p231 is newly equal to or greater than HAVE_FUTURE_DATA p230 , paused p231 is false, seeking p234 is false, or the current playback position p229 is contained in one of the ranges in buffered p228 . canplay Event p31 The user agent can resume playback of the media data p219 , but estimates that if playback were to be started now, the media resource p219 could not be rendered at the current playback rate up to its end without having to stop for further buffering of content. readyState p231 newly increased to HAVE_FUTURE_DATA p230 or greater. canplaythrough Event p31 The user agent estimates that if playback readyState p231 is newly equal to HAVE_ENOUGH_DATA p230 . were to be started now, the media resource p219 could be rendered at the current playback rate all the way to its end without having to stop for further buffering. seeking Event p31 The seeking p234 IDL attribute changed to true and the seek operation is taking long enough that the user agent has time to fire the event. seeked Event p31 The seeking p234 IDL attribute changed to false. timeupdate Event p31 The current playback position p229 changed as part of normal playback or in an especially interesting way, for example discontinuously. 237 Event name Interface Dispatched when... Preconditions ended Event p31 Playback has stopped because the end of the currentTime p229 equals the end of the media resource p219 ; media resource p219 was reached. ended p232 is true. ratechange Event p31 Either the defaultPlaybackRate p232 or the playbackRate p232 attribute has just been updated. durationchange Event p31 Event p31 volumechange The duration p228 attribute has just been updated. Either the volume p236 attribute or the muted p236 attribute has changed. Fired after the relevant attribute's setter has returned. 4.8.9.13 Security and privacy considerations The main security and privacy implications of the video p213 and audio p216 elements come from the ability to embed media cross-origin. There are two directions that threats can flow: from hostile content to a victim page, and from a hostile page to victim content. If a victim page embeds hostile content, the threat is that the content might contain scripted code that attempts to interact with the Document p31 that embeds the content. To avoid this, user agents must ensure that there is no access from the content to the embedding page. In the case of media content that uses DOM concepts, the embedded content must be treated as if it was in its own unrelated top-level browsing context p439 . For instance, if an SVG animation was embedded in a video p213 element, the user agent would not give it access to the DOM of the outer page. From the perspective of scripts in the SVG resource, the SVG file would appear to be in a lone top-level browsing context with no parent. If a hostile page embeds victim content, the threat is that the embedding page could obtain information from the content that it would not otherwise have access to. The API does expose some information: the existence of the media, its type, its duration, its size, and the performance characteristics of its host. Such information is already potentially problematic, but in practice the same information can more or less be obtained using the img p186 element, and so it has been deemed acceptable. However, significantly more sensitive information could be obtained if the user agent further exposes metadata within the content such as subtitles or chapter titles. This version of the API does not expose such information. Future extensions to this API will likely reuse a mechanism such as CORS to check that the embedded content's site has opted in to exposing such information. [CORS] p700 An attacker could trick a user running within a corporate network into visiting a site that attempts to load a video from a previously leaked location on the corporation's intranet. If such a video included confidential plans for a new product, then being able to read the subtitles would present a confidentiality breach. 4.8.10 The canvas element Categories Flow content p91 . Phrasing content p91 . Embedded content p92 . Contexts in which this element may be used: Where embedded content p92 is expected. Content model: Transparent p93 . Content attributes: Global attributes p82 width p239 height p239 DOM interface: interface HTMLCanvasElement : HTMLElement { attribute unsigned long width; attribute unsigned long height; DOMString toDataURL(in optional DOMString type, in any... args); 238 object getContext(in DOMString contextId); }; The canvas p238 element provides scripts with a resolution-dependent bitmap canvas, which can be used for rendering graphs, game graphics, or other visual images on the fly. Authors should not use the canvas p238 element in a document when a more suitable element is available. For example, it is inappropriate to use a canvas p238 element to render a page heading: if the desired presentation of the heading is graphically intense, it should be marked up using appropriate elements (typically h1 p139 ) and then styled using CSS and supporting technologies such as XBL. When authors use the canvas p238 element, they must also provide content that, when presented to the user, conveys essentially the same function or purpose as the bitmap canvas. This content may be placed as content of the canvas p238 element. The contents of the canvas p238 element, if any, are the element's fallback content p92 . In interactive visual media, if scripting is enabled p487 for the canvas p238 element, and if support for canvas p238 elements has been enabled, the canvas p238 element represents p638 embedded content p92 consisting of a dynamically created image. In non-interactive, static, visual media, if the canvas p238 element has been previously painted on (e.g. if the page was viewed in an interactive visual medium and is now being printed, or if some script that ran during the page layout process painted on the element), then the canvas p238 element represents p638 embedded content p92 with the current image and size. Otherwise, the element represents its fallback content p92 instead. In non-visual media, and in visual media if scripting is disabled p487 for the canvas p238 element or if support for canvas p238 elements has been disabled, the canvas p238 element represents p638 its fallback content p92 instead. When a canvas p238 element represents p638 embedded content p92 , the user can still focus descendants of the canvas p238 element (in the fallback content p92 ). This allows authors to make an interactive canvas keyboardfocusable: authors should have a one-to-one mapping of interactive regions to focusable elements in the fallback content p92 . The canvas p238 element has two attributes to control the size of the coordinate space: width and height. These attributes, when specified, must have values that are valid non-negative integers p35 . The rules for parsing nonnegative integers p35 must be used to obtain their numeric values. If an attribute is missing, or if parsing its value returns an error, then the default value must be used instead. The width p239 attribute defaults to 300, and the height p239 attribute defaults to 150. The intrinsic dimensions of the canvas p238 element equal the size of the coordinate space, with the numbers interpreted in CSS pixels. However, the element can be sized arbitrarily by a style sheet. During rendering, the image is scaled to fit this layout size. The size of the coordinate space does not necessarily represent the size of the actual bitmap that the user agent will use internally or during rendering. On high-definition displays, for instance, the user agent may internally use a bitmap with two device pixels per unit in the coordinate space, so that the rendering remains at high quality throughout. When the canvas p238 element is created, and subsequently whenever the width p239 and height p239 attributes are set (whether to a new value or to the previous value), the bitmap and any associated contexts must be cleared back to their initial state and reinitialized with the newly specified coordinate space dimensions. When the canvas is initialized, its bitmap must be cleared to transparent black. The width and height IDL attributes must reflect p57 the respective content attributes of the same name. Only one square appears to be drawn in the following example: // canvas is a reference to a element var context = canvas.getContext('2d'); context.fillRect(0,0,50,50); canvas.setAttribute('width', '300'); // clears the canvas context.fillRect(0,100,50,50); canvas.width = canvas.width; // clears the canvas context.fillRect(100,0,50,50); // only this square remains To draw on the canvas, authors must first obtain a reference to a context using the getContext(contextId) method of the canvas p238 element. This box is non-normative. Implementation requirements are given below this box. 239 context = canvas . getContext p239 (contextId) Returns an object that exposes an API for drawing on the canvas. Returns null if the given context ID is not supported. This specification only defines one context, with the name "2d p241 ". If getContext() p239 is called with that exact string for its contextId argument, then the UA must return a reference to an object implementing CanvasRenderingContext2D p241 . Other specifications may define their own contexts, which would return different objects. Vendors may also define experimental contexts using the syntax vendorname-context, for example, moz-3d. When the UA is passed an empty string or a string specifying a context that it does not support, then it must return null. String comparisons must be case-sensitive p33 . This box is non-normative. Implementation requirements are given below this box. url = canvas . toDataURL p240 ( [ type, ... ]) Returns a data: URL for the image in the canvas. The first argument, if provided, controls the type of the image to be returned (e.g. PNG or JPEG). The default is image/png; that type is also used if the given type isn't supported. The other arguments are specific to the type, and control the way that the image is generated, as given in the table below. The toDataURL() method must, when called with no arguments, return a data: URL containing a representation of the image as a PNG file. [PNG] p702 If the canvas has no pixels (i.e. either its horizontal dimension or its vertical dimension is zero) then the method must return the string "data:,". (This is the shortest data: URL; it represents the empty string in a text/plain resource.) When the toDataURL(type) p240 method is called with one or more arguments, it must return a data: URL containing a representation of the image in the format given by type. The possible values are MIME types p26 with no parameters, for example image/png, image/jpeg, or even maybe image/svg+xml if the implementation actually keeps enough information to reliably render an SVG image from the canvas. For image types that do not support an alpha channel, the image must be composited onto a solid black background using the source-over operator, and the resulting image must be the one used to create the data: URL. Only support for image/png is required. User agents may support other types. If the user agent does not support the requested type, it must return the image using the PNG format. User agents must convert the provided type to ASCII lowercase p33 before establishing if they support that type and before creating the data: URL. Note: When trying to use types other than image/png, authors can check if the image was really returned in the requested format by checking to see if the returned string starts with one the exact strings "data:image/png," or "data:image/png;". If it does, the image is PNG, and thus the requested type was not supported. (The one exception to this is if the canvas has either no height or no width, in which case the result might simply be "data:,".) If the method is invoked with the first argument giving a type corresponding to one of the types given in the first column of the following table, and the user agent supports that type, then the subsequent arguments, if any, must be treated as described in the second cell of that row. Type Other arguments image/ The second argument, if it is a number in the range 0.0 to 1.0 inclusive, must be treated as the desired quality level. If it is not a jpeg number or is outside that range, the user agent must use its default value, as if the argument had been omitted. For the purposes of these rules, an argument is considered to be a number if it is converted to an IDL double value by the rules for handling arguments of type any in the Web IDL specification. [WEBIDL] p704 Other arguments must be ignored and must not cause the user agent to raise an exception. A future version of this specification will probably define other parameters to be passed to toDataURL() p240 to allow authors to more carefully control compression settings, image metadata, etc. 240 4.8.10.1 The 2D context When the getContext() p239 method of a canvas p238 element is invoked with 2d as the argument, a CanvasRenderingContext2D p241 object is returned. There is only one CanvasRenderingContext2D p241 object per canvas, so calling the getContext() p239 method with the 2d p241 argument a second time must return the same object. The 2D context represents a flat Cartesian surface whose origin (0,0) is at the top left corner, with the coordinate space having x values increasing when going right, and y values increasing when going down. interface CanvasRenderingContext2D { // back-reference to the canvas readonly attribute HTMLCanvasElement canvas; // state void save(); // push state on state stack void restore(); // pop state stack and restore state // transformations (default transform is the identity matrix) void scale(in float x, in float y); void rotate(in float angle); void translate(in float x, in float y); void transform(in float m11, in float m12, in float m21, in float m22, in float dx, in float dy); void setTransform(in float m11, in float m12, in float m21, in float m22, in float dx, in float dy); // compositing attribute float globalAlpha; // (default 1.0) attribute DOMString globalCompositeOperation; // (default source-over) // colors and styles attribute any strokeStyle; // (default black) attribute any fillStyle; // (default black) CanvasGradient createLinearGradient(in float x0, in float y0, in float x1, in float y1); CanvasGradient createRadialGradient(in float x0, in float y0, in float r0, in float x1, in float y1, in float r1); CanvasPattern createPattern(in HTMLImageElement image, in DOMString repetition); CanvasPattern createPattern(in HTMLCanvasElement image, in DOMString repetition); CanvasPattern createPattern(in HTMLVideoElement image, in DOMString repetition); // line caps/joins attribute attribute attribute attribute float lineWidth; // (default 1) DOMString lineCap; // "butt", "round", "square" (default "butt") DOMString lineJoin; // "round", "bevel", "miter" (default "miter") float miterLimit; // (default 10) // shadows attribute attribute attribute attribute float shadowOffsetX; // (default 0) float shadowOffsetY; // (default 0) float shadowBlur; // (default 0) DOMString shadowColor; // (default transparent black) // rects void clearRect(in float x, in float y, in float w, in float h); void fillRect(in float x, in float y, in float w, in float h); void strokeRect(in float x, in float y, in float w, in float h); // path API void beginPath(); void closePath(); void moveTo(in float x, in float y); void lineTo(in float x, in float y); void quadraticCurveTo(in float cpx, in float cpy, in float x, in float y); void bezierCurveTo(in float cp1x, in float cp1y, in float cp2x, in float cp2y, in float x, in float y); 241 void arcTo(in float x1, in float y1, in float x2, in float y2, in float radius); void rect(in float x, in float y, in float w, in float h); void arc(in float x, in float y, in float radius, in float startAngle, in float endAngle, in boolean anticlockwise); void fill(); void stroke(); void clip(); boolean isPointInPath(in float x, in float y); // focus management boolean drawFocusRing(in Element element, in float xCaret, in float yCaret, in optional boolean canDrawCustom); // text attribute DOMString font; // (default 10px sans-serif) attribute DOMString textAlign; // "start", "end", "left", "right", "center" (default: "start") attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic", "ideographic", "bottom" (default: "alphabetic") void fillText(in DOMString text, in float x, in float y, in optional float maxWidth); void strokeText(in DOMString text, in float x, in float y, in optional float maxWidth); TextMetrics measureText(in DOMString text); // drawing images void drawImage(in HTMLImageElement image, in float dx, in float dy, in optional float dw, in float dh); void drawImage(in HTMLImageElement image, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh); void drawImage(in HTMLCanvasElement image, in float dx, in float dy, in optional float dw, in float dh); void drawImage(in HTMLCanvasElement image, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh); void drawImage(in HTMLVideoElement image, in float dx, in float dy, in optional float dw, in float dh); void drawImage(in HTMLVideoElement image, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh); // pixel manipulation ImageData createImageData(in float sw, in float sh); ImageData createImageData(in ImageData imagedata); ImageData getImageData(in float sx, in float sy, in float sw, in float sh); void putImageData(in ImageData imagedata, in float dx, in float dy, in optional float dirtyX, in float dirtyY, in float dirtyWidth, in float dirtyHeight); }; interface CanvasGradient { // opaque object void addColorStop(in float offset, in DOMString color); }; interface CanvasPattern { // opaque object }; interface TextMetrics { readonly attribute float width; }; interface ImageData { readonly attribute unsigned long width; readonly attribute unsigned long height; readonly attribute CanvasPixelArray data; }; interface CanvasPixelArray { readonly attribute unsigned long length; getter octet (in unsigned long index); setter void (in unsigned long index, in octet value); }; 242 This box is non-normative. Implementation requirements are given below this box. context . canvas p243 Returns the canvas p238 element. The canvas attribute must return the canvas p238 element that the context paints on. Except where otherwise specified, for the 2D context interface, any method call with a numeric argument whose value is infinite or a NaN value must be ignored. Whenever the CSS value currentColor is used as a color in this API, the "computed value of the 'color' property" for the purposes of determining the computed value of the currentColor keyword is the computed value of the 'color' property on the element in question at the time that the color is specified (e.g. when the appropriate attribute is set, or when the method is called; not when the color is rendered or otherwise used). If the computed value of the 'color' property is undefined for a particular case (e.g. because the element is not in a Document p27 ), then the "computed value of the 'color' property" for the purposes of determining the computed value of the currentColor keyword is fully opaque black. [CSSCOLOR] p700 4.8.10.1.1 The canvas state Each context maintains a stack of drawing states. Drawing states consist of: • • • The current transformation matrix p243 . The current clipping region p253 . The current values of the following attributes: strokeStyle p245 , fillStyle p245 , globalAlpha p244 , lineWidth p248 , lineCap p248 , lineJoin p249 , miterLimit p249 , shadowOffsetX p250 , shadowOffsetY p250 , shadowBlur p250 , shadowColor p249 , globalCompositeOperation p244 , font p255 , textAlign p256 , textBaseline p256 . Note: The current path and the current bitmap are not part of the drawing state. The current path is persistent, and can only be reset using the beginPath() p252 method. The current bitmap is a property of the canvas, not the context. This box is non-normative. Implementation requirements are given below this box. context . save p243 () Pushes the current state onto the stack. context . restore p243 () Pops the top state on the stack, restoring the context to that state. The save() method must push a copy of the current drawing state onto the drawing state stack. The restore() method must pop the top entry in the drawing state stack, and reset the drawing state it describes. If there is no saved state, the method must do nothing. 4.8.10.1.2 Transformations The transformation matrix is applied to coordinates when creating shapes and paths. When the context is created, the transformation matrix must initially be the identity transform. It may then be adjusted using the transformation methods. The transformations must be performed in reverse order. For instance, if a scale transformation that doubles the width is applied, followed by a rotation transformation that rotates drawing operations by a quarter turn, and a rectangle twice as wide as it is tall is then drawn on the canvas, the actual result will be a square. This box is non-normative. Implementation requirements are given below this box. context . scale p244 (x, y) Changes the transformation matrix to apply a scaling transformation with the given characteristics. context . rotate p244 (angle) Changes the transformation matrix to apply a rotation transformation with the given characteristics. The angle is in radians. 243 context . translate p244 (x, y) Changes the transformation matrix to apply a translation transformation with the given characteristics. context . transform p244 (m11, m12, m21, m22, dx, dy) Changes the transformation matrix to apply the matrix given by the arguments as described below. context . setTransform p244 (m11, m12, m21, m22, dx, dy) Changes the transformation matrix to the matrix given by the arguments as described below. The scale(x, y) method must add the scaling transformation described by the arguments to the transformation matrix. The x argument represents the scale factor in the horizontal direction and the y argument represents the scale factor in the vertical direction. The factors are multiples. The rotate(angle) method must add the rotation transformation described by the argument to the transformation matrix. The angle argument represents a clockwise rotation angle expressed in radians. The translate(x, y) method must add the translation transformation described by the arguments to the transformation matrix. The x argument represents the translation distance in the horizontal direction and the y argument represents the translation distance in the vertical direction. The arguments are in coordinate space units. The transform(m11, m12, m21, m22, dx, dy) method must multiply the current transformation matrix with the matrix described by: m11 m21 dx m12 m22 dy 0 0 1 The setTransform(m11, m12, m21, m22, dx, dy) method must reset the current transform to the identity matrix, and then invoke the transform p244 (m11, m12, m21, m22, dx, dy) method with the same arguments. 4.8.10.1.3 Compositing This box is non-normative. Implementation requirements are given below this box. context . globalAlpha p244 [ = value ] Returns the current alpha value applied to rendering operations. Can be set, to change the alpha value. Values outside of the range 0.0 .. 1.0 are ignored. context . globalCompositeOperation p244 [ = value ] Returns the current composition operation, from the list below. Can be set, to change the composition operation. Unknown values are ignored. All drawing operations are affected by the global compositing attributes, globalAlpha p244 and globalCompositeOperation p244 . The globalAlpha attribute gives an alpha value that is applied to shapes and images before they are composited onto the canvas. The value must be in the range from 0.0 (fully transparent) to 1.0 (no additional transparency). If an attempt is made to set the attribute to a value outside this range, including Infinity and Not-a-Number (NaN) values, the attribute must retain its previous value. When the context is created, the globalAlpha p244 attribute must initially have the value 1.0. The globalCompositeOperation attribute sets how shapes and images are drawn onto the existing bitmap, once they have had globalAlpha p244 and the current transformation matrix applied. It must be set to a value from the following list. In the descriptions below, the source image, A, is the shape or image being rendered, and the destination image, B, is the current state of the bitmap. source-atop A atop B. Display the source image wherever both images are opaque. Display the destination image wherever the destination image is opaque but the source image is transparent. Display transparency elsewhere. source-in A in B. Display the source image wherever both the source image and destination image are opaque. Display transparency elsewhere. 244 source-out A out B. Display the source image wherever the source image is opaque and the destination image is transparent. Display transparency elsewhere. source-over (default) A over B. Display the source image wherever the source image is opaque. Display the destination image elsewhere. destination-atop B atop A. Same as source-atop p244 but using the destination image instead of the source image and vice versa. destination-in B in A. Same as source-in p244 but using the destination image instead of the source image and vice versa. destination-out B out A. Same as source-out p245 but using the destination image instead of the source image and vice versa. destination-over B over A. Same as source-over p245 but using the destination image instead of the source image and vice versa. lighter A plus B. Display the sum of the source image and destination image, with color values approaching 1 as a limit. copy A (B is ignored). Display the source image instead of the destination image. xor A xor B. Exclusive OR of the source image and destination image. vendorName-operationName Vendor-specific extensions to the list of composition operators should use this syntax. These values are all case-sensitive — they must be used exactly as shown. User agents must not recognize values that are not a case-sensitive p33 match for one of the values given above. The operators in the above list must be treated as described by the Porter-Duff operator given at the start of their description (e.g. A over B). [PORTERDUFF] p702 On setting, if the user agent does not recognize the specified value, it must be ignored, leaving the value of globalCompositeOperation p244 unaffected. When the context is created, the globalCompositeOperation p244 attribute must initially have the value sourceover. 4.8.10.1.4 Colors and styles This box is non-normative. Implementation requirements are given below this box. context . strokeStyle p245 [ = value ] Returns the current style used for stroking shapes. Can be set, to change the stroke style. The style can be either a string containing a CSS color, or a CanvasGradient p242 or CanvasPattern p242 object. Invalid values are ignored. context . fillStyle p245 [ = value ] Returns the current style used for filling shapes. Can be set, to change the fill style. The style can be either a string containing a CSS color, or a CanvasGradient p242 or CanvasPattern p242 object. Invalid values are ignored. The strokeStyle attribute represents the color or style to use for the lines around shapes, and the fillStyle attribute represents the color or style to use inside the shapes. Both attributes can be either strings, CanvasGradient p242 s, or CanvasPattern p242 s. On setting, strings must be parsed as CSS values and the color assigned, and CanvasGradient p242 and CanvasPattern p242 objects 245 must be assigned themselves. [CSSCOLOR] p700 If the value is a string but is not a valid color, or is neither a string, a CanvasGradient p242 , nor a CanvasPattern p242 , then it must be ignored, and the attribute must retain its previous value. When set to a CanvasPattern p242 or CanvasGradient p242 object, the assignment is live p27 , meaning that changes made to the object after the assignment do affect subsequent stroking or filling of shapes. On getting, if the value is a color, then the serialization of the color p246 must be returned. Otherwise, if it is not a color but a CanvasGradient p242 or CanvasPattern p242 , then the respective object must be returned. (Such objects are opaque and therefore only useful for assigning to other attributes or for comparison to other gradients or patterns.) The serialization of a color for a color value is a string, computed as follows: if it has alpha equal to 1.0, then the string is a lowercase six-digit hex value, prefixed with a "#" character (U+0023 NUMBER SIGN), with the first two digits representing the red component, the next two digits representing the green component, and the last two digits representing the blue component, the digits being in the range 0-9 a-f (U+0030 to U+0039 and U+0061 to U+0066). Otherwise, the color value has alpha less than 1.0, and the string is the color value in the CSS rgba() functional-notation format: the literal string rgba (U+0072 U+0067 U+0062 U+0061) followed by a U+0028 LEFT PARENTHESIS, a base-ten integer in the range 0-255 representing the red component (using digits 0-9, U+0030 to U+0039, in the shortest form possible), a literal U+002C COMMA and U+0020 SPACE, an integer for the green component, a comma and a space, an integer for the blue component, another comma and space, a U+0030 DIGIT ZERO, a U+002E FULL STOP (representing the decimal point), one or more digits in the range 0-9 (U+0030 to U+0039) representing the fractional part of the alpha value, and finally a U+0029 RIGHT PARENTHESIS. When the context is created, the strokeStyle p245 and fillStyle p245 attributes must initially have the string value #000000. There are two types of gradients, linear gradients and radial gradients, both represented by objects implementing the opaque CanvasGradient p242 interface. Once a gradient has been created (see below), stops are placed along it to define how the colors are distributed along the gradient. The color of the gradient at each stop is the color specified for that stop. Between each such stop, the colors and the alpha component must be linearly interpolated over the RGBA space without premultiplying the alpha value to find the color to use at that offset. Before the first stop, the color must be the color of the first stop. After the last stop, the color must be the color of the last stop. When there are no stops, the gradient is transparent black. This box is non-normative. Implementation requirements are given below this box. gradient . addColorStop p246 (offset, color) Adds a color stop with the given color to the gradient at the given offset. 0.0 is the offset at one end of the gradient, 1.0 is the offset at the other end. Throws an INDEX_SIZE_ERR p70 exception if the offset is out of range. Throws a SYNTAX_ERR p70 exception if the color cannot be parsed. gradient = context . createLinearGradient p246 (x0, y0, x1, y1) Returns a CanvasGradient p242 object that represents a linear gradient that paints along the line given by the coordinates represented by the arguments. If any of the arguments are not finite numbers, throws a NOT_SUPPORTED_ERR p70 exception. gradient = context . createRadialGradient p247 (x0, y0, r0, x1, y1, r1) Returns a CanvasGradient p242 object that represents a radial gradient that paints along the cone given by the circles represented by the arguments. If any of the arguments are not finite numbers, throws a NOT_SUPPORTED_ERR p70 exception. If either of the radii are negative, throws an INDEX_SIZE_ERR p70 exception. The addColorStop(offset, color) method on the CanvasGradient p242 interface adds a new stop to a gradient. If the offset is less than 0, greater than 1, infinite, or NaN, then an INDEX_SIZE_ERR p70 exception must be raised. If the color cannot be parsed as a CSS color, then a SYNTAX_ERR p70 exception must be raised. Otherwise, the gradient must have a new stop placed, at offset offset relative to the whole gradient, and with the color obtained by parsing color as a CSS value. If multiple stops are added at the same offset on a gradient, they must be placed in the order added, with the first one closest to the start of the gradient, and each subsequent one infinitesimally further along towards the end point (in effect causing all but the first and last stop added at each point to be ignored). The createLinearGradient(x0, y0, x1, y1) method takes four arguments that represent the start point (x0, y0) and end point (x1, y1) of the gradient. If any of the arguments to createLinearGradient() p246 are infinite or 246 NaN, the method must raise a NOT_SUPPORTED_ERR p70 exception. Otherwise, the method must return a linear CanvasGradient p242 initialized with the specified line. Linear gradients must be rendered such that all points on a line perpendicular to the line that crosses the start and end points have the color at the point where those two lines cross (with the colors coming from the interpolation and extrapolation p246 described above). The points in the linear gradient must be transformed as described by the current transformation matrix p243 when rendering. If x0 = x1 and y0 = y1, then the linear gradient must paint nothing. The createRadialGradient(x0, y0, r0, x1, y1, r1) method takes six arguments, the first three representing the start circle with origin (x0, y0) and radius r0, and the last three representing the end circle with origin (x1, y1) and radius r1. The values are in coordinate space units. If any of the arguments are infinite or NaN, a NOT_SUPPORTED_ERR p70 exception must be raised. If either of r0 or r1 are negative, an INDEX_SIZE_ERR p70 exception must be raised. Otherwise, the method must return a radial CanvasGradient p242 initialized with the two specified circles. Radial gradients must be rendered by following these steps: 1. If x0 = x1 and y0 = y1 and r0 = r1, then the radial gradient must paint nothing. Abort these steps. 2. Let x(ω) = (x1-x0)ω + x0 Let y(ω) = (y1-y0)ω + y0 Let r(ω) = (r1-r0)ω + r0 Let the color at ω be the color at that position on the gradient (with the colors coming from the interpolation and extrapolation p246 described above). 3. For all values of ω where r(ω) > 0, starting with the value of ω nearest to positive infinity and ending with the value of ω nearest to negative infinity, draw the circumference of the circle with radius r(ω) at position (x(ω), y(ω)), with the color at ω, but only painting on the parts of the canvas that have not yet been painted on by earlier circles in this step for this rendering of the gradient. Note: This effectively creates a cone, touched by the two circles defined in the creation of the gradient, with the part of the cone before the start circle (0.0) using the color of the first offset, the part of the cone after the end circle (1.0) using the color of the last offset, and areas outside the cone untouched by the gradient (transparent black). The points in the radial gradient must be transformed as described by the current transformation matrix p243 when rendering. Gradients must be painted only where the relevant stroking or filling effects requires that they be drawn. Patterns are represented by objects implementing the opaque CanvasPattern p242 interface. This box is non-normative. Implementation requirements are given below this box. pattern = context . createPattern p247 (image, repetition) Returns a CanvasPattern p242 object that uses the given image and repeats in the direction(s) given by the repetition argument. The allowed values for repetition are repeat (both directions), repeat-x (horizontal only), repeat-y (vertical only), and no-repeat (neither). If the repetition argument is empty or null, the value repeat is used. If the first argument isn't an img p186 , canvas p238 , or video p213 element, throws a TYPE_MISMATCH_ERR p70 exception. If the image has no image data, throws an INVALID_STATE_ERR p70 exception. If the second argument isn't one of the allowed values, throws a SYNTAX_ERR p70 exception. If the image isn't yet fully decoded, then the method returns null. To create objects of this type, the createPattern(image, repetition) method is used. The first argument gives the image to use as the pattern (either an HTMLImageElement p186 , HTMLCanvasElement p238 , or HTMLVideoElement p214 object). Modifying this image after calling the createPattern() p247 method must not affect the pattern. The second argument must be a string with one of the following values: repeat, repeat-x, repeat-y, no-repeat. If the empty string or null is specified, repeat must be assumed. If an unrecognized value is given, then the user agent must raise a SYNTAX_ERR p70 exception. User agents must recognize the four values described above exactly (e.g. they must not do case folding). The method must return a CanvasPattern p242 object suitably initialized. 247 The image argument is an instance of either HTMLImageElement p186 , HTMLCanvasElement p238 , or HTMLVideoElement p214 . If the image is null, the implementation must raise a TYPE_MISMATCH_ERR p70 exception. If the image argument is an HTMLImageElement p186 object whose complete p189 attribute is false, or if the image argument is an HTMLVideoElement p214 object whose readyState p231 attribute is either HAVE_NOTHING p229 or HAVE_METADATA p229 , then the implementation must return null. If the image argument is an HTMLCanvasElement p238 object with either a horizontal dimension or a vertical dimension equal to zero, then the implementation must raise an INVALID_STATE_ERR p70 exception. Patterns must be painted so that the top left of the first image is anchored at the origin of the coordinate space, and images are then repeated horizontally to the left and right (if the repeat-x string was specified) or vertically up and down (if the repeat-y string was specified) or in all four directions all over the canvas (if the repeat string was specified). The images are not scaled by this process; one CSS pixel of the image must be painted on one coordinate space unit. Of course, patterns must actually be painted only where the stroking or filling effect requires that they be drawn, and are affected by the current transformation matrix. When the createPattern() p247 method is passed an animated image as its image argument, the user agent must use the poster frame of the animation, or, if there is no poster frame, the first frame of the animation. When the image argument is an HTMLVideoElement p214 , then the frame at the current playback position p229 must be used as the source image, and the source image's dimensions must be the intrinsic width p215 and intrinsic height p215 of the media resource p219 (i.e. after any aspect-ratio correction has been applied). 4.8.10.1.5 Line styles This box is non-normative. Implementation requirements are given below this box. context . lineWidth p248 [ = value ] Returns the current line width. Can be set, to change the line width. Values that are not finite values greater than zero are ignored. context . lineCap p248 [ = value ] Returns the current line cap style. Can be set, to change the line cap style. The possible line cap styles are butt, round, and square. Other values are ignored. context . lineJoin p249 [ = value ] Returns the current line join style. Can be set, to change the line join style. The possible line join styles are bevel, round, and miter. Other values are ignored. context . miterLimit p249 [ = value ] Returns the current miter limit ratio. Can be set, to change the miter limit ratio. Values that are not finite values greater than zero are ignored. The lineWidth attribute gives the width of lines, in coordinate space units. On getting, it must return the current value. On setting, zero, negative, infinite, and NaN values must be ignored, leaving the value unchanged; other values must change the current value to the new value. When the context is created, the lineWidth p248 attribute must initially have the value 1.0. The lineCap attribute defines the type of endings that UAs will place on the end of lines. The three valid values are butt, round, and square. The butt value means that the end of each line has a flat edge perpendicular to the direction of the line (and that no additional line cap is added). The round value means that a semi-circle with the diameter equal to the width of the line must then be added on to the end of the line. The square value means that a rectangle with the length of the line width and the width of half the line width, placed flat against the edge perpendicular to the direction of the line, must be added at the end of each line. On getting, it must return the current value. On setting, if the new value is one of the literal strings butt, round, and square, then the current value must be changed to the new value; other values must ignored, leaving the value unchanged. When the context is created, the lineCap p248 attribute must initially have the value butt. 248 The lineJoin attribute defines the type of corners that UAs will place where two lines meet. The three valid values are bevel, round, and miter. On getting, it must return the current value. On setting, if the new value is one of the literal strings bevel, round, and miter, then the current value must be changed to the new value; other values must be ignored, leaving the value unchanged. When the context is created, the lineJoin p249 attribute must initially have the value miter. A join exists at any point in a subpath shared by two consecutive lines. When a subpath is closed, then a join also exists at its first point (equivalent to its last point) connecting the first and last lines in the subpath. In addition to the point where the join occurs, two additional points are relevant to each join, one for each line: the two corners found half the line width away from the join point, one perpendicular to each line, each on the side furthest from the other line. A filled triangle connecting these two opposite corners with a straight line, with the third point of the triangle being the join point, must be rendered at all joins. The lineJoin p249 attribute controls whether anything else is rendered. The three aforementioned values have the following meanings: The bevel value means that this is all that is rendered at joins. The round value means that a filled arc connecting the two aforementioned corners of the join, abutting (and not overlapping) the aforementioned triangle, with the diameter equal to the line width and the origin at the point of the join, must be rendered at joins. The miter value means that a second filled triangle must (if it can given the miter length) be rendered at the join, with one line being the line between the two aforementioned corners, abutting the first triangle, and the other two being continuations of the outside edges of the two joining lines, as long as required to intersect without going over the miter length. The miter length is the distance from the point where the join occurs to the intersection of the line edges on the outside of the join. The miter limit ratio is the maximum allowed ratio of the miter length to half the line width. If the miter length would cause the miter limit ratio to be exceeded, this second triangle must not be rendered. The miter limit ratio can be explicitly set using the miterLimit attribute. On getting, it must return the current value. On setting, zero, negative, infinite, and NaN values must be ignored, leaving the value unchanged; other values must change the current value to the new value. When the context is created, the miterLimit p249 attribute must initially have the value 10.0. 4.8.10.1.6 Shadows All drawing operations are affected by the four global shadow attributes. This box is non-normative. Implementation requirements are given below this box. context . shadowColor p249 [ = value ] Returns the current shadow color. Can be set, to change the shadow color. Values that cannot be parsed as CSS colors are ignored. context . shadowOffsetX p250 [ = value ] context . shadowOffsetY p250 [ = value ] Returns the current shadow offset. Can be set, to change the shadow offset. Values that are not finite numbers are ignored. context . shadowBlur p250 [ = value ] Returns the current level of blur applied to shadows. Can be set, to change the blur level. Values that are not finite numbers greater than or equal to zero are ignored. The shadowColor attribute sets the color of the shadow. When the context is created, the shadowColor p249 attribute initially must be fully-transparent black. On getting, the serialization of the color p246 must be returned. On setting, the new value must be parsed as a CSS value and the color assigned. If the value is not a valid color, then it must be ignored, and the attribute must retain its previous value. [CSSCOLOR] p700 249 The shadowOffsetX and shadowOffsetY attributes specify the distance that the shadow will be offset in the positive horizontal and positive vertical distance respectively. Their values are in coordinate space units. They are not affected by the current transformation matrix. When the context is created, the shadow offset attributes must initially have the value 0. On getting, they must return their current value. On setting, the attribute being set must be set to the new value, except if the value is infinite or NaN, in which case the new value must be ignored. The shadowBlur attribute specifies the size of the blurring effect. (The units do not map to coordinate space units, and are not affected by the current transformation matrix.) When the context is created, the shadowBlur p250 attribute must initially have the value 0. On getting, the attribute must return its current value. On setting the attribute must be set to the new value, except if the value is negative, infinite or NaN, in which case the new value must be ignored. Shadows are only drawn if the opacity component of the alpha component of the color of shadowColor p249 is non-zero and either the shadowBlur p250 is non-zero, or the shadowOffsetX p250 is non-zero, or the shadowOffsetY p250 is non-zero. When shadows are drawn p250 , they must be rendered as follows: 1. Let A be an infinite transparent black bitmap on which the source image for which a shadow is being created has been rendered. 2. Let B be an infinite transparent black bitmap, with a coordinate space and an origin identical to A. 3. Copy the alpha channel of A to B, offset by shadowOffsetX p250 in the positive x direction, and shadowOffsetY p250 in the positive y direction. 4. If shadowBlur p250 is greater than 0: 1. If shadowBlur p250 is less than 8, let σ be half the value of shadowBlur p250 ; otherwise, let σ be the square root of multiplying the value of shadowBlur p250 by 2. 2. Perform a 2D Gaussian Blur on B, using σ as the standard deviation. User agents may limit values of σ to an implementation-specific maximum value to avoid exceeding hardware limitations during the Gaussian blur operation. 5. Set the red, green, and blue components of every pixel in B to the red, green, and blue components (respectively) of the color of shadowColor p249 . 6. Multiply the alpha component of every pixel in B by the alpha component of the color of shadowColor p249 . 7. The shadow is in the bitmap B, and is rendered as part of the drawing model described below. If the current composition operation is copy p245 , shadows effectively won't render (since the shape will overwrite the shadow). 4.8.10.1.7 Simple shapes (rectangles) There are three methods that immediately draw rectangles to the bitmap. They each take four arguments; the first two give the x and y coordinates of the top left of the rectangle, and the second two give the width w and height h of the rectangle, respectively. The current transformation matrix p243 must be applied to the following four coordinates, which form the path that must then be closed to get the specified rectangle: (x, y), (x+w, y), (x+w, y+h), (x, y+h). Shapes are painted without affecting the current path, and are subject to the clipping region p253 , and, with the exception of clearRect() p251 , also shadow effects p249 , global alpha p244 , and global composition operators p244 . This box is non-normative. Implementation requirements are given below this box. context . clearRect p251 (x, y, w, h) Clears all pixels on the canvas in the given rectangle to transparent black. context . fillRect p251 (x, y, w, h) Paints the given rectangle onto the canvas, using the current fill style. 250 context . strokeRect p251 (x, y, w, h) Paints the box that outlines the given rectangle onto the canvas, using the current stroke style. The clearRect(x, y, w, h) method must clear the pixels in the specified rectangle that also intersect the current clipping region to a fully transparent black, erasing any previous image. If either height or width are zero, this method has no effect. The fillRect(x, y, w, h) method must paint the specified rectangular area using the fillStyle p245 . If either height or width are zero, this method has no effect. The strokeRect(x, y, w, h) method must stroke the specified rectangle's path using the strokeStyle p245 , lineWidth p248 , lineJoin p249 , and (if appropriate) miterLimit p249 attributes. If both height and width are zero, this method has no effect, since there is no path to stroke (it's a point). If only one of the two is zero, then the method will draw a line instead (the path for the outline is just a straight line along the non-zero dimension). 4.8.10.1.8 Complex shapes (paths) The context always has a current path. There is only one current path, it is not part of the drawing state p243 . A path has a list of zero or more subpaths. Each subpath consists of a list of one or more points, connected by straight or curved lines, and a flag indicating whether the subpath is closed or not. A closed subpath is one where the last point of the subpath is connected to the first point of the subpath by a straight line. Subpaths with fewer than two points are ignored when painting the path. This box is non-normative. Implementation requirements are given below this box. context . beginPath p252 () Resets the current path. context . moveTo p252 (x, y) Creates a new subpath with the given point. context . closePath p252 () Marks the current subpath as closed, and starts a new subpath with a point the same as the start and end of the newly closed subpath. context . lineTo p252 (x, y) Adds the given point to the current subpath, connected to the previous one by a straight line. context . quadraticCurveTo p252 (cpx, cpy, x, y) Adds the given point to the current path, connected to the previous one by a quadratic Bézier curve with the given control point. context . bezierCurveTo p252 (cp1x, cp1y, cp2x, cp2y, x, y) Adds the given point to the current path, connected to the previous one by a cubic Bézier curve with the given control points. context . arcTo p252 (x1, y1, x2, y2, radius) Adds a point to the current path, connected to the previous one by a straight line, then adds a second point to the current path, connected to the previous one by an arc whose properties are described by the arguments. Throws an INDEX_SIZE_ERR p70 exception if the given radius is negative. context . arc p252 (x, y, radius, startAngle, endAngle, anticlockwise) Adds points to the subpath such that the arc described by the circumference of the circle described by the arguments, starting at the given start angle and ending at the given end angle, going in the given direction, is added to the path, connected to the previous point by a straight line. Throws an INDEX_SIZE_ERR p70 exception if the given radius is negative. context . rect p253 (x, y, w, h) Adds a new closed subpath to the path, representing the given rectangle. context . fill p253 () Fills the subpaths with the current fill style. 251 context . stroke p253 () Strokes the subpaths with the current stroke style. context . clip p253 () Further constrains the clipping region to the given path. context . isPointInPath p253 (x, y) Returns true if the given point is in the current path. Initially, the context's path must have zero subpaths. The points and lines added to the path by these methods must be transformed according to the current transformation matrix p243 as they are added. The beginPath() method must empty the list of subpaths so that the context once again has zero subpaths. The moveTo(x, y) method must create a new subpath with the specified point as its first (and only) point. When the user agent is to ensure there is a subpath for a coordinate (x, y), the user agent must check to see if the context has any subpaths, and if it does not, then the user agent must create a new subpath with the point (x, y) as its first (and only) point, as if the moveTo() p252 method had been called. The closePath() method must do nothing if the context has no subpaths. Otherwise, it must mark the last subpath as closed, create a new subpath whose first point is the same as the previous subpath's first point, and finally add this new subpath to the path. Note: If the last subpath had more than one point in its list of points, then this is equivalent to adding a straight line connecting the last point back to the first point, thus "closing" the shape, and then repeating the last (possibly implied) moveTo() p252 call. New points and the lines connecting them are added to subpaths using the methods described below. In all cases, the methods only modify the last subpath in the context's paths. The lineTo(x, y) method must ensure there is a subpath p252 for (x, y) if the context has no subpaths. Otherwise, it must connect the last point in the subpath to the given point (x, y) using a straight line, and must then add the given point (x, y) to the subpath. The quadraticCurveTo(cpx, cpy, x, y) method must ensure there is a subpath p252 for (cpx, cpy), and then must connect the last point in the subpath to the given point (x, y) using a quadratic Bézier curve with control point (cpx, cpy), and must then add the given point (x, y) to the subpath. [BEZIER] p700 The bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) method must ensure there is a subpath p252 for (cp1x, cp1y), and then must connect the last point in the subpath to the given point (x, y) using a cubic Bézier curve with control points (cp1x, cp1y) and (cp2x, cp2y). Then, it must add the point (x, y) to the subpath. [BEZIER] p700 The arcTo(x1, y1, x2, y2, radius) method must first ensure there is a subpath p252 for (x1, y1). Then, the behavior depends on the arguments and the last point in the subpath, as described below. Negative values for radius must cause the implementation to raise an INDEX_SIZE_ERR p70 exception. Let the point (x0, y0) be the last point in the subpath. If the point (x0, y0) is equal to the point (x1, y1), or if the point (x1, y1) is equal to the point (x2, y2), or if the radius radius is zero, then the method must add the point (x1, y1) to the subpath, and connect that point to the previous point (x0, y0) by a straight line. Otherwise, if the points (x0, y0), (x1, y1), and (x2, y2) all lie on a single straight line, then the method must add the point (x1, y1) to the subpath, and connect that point to the previous point (x0, y0) by a straight line. Otherwise, let The Arc be the shortest arc given by circumference of the circle that has radius radius, and that has one point tangent to the half-infinite line that crosses the point (x0, y0) and ends at the point (x1, y1), and that has a different point tangent to the half-infinite line that ends at the point (x1, y1) and crosses the point (x2, y2). The points at which this circle touches these two lines are called the start and end tangent points respectively. The method must connect the point (x0, y0) to the start tangent point by a straight line, adding the start tangent point to the subpath, and then must connect the start tangent point to the end tangent point by The Arc, adding the end tangent point to the subpath. The arc(x, y, radius, startAngle, endAngle, anticlockwise) method draws an arc. If the context has any subpaths, then the method must add a straight line from the last point in the subpath to the start point of the arc. 252 In any case, it must draw the arc between the start point of the arc and the end point of the arc, and add the start and end points of the arc to the subpath. The arc and its start and end points are defined as follows: Consider a circle that has its origin at (x, y) and that has radius radius. The points at startAngle and endAngle along this circle's circumference, measured in radians clockwise from the positive x-axis, are the start and end points respectively. If the anticlockwise argument is false and endAngle-startAngle is equal to or greater than 2π, or, if the anticlockwise argument is true and startAngle-endAngle is equal to or greater than 2π, then the arc is the whole circumference of this circle. Otherwise, the arc is the path along the circumference of this circle from the start point to the end point, going anti-clockwise if the anticlockwise argument is true, and clockwise otherwise. Since the points are on the circle, as opposed to being simply angles from zero, the arc can never cover an angle greater than 2π radians. If the two points are the same, or if the radius is zero, then the arc is defined as being of zero length in both directions. Negative values for radius must cause the implementation to raise an INDEX_SIZE_ERR p70 exception. The rect(x, y, w, h) method must create a new subpath containing just the four points (x, y), (x+w, y), (x+w, y+h), (x, y+h), with those four points connected by straight lines, and must then mark the subpath as closed. It must then create a new subpath with the point (x, y) as the only point in the subpath. The fill() method must fill all the subpaths of the current path, using fillStyle p245 , and using the non-zero winding number rule. Open subpaths must be implicitly closed when being filled (without affecting the actual subpaths). Note: Thus, if two overlapping but otherwise independent subpaths have opposite windings, they cancel out and result in no fill. If they have the same winding, that area just gets painted once. The stroke() method must calculate the strokes of all the subpaths of the current path, using the lineWidth p248 , lineCap p248 , lineJoin p249 , and (if appropriate) miterLimit p249 attributes, and then fill the combined stroke area using the strokeStyle p245 attribute. Note: Since the subpaths are all stroked as one, overlapping parts of the paths in one stroke operation are treated as if their union was what was painted. Paths, when filled or stroked, must be painted without affecting the current path, and must be subject to shadow effects p249 , global alpha p244 , the clipping region p253 , and global composition operators p244 . (Transformations affect the path when the path is created, not when it is painted, though the stroke style is still affected by the transformation during painting.) Zero-length line segments must be pruned before stroking a path. Empty subpaths must be ignored. The clip() method must create a new clipping region by calculating the intersection of the current clipping region and the area described by the current path, using the non-zero winding number rule. Open subpaths must be implicitly closed when computing the clipping region, without affecting the actual subpaths. The new clipping region replaces the current clipping region. When the context is initialized, the clipping region must be set to the rectangle with the top left corner at (0,0) and the width and height of the coordinate space. The isPointInPath(x, y) method must return true if the point given by the x and y coordinates passed to the method, when treated as coordinates in the canvas coordinate space unaffected by the current transformation, is inside the current path as determined by the non-zero winding number rule; and must return false otherwise. Points on the path itself are considered to be inside the path. If either of the arguments is infinite or NaN, then the method must return false. 4.8.10.1.9 Focus management When a canvas is interactive, authors should include focusable elements in the element's fallback content corresponding to each focusable part of the canvas. To indicate which focusable part of the canvas is currently focused, authors should use the drawFocusRing() p254 method, passing it the element for which a ring is being drawn. This method only draws the focus ring if the element is focused, so that it can simply be called whenever drawing the element, without checking whether the element is focused or not first. The position of the center of the control, or of the editing caret if the control has one, should be given in the x and y arguments. 253 This box is non-normative. Implementation requirements are given below this box. shouldDraw = context . drawFocusRing p254 (element, x, y, [ canDrawCustom ]) If the given element is focused, draws a focus ring around the current path, following the platform conventions for focus rings. The given coordinate is used if the user's attention needs to be brought to a particular position (e.g. if a magnifier is following the editing caret in a text field). If the canDrawCustom argument is true, then the focus ring is only drawn if the user has configured his system to draw focus rings in a particular manner. (For example, high contrast focus rings.) Returns true if the given element is focused, the canDrawCustom argument is true, and the user has not configured his system to draw focus rings in a particular manner. Otherwise, returns false. When the method returns true, the author is expected to manually draw a focus ring. The drawFocusRing(element, x, y, [canDrawCustom]) method, when invoked, must run the following steps: 1. If element is not focused or is not a descendant of the element with whose context the method is associated, then return false and abort these steps. 2. Transform the given point (x, y) according to the current transformation matrix p243 . 3. Optionally, inform the user that the focus is at the given (transformed) coordinate on the canvas. (For example, this could involve moving the user's magnification tool.) 4. If the user has requested the use of particular focus rings (e.g. high-contrast focus rings), or if the canDrawCustom argument is absent or false, then draw a focus ring of the appropriate style along the path, following platform conventions, return false, and abort these steps. The focus ring should not be subject to the shadow effects p249 , the global alpha p244 , or the global composition operators p244 , but should be subject to the clipping region p253 . 5. Return true. This canvas p238 element has a couple of checkboxes: 4.8.10.1.10 Text This box is non-normative. Implementation requirements are given below this box. context . font p255 [ = value ] Returns the current font settings. Can be set, to change the font. The syntax is the same as for the CSS 'font' property; values that cannot be parsed as CSS font values are ignored. Relative keywords and lengths are computed relative to the font of the canvas p238 element. context . textAlign p256 [ = value ] Returns the current text alignment settings. Can be set, to change the alignment. The possible values are start, end, left, right, and center. Other values are ignored. The default is start. context . textBaseline p256 [ = value ] Returns the current baseline alignment settings. Can be set, to change the baseline alignment. The possible values and their meanings are given below. Other values are ignored. The default is alphabetic. context . fillText p257 (text, x, y [, maxWidth ] ) context . strokeText p257 (text, x, y [, maxWidth ] ) Fills or strokes (respectively) the given text at the given position. If a maximum width is provided, the text will be scaled to fit that width if necessary. metrics = context . measureText p258 (text) Returns a TextMetrics p242 object with the metrics of the given text in the current font. metrics . width p258 Returns the advance width of the text that was passed to the measureText() p258 method. The font IDL attribute, on setting, must be parsed the same way as the 'font' property of CSS (but without supporting property-independent style sheet syntax like 'inherit'), and the resulting font must be assigned to the context, with the 'line-height' component forced to 'normal', with the 'font-size' component converted to CSS pixels, and with system fonts being computed to explicit values. If the new value is syntactically incorrect 255 (including using property-independent style sheet syntax like 'inherit' or 'initial'), then it must be ignored, without assigning a new font value. [CSS] p700 Font names must be interpreted in the context of the canvas p238 element's stylesheets; any fonts embedded using @font-face must therefore be available once they are loaded. (If a font is referenced before it is fully loaded, then it must be treated as if it was an unknown font, falling back to another as described by the relevant CSS specifications.) [CSSFONTS] p700 Only vector fonts should be used by the user agent; if a user agent were to use bitmap fonts then transformations would likely make the font look very ugly. On getting, the font p255 attribute must return the serialized form of the current font of the context (with no 'lineheight' component). [CSSOM] p700 For example, after the following statement: context.font = 'italic 400 12px/2 Unknown Font, sans-serif'; ...the expression context.font would evaluate to the string "italic 12px "Unknown Font", sansserif". The "400" font-weight doesn't appear because that is the default value. The line-height doesn't appear because it is forced to "normal", the default value. When the context is created, the font of the context must be set to 10px sans-serif. When the 'font-size' component is set to lengths using percentages, 'em' or 'ex' units, or the 'larger' or 'smaller' keywords, these must be interpreted relative to the computed value of the 'font-size' property of the corresponding canvas p238 element at the time that the attribute is set. When the 'font-weight' component is set to the relative values 'bolder' and 'lighter', these must be interpreted relative to the computed value of the 'font-weight' property of the corresponding canvas p238 element at the time that the attribute is set. If the computed values are undefined for a particular case (e.g. because the canvas p238 element is not in a Document p27 ), then the relative keywords must be interpreted relative to the normal-weight 10px sans-serif default. The textAlign IDL attribute, on getting, must return the current value. On setting, if the value is one of start, end, left, right, or center, then the value must be changed to the new value. Otherwise, the new value must be ignored. When the context is created, the textAlign p256 attribute must initially have the value start. The textBaseline IDL attribute, on getting, must return the current value. On setting, if the value is one of top p256 , hanging p256 , middle p256 , alphabetic p256 , ideographic p257 , or bottom p257 , then the value must be changed to the new value. Otherwise, the new value must be ignored. When the context is created, the textBaseline p256 attribute must initially have the value alphabetic. The textBaseline p256 attribute's allowed keywords correspond to alignment points in the font: The keywords map to these alignment points as follows: top The top of the em square hanging The hanging baseline middle The middle of the em square alphabetic The alphabetic baseline 256 ideographic The ideographic baseline bottom The bottom of the em square The fillText() and strokeText() methods take three or four arguments, text, x, y, and optionally maxWidth, and render the given text at the given (x, y) coordinates ensuring that the text isn't wider than maxWidth if specified, using the current font p255 , textAlign p256 , and textBaseline p256 values. Specifically, when the methods are called, the user agent must run the following steps: 1. Let font be the current font of the context, as given by the font p255 attribute. 2. Replace all the space characters p34 in text with U+0020 SPACE characters. 3. Form a hypothetical infinitely wide CSS line box containing a single inline box containing the text text, with all the properties at their initial values except the 'font' property of the inline box set to font and the 'direction' property of the inline box set to the directionality p86 of the canvas p238 element. [CSS] p700 4. If the maxWidth argument was specified and the hypothetical width of the inline box in the hypothetical line box is greater than maxWidth CSS pixels, then change font to have a more condensed font (if one is available or if a reasonably readable one can be synthesized by applying a horizontal scale factor to the font) or a smaller font, and return to the previous step. 5. Let the anchor point be a point on the inline box, determined by the textAlign p256 and textBaseline p256 values, as follows: Horizontal position: If textAlign p256 is left If textAlign p256 is start and the directionality p86 of the canvas p238 element is 'ltr' If textAlign p256 is end and the directionality p86 of the canvas p238 element is 'rtl' Let the anchor point's horizontal position be the left edge of the inline box. If textAlign p256 is right If textAlign p256 is end and the directionality p86 of the canvas p238 element is 'ltr' If textAlign p256 is start and the directionality p86 of the canvas p238 element is 'rtl' Let the anchor point's horizontal position be the right edge of the inline box. If textAlign p256 is center Let the anchor point's horizontal position be half way between the left and right edges of the inline box. Vertical position: If textBaseline p256 is top p256 Let the anchor point's vertical position be the top of the em box of the first available font of the inline box. If textBaseline p256 is hanging p256 Let the anchor point's vertical position be the hanging baseline of the first available font of the inline box. If textBaseline p256 is middle p256 Let the anchor point's vertical position be half way between the bottom and the top of the em box of the first available font of the inline box. If textBaseline p256 is alphabetic p256 Let the anchor point's vertical position be the alphabetic baseline of the first available font of the inline box. If textBaseline p256 is ideographic p257 Let the anchor point's vertical position be the ideographic baseline of the first available font of the inline box. If textBaseline p256 is bottom p257 Let the anchor point's vertical position be the bottom of the em box of the first available font of the inline box. 6. Paint the hypothetical inline box as the shape given by the text's glyphs, as transformed by the current transformation matrix p243 , and anchored and sized so that before applying the current transformation matrix p243 , the anchor point is at (x, y) and each CSS pixel is mapped to one coordinate space unit. 257 For fillText() p257 fillStyle p245 must be applied to the glyphs and strokeStyle p245 must be ignored. For strokeText() p257 the reverse holds and strokeStyle p245 must be applied to the glyph outlines and fillStyle p245 must be ignored. Text is painted without affecting the current path, and is subject to shadow effects p249 , global alpha p244 , the clipping region p253 , and global composition operators p244 . The measureText() method takes one argument, text. When the method is invoked, the user agent must replace all the space characters p34 in text with U+0020 SPACE characters, and then must form a hypothetical infinitely wide CSS line box containing a single inline box containing the text text, with all the properties at their initial values except the 'font' property of the inline element set to the current font of the context, as given by the font p255 attribute, and must then return a new TextMetrics p242 object with its width p258 attribute set to the width of that inline box, in CSS pixels. [CSS] p700 The TextMetrics p242 interface is used for the objects returned from measureText() p258 . It has one attribute, width, which is set by the measureText() p258 method. Note: Glyphs rendered using fillText() p257 and strokeText() p257 can spill out of the box given by the font size (the em square size) and the width returned by measureText() p258 (the text width). This version of the specification does not provide a way to obtain the bounding box dimensions of the text. If the text is to be rendered and removed, care needs to be taken to replace the entire area of the canvas that the clipping region covers, not just the box given by the em square height and measured text width. Note: A future version of the 2D context API may provide a way to render fragments of documents, rendered using CSS, straight to the canvas. This would be provided in preference to a dedicated way of doing multiline layout. 4.8.10.1.11 Images To draw images onto the canvas, the drawImage method can be used. This method can be invoked with three different sets of arguments: • • • drawImage(image, dx, dy) drawImage(image, dx, dy, dw, dh) drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh) Each of those three can take either an HTMLImageElement p186 , an HTMLCanvasElement p238 , or an HTMLVideoElement p214 for the image argument. This box is non-normative. Implementation requirements are given below this box. context . drawImage p258 (image, dx, dy) context . drawImage p258 (image, dx, dy, dw, dh) context . drawImage p258 (image, sx, sy, sw, sh, dx, dy, dw, dh) Draws the given image onto the canvas. The arguments are interpreted as follows: 258 If the first argument isn't an img p186 , canvas p238 , or video p213 element, throws a TYPE_MISMATCH_ERR p70 exception. If the image has no image data, throws an INVALID_STATE_ERR p70 exception. If the numeric arguments don't make sense (e.g. the destination is a 0×0 rectangle), throws an INDEX_SIZE_ERR p70 exception. If the image isn't yet fully decoded, then nothing is drawn. If not specified, the dw and dh arguments must default to the values of sw and sh, interpreted such that one CSS pixel in the image is treated as one unit in the canvas coordinate space. If the sx, sy, sw, and sh arguments are omitted, they must default to 0, 0, the image's intrinsic width in image pixels, and the image's intrinsic height in image pixels, respectively. The image argument is an instance of either HTMLImageElement p186 , HTMLCanvasElement p238 , or HTMLVideoElement p214 . If the image is null, the implementation must raise a TYPE_MISMATCH_ERR p70 exception. If the image argument is an HTMLImageElement p186 object whose complete p189 attribute is false, or if the image argument is an HTMLVideoElement p214 object whose readyState p231 attribute is either HAVE_NOTHING p229 or HAVE_METADATA p229 , then the implementation must return without drawing anything. If the image argument is an HTMLCanvasElement p238 object with either a horizontal dimension or a vertical dimension equal to zero, then the implementation must raise an INVALID_STATE_ERR p70 exception. The source rectangle is the rectangle whose corners are the four points (sx, sy), (sx+sw, sy), (sx+sw, sy+sh), (sx, sy+sh). If the source rectangle is not entirely within the source image, or if one of the sw or sh arguments is zero, the implementation must raise an INDEX_SIZE_ERR p70 exception. The destination rectangle is the rectangle whose corners are the four points (dx, dy), (dx+dw, dy), (dx+dw, dy+dh), (dx, dy+dh). When drawImage() p258 is invoked, the region of the image specified by the source rectangle must be painted on the region of the canvas specified by the destination rectangle, after applying the current transformation matrix p243 to the points of the destination rectangle. The original image data of the source image must be used, not the image as it is rendered (e.g. width p271 and height p271 attributes on the source element have no effect). The image data must be processed in the original direction, even if the dimensions given are negative. Note: This specification does not define the algorithm to use when scaling the image, if necessary. Note: When a canvas is drawn onto itself, the drawing model requires the source to be copied before the image is drawn back onto the canvas, so it is possible to copy parts of a canvas onto overlapping parts of itself. 259 When the drawImage() p258 method is passed an animated image as its image argument, the user agent must use the poster frame of the animation, or, if there is no poster frame, the first frame of the animation. When the image argument is an HTMLVideoElement p214 , then the frame at the current playback position p229 must be used as the source image, and the source image's dimensions must be the intrinsic width p215 and intrinsic height p215 of the media resource p219 (i.e. after any aspect-ratio correction has been applied). Images are painted without affecting the current path, and are subject to shadow effects p249 , global alpha p244 , the clipping region p253 , and global composition operators p244 . 4.8.10.1.12 Pixel manipulation This box is non-normative. Implementation requirements are given below this box. imagedata = context . createImageData p260 (sw, sh) Returns an ImageData p242 object with the given dimensions in CSS pixels (which might map to a different number of actual device pixels exposed by the object itself). All the pixels in the returned object are transparent black. imagedata = context . createImageData p260 (imagedata) Returns an ImageData p242 object with the same dimensions as the argument. All the pixels in the returned object are transparent black. Throws a NOT_SUPPORTED_ERR p70 exception if the argument is null. imagedata = context . getImageData p260 (sx, sy, sw, sh) Returns an ImageData p242 object containing the image data for the given rectangle of the canvas. Throws a NOT_SUPPORTED_ERR p70 exception if any of the arguments are not finite. Throws an INDEX_SIZE_ERR p70 exception if the either of the width or height arguments are zero. imagedata . width p260 imagedata . height p260 Returns the actual dimensions of the data in the ImageData p242 object, in device pixels. imagedata . data p261 Returns the one-dimensional array containing the data in RGBA order, as integers in the range 0 to 255. context . putImageData p261 (imagedata, dx, dy [, dirtyX, dirtyY, dirtyWidth, dirtyHeight ]) Paints the data from the given ImageData p242 object onto the canvas. If a dirty rectangle is provided, only the pixels from that rectangle are painted. The globalAlpha p244 and globalCompositeOperation p244 attributes, as well as the shadow attributes, are ignored for the purposes of this method call; pixels in the canvas are replaced wholesale, with no composition, alpha blending, no shadows, etc. If the first argument isn't an ImageData p242 object, throws a TYPE_MISMATCH_ERR p70 exception. Throws a NOT_SUPPORTED_ERR p70 exception if any of the other arguments are not finite. The createImageData() method is used to instantiate new blank ImageData p242 objects. When the method is invoked with two arguments sw and sh, it must return an ImageData p242 object representing a rectangle with a width in CSS pixels equal to the absolute magnitude of sw and a height in CSS pixels equal to the absolute magnitude of sh. When invoked with a single imagedata argument, it must return an ImageData p242 object representing a rectangle with the same dimensions as the ImageData p242 object passed as the argument. The ImageData p242 object return must be filled with transparent black. The getImageData(sx, sy, sw, sh) method must return an ImageData p242 object representing the underlying pixel data for the area of the canvas denoted by the rectangle whose corners are the four points (sx, sy), (sx+sw, sy), (sx+sw, sy+sh), (sx, sy+sh), in canvas coordinate space units. Pixels outside the canvas must be returned as transparent black. Pixels must be returned as non-premultiplied alpha values. If any of the arguments to createImageData() p260 or getImageData() p260 are infinite or NaN, or if the createImageData() p260 method is invoked with only one argument but that argument is null, the method must instead raise a NOT_SUPPORTED_ERR p70 exception. If either the sw or sh arguments are zero, the method must instead raise an INDEX_SIZE_ERR p70 exception. ImageData p242 objects must be initialized so that their width attribute is set to w, the number of physical device pixels per row in the image data, their height attribute is set to h, the number of rows in the image data, and their 260 data attribute is initialized to a CanvasPixelArray p242 object holding the image data. At least one pixel's worth of image data must be returned. The CanvasPixelArray p242 object provides ordered, indexed access to the color components of each pixel of the image data. The data must be represented in left-to-right order, row by row top to bottom, starting with the top left, with each pixel's red, green, blue, and alpha components being given in that order for each pixel. Each component of each device pixel represented in this array must be in the range 0..255, representing the 8 bit value for that component. The components must be assigned consecutive indices starting with 0 for the top left pixel's red component. The CanvasPixelArray p242 object thus represents h×w×4 integers. The length attribute of a CanvasPixelArray p242 object must return this number. The object's indices of the supported indexed properties are the numbers in the range 0 .. h×w×4-1. When a CanvasPixelArray p242 object is indexed to retrieve an indexed property index, the value returned must be the value of the indexth component in the array. When a CanvasPixelArray p242 object is indexed to modify an indexed property index with value value, the value of the indexth component in the array must be set to value. Note: The width and height (w and h) might be different from the sw and sh arguments to the above methods, e.g. if the canvas is backed by a high-resolution bitmap, or if the sw and sh arguments are negative. The putImageData(imagedata, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight) method writes data from ImageData p242 structures back to the canvas. If any of the arguments to the method are infinite or NaN, the method must raise a NOT_SUPPORTED_ERR p70 exception. If the first argument to the method is null or not an ImageData p242 object then the putImageData() p261 method must raise a TYPE_MISMATCH_ERR p70 exception. When the last four arguments are omitted, they must be assumed to have the values 0, 0, the width p260 member of the imagedata structure, and the height p260 member of the imagedata structure, respectively. When invoked with arguments that do not, per the last few paragraphs, cause an exception to be raised, the putImageData() p261 method must act as follows: 1. Let dxdevice be the x-coordinate of the device pixel in the underlying pixel data of the canvas corresponding to the dx coordinate in the canvas coordinate space. Let dydevice be the y-coordinate of the device pixel in the underlying pixel data of the canvas corresponding to the dy coordinate in the canvas coordinate space. 2. If dirtyWidth is negative, let dirtyX be dirtyX+dirtyWidth, and let dirtyWidth be equal to the absolute magnitude of dirtyWidth. If dirtyHeight is negative, let dirtyY be dirtyY+dirtyHeight, and let dirtyHeight be equal to the absolute magnitude of dirtyHeight. 3. If dirtyX is negative, let dirtyWidth be dirtyWidth+dirtyX, and let dirtyX be zero. If dirtyY is negative, let dirtyHeight be dirtyHeight+dirtyY, and let dirtyY be zero. 4. If dirtyX+dirtyWidth is greater than the width p260 attribute of the imagedata argument, let dirtyWidth be the value of that width p260 attribute, minus the value of dirtyX. If dirtyY+dirtyHeight is greater than the height p260 attribute of the imagedata argument, let dirtyHeight be the value of that height p260 attribute, minus the value of dirtyY. 5. If, after those changes, either dirtyWidth or dirtyHeight is negative or zero, stop these steps without affecting the canvas. 6. Otherwise, for all integer values of x and y where dirtyX ≤ x < dirtyX+dirtyWidth and dirtyY ≤ y < dirtyY+dirtyHeight, copy the four channels of the pixel with coordinate (x, y) in the imagedata data structure to the pixel with coordinate (dxdevice+x, dydevice+y) in the underlying pixel data of the canvas. The handling of pixel rounding when the specified coordinates do not exactly map to the device coordinate space is not defined by this specification, except that the following must result in no visible changes to the rendering: context.putImageData(context.getImageData(x, y, w, h), p, q); 261 ...for any value of x, y, w, and h and where p is the smaller of x and the sum of x and w, and q is the smaller of y and the sum of y and h; and except that the following two calls: context.createImageData(w, h); context.getImageData(0, 0, w, h); ...must return ImageData p242 objects with the same dimensions, for any value of w and h. In other words, while user agents may round the arguments of these methods so that they map to device pixel boundaries, any rounding performed must be performed consistently for all of the createImageData() p260 , getImageData() p260 and putImageData() p261 operations. Note: Due to the lossy nature of converting to and from premultiplied alpha color values, pixels that have just been set using putImageData() p261 might be returned to an equivalent getImageData() p260 as different values. The current path, transformation matrix p243 , shadow attributes p249 , global alpha p244 , the clipping region p253 , and global composition operator p244 must not affect the getImageData() p260 and putImageData() p261 methods. The data returned by getImageData() p260 is at the resolution of the canvas backing store, which is likely to not be one device pixel to each CSS pixel if the display used is a high resolution display. In the following example, the script generates an ImageData p242 object so that it can draw onto it. // canvas is a reference to a element var context = canvas.getContext('2d'); // create a blank slate var data = context.createImageData(canvas.width, canvas.height); // create some plasma FillPlasma(data, 'green'); // green plasma // add a cloud to the plasma AddCloud(data, data.width/2, data.height/2); // put a cloud in the middle // paint the plasma+cloud on the canvas context.putImageData(data, 0, 0); // support methods function FillPlasma(data, color) { ... } function AddCloud(data, x, y) { ... } Here is an example of using getImageData() p260 and putImageData() p261 to implement an edge detection filter. Edge detection demo 4.8.10.1.13 Drawing model When a shape or image is painted, user agents must follow these steps, in the order given (or act as if they do): 1. Render the shape or image onto an infinite transparent black bitmap, creating image A, as described in the previous sections. For shapes, the current fill, stroke, and line styles must be honored, and the stroke must itself also be subjected to the current transformation matrix. 2. When shadows are drawn p250 , render the shadow from image A, using the current shadow styles, creating image B. 3. When shadows are drawn p250 , multiply the alpha component of every pixel in B by globalAlpha p244 . 4. When shadows are drawn p250 , composite B within the clipping region over the current canvas bitmap using the current composition operator. 5. Multiply the alpha component of every pixel in A by globalAlpha p244 . 6. Composite A within the clipping region over the current canvas bitmap using the current composition operator. 4.8.10.1.14 Examples This section is non-normative. Here is an example of a script that uses canvas to draw pretty glowing lines. 4.8.10.2 Color spaces and color correction The canvas p238 APIs must perform color correction at only two points: when rendering images with their own gamma correction and color space information onto the canvas, to convert the image to the color space used by the canvas (e.g. using the 2D Context's drawImage() p258 method with an HTMLImageElement p186 object), and when rendering the actual canvas bitmap to the output device. Note: Thus, in the 2D context, colors used to draw shapes onto the canvas will exactly match colors obtained through the getImageData() p260 method. The toDataURL() p240 method must not include color space information in the resource returned. Where the output format allows it, the color of pixels in resources created by toDataURL() p240 must match those returned by the getImageData() p260 method. In user agents that support CSS, the color space used by a canvas p238 element must match the color space used for processing any colors for that element in CSS. The gamma correction and color space information of images must be handled in such a way that an image rendered directly using an img p186 element would use the same colors as one painted on a canvas p238 element that is then itself rendered. Furthermore, the rendering of images that have no color correction information (such as those returned by the toDataURL() p240 method) must be rendered with no color correction. Note: Thus, in the 2D context, calling the drawImage() p258 method to render the output of the toDataURL() p240 method to the canvas, given the appropriate dimensions, has no visible effect. 4.8.10.3 Security with canvas p238 elements Information leakage can occur if scripts from one origin p449 can access information (e.g. read pixels) from images from another origin (one that isn't the same p451 ). To mitigate this, canvas p238 elements are defined to have a flag indicating whether they are origin-clean. All canvas p238 elements must start with their origin-clean set to true. The flag must be set to false if any of the following actions occur: 264 • The element's 2D context's drawImage() p258 method is called with an HTMLImageElement p186 or an HTMLVideoElement p214 whose origin p449 is not the same p451 as that of the Document p31 object that owns the canvas p238 element. • The element's 2D context's drawImage() p258 method is called with an HTMLCanvasElement p238 whose origin-clean flag is false. • The element's 2D context's fillStyle p245 attribute is set to a CanvasPattern p242 object that was created from an HTMLImageElement p186 or an HTMLVideoElement p214 whose origin p449 was not the same p451 as that of the Document p31 object that owns the canvas p238 element when the pattern was created. • The element's 2D context's fillStyle p245 attribute is set to a CanvasPattern p242 object that was created from an HTMLCanvasElement p238 whose origin-clean flag was false when the pattern was created. • The element's 2D context's strokeStyle p245 attribute is set to a CanvasPattern p242 object that was created from an HTMLImageElement p186 or an HTMLVideoElement p214 whose origin p449 was not the same p451 as that of the Document p31 object that owns the canvas p238 element when the pattern was created. • The element's 2D context's strokeStyle p245 attribute is set to a CanvasPattern p242 object that was created from an HTMLCanvasElement p238 whose origin-clean flag was false when the pattern was created. Whenever the toDataURL() p240 method of a canvas p238 element whose origin-clean flag is set to false is called, the method must raise a SECURITY_ERR p70 exception. Whenever the getImageData() p260 method of the 2D context of a canvas p238 element whose origin-clean flag is set to false is called with otherwise correct arguments, the method must raise a SECURITY_ERR p70 exception. Note: Even resetting the canvas state by changing its width p239 or height p239 attributes doesn't reset the origin-clean flag. 4.8.11 The map element Categories Flow content p91 . When the element only contains phrasing content p91 : phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Transparent p93 . Content attributes: Global attributes p82 name p265 DOM interface: interface HTMLMapElement : HTMLElement { attribute DOMString name; readonly attribute HTMLCollection areas; readonly attribute HTMLCollection images; }; The map p265 element, in conjunction with any area p266 element descendants, defines an image map p268 . The element represents p638 its children. The name attribute gives the map a name so that it can be referenced. The attribute must be present and must have a non-empty value with no space characters p34 . The value of the name p265 attribute must not be a compatibility-caseless p33 match for the value of the name p265 attribute of another map p265 element in the same document. If the id p84 attribute is also specified, both attributes must have the same value. This box is non-normative. Implementation requirements are given below this box. map . areas p265 Returns an HTMLCollection p59 of the area p266 elements in the map p265 . map . images p266 Returns an HTMLCollection p59 of the img p186 and object p208 elements that use the map p265 . The areas attribute must return an HTMLCollection p59 rooted at the map p265 element, whose filter matches only area p266 elements. 265 The images attribute must return an HTMLCollection p59 rooted at the Document p31 node, whose filter matches only img p186 and object p208 elements that are associated with this map p265 element according to the image map p268 processing model. The IDL attribute name must reflect p57 the content attribute of the same name. 4.8.12 The area element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected, but only if there is a map p265 element ancestor. Content model: Empty. Content attributes: Global attributes p82 alt p266 coords p267 shape p267 href p383 target p384 ping p384 rel p384 media p384 hreflang p384 type p384 DOM interface: interface HTMLAreaElement : HTMLElement { attribute DOMString alt; attribute DOMString coords; attribute DOMString shape; stringifier attribute DOMString href; attribute DOMString target; attribute DOMString ping; attribute readonly attribute attribute attribute attribute DOMString rel; DOMTokenList relList; DOMString media; DOMString hreflang; DOMString type; // URL decomposition IDL attributes attribute DOMString protocol; attribute DOMString host; attribute DOMString hostname; attribute DOMString port; attribute DOMString pathname; attribute DOMString search; attribute DOMString hash; }; The area p266 element represents p638 either a hyperlink with some text and a corresponding area on an image map p268 , or a dead area on an image map. If the area p266 element has an href p383 attribute, then the area p266 element represents a hyperlink p383 . In this case, the alt attribute must be present. It specifies the text of the hyperlink. Its value must be text that, when presented with the texts specified for the other hyperlinks of the image map p268 , and with the alternative text of the image, but without the image itself, provides the user with the same kind of choice as the hyperlink would when used without its text but with its shape applied to the image. The alt p266 attribute may be left blank if there is another area p266 element in the same image map p268 that points to the same resource and has a non-blank alt p266 attribute. 266 If the area p266 element has no href p383 attribute, then the area represented by the element cannot be selected, and the alt p266 attribute must be omitted. In both cases, the shape p267 and coords p267 attributes specify the area. The shape attribute is an enumerated attribute p34 . The following table lists the keywords defined for this attribute. The states given in the first cell of the rows with keywords give the states to which those keywords map. Some of the keywords are non-conforming, as noted in the last column. State Circle state p267 Keywords Notes circle circ Default state p267 default Polygon state p267 poly polygon Non-conforming Non-conforming Rectangle state p267 rect rectangle Non-conforming The attribute may be omitted. The missing value default is the rectangle p267 state. The coords attribute must, if specified, contain a valid list of integers p38 . This attribute gives the coordinates for the shape described by the shape p267 attribute. The processing for this attribute is described as part of the image map p268 processing model. In the circle state, area p266 elements must have a coords p267 attribute present, with three integers, the last of which must be non-negative. The first integer must be the distance in CSS pixels from the left edge of the image to the center of the circle, the second integer must be the distance in CSS pixels from the top edge of the image to the center of the circle, and the third integer must be the radius of the circle, again in CSS pixels. In the default state state, area p266 elements must not have a coords p267 attribute. (The area is the whole image.) In the polygon state, area p266 elements must have a coords p267 attribute with at least six integers, and the number of integers must be even. Each pair of integers must represent a coordinate given as the distances from the left and the top of the image in CSS pixels respectively, and all the coordinates together must represent the points of the polygon, in order. In the rectangle state, area p266 elements must have a coords p267 attribute with exactly four integers, the first of which must be less than the third, and the second of which must be less than the fourth. The four points must represent, respectively, the distance from the left edge of the image to the left side of the rectangle, the distance from the top edge to the top side, the distance from the left edge to the right side, and the distance from the top edge to the bottom side, all in CSS pixels. When user agents allow users to follow hyperlinks p384 created using the area p266 element, as described in the next section, the href p383 , target p384 and ping p384 attributes decide how the link is followed. The rel p384 , media p384 , hreflang p384 , and type p384 attributes may be used to indicate to the user the likely nature of the target resource before the user follows the link. The target p384 , ping p384 , rel p384 , media p384 , hreflang p384 , and type p384 attributes must be omitted if the href p383 attribute is not present. The activation behavior p93 of area p266 elements is to run the following steps: 1. If the DOMActivate p31 event in question is not trusted p27 (i.e. a click() p508 method call was the reason for the event being dispatched), and the area p266 element's target p384 attribute is such that applying the rules for choosing a browsing context given a browsing context name p442 , using the value of the target p384 attribute as the browsing context name, would result in there not being a chosen browsing context, then raise an INVALID_ACCESS_ERR p70 exception and abort these steps. 2. Otherwise, the user agent must follow the hyperlink p384 defined by the area p266 element, if any. The IDL attributes alt, coords, href, target, ping, rel, media, hreflang, and type, each must reflect p57 the respective content attributes of the same name. The IDL attribute shape must reflect p57 the shape p267 content attribute, limited to only known values p58 . The IDL attribute relList must reflect p57 the rel p384 content attribute. The area p266 element also supports the complement of URL decomposition IDL attributes p53 , protocol, host, port, hostname, pathname, search, and hash. These must follow the rules given for URL decomposition IDL attributes, with the input p54 being the result of resolving p51 the element's href p383 attribute relative to the element, if there is such an attribute and resolving it is successful, or the empty string otherwise; and the common setter action p54 being the same as setting the element's href p383 attribute to the new output value. 267 4.8.13 Image maps 4.8.13.1 Authoring An image map allows geometric areas on an image to be associated with hyperlinks p383 . An image, in the form of an img p186 element or an object p208 element representing an image, may be associated with an image map (in the form of a map p265 element) by specifying a usemap attribute on the img p186 or object p208 element. The usemap p268 attribute, if specified, must be a valid hash-name reference p50 to a map p265 element. Consider an image that looks as follows: If we wanted just the colored areas to be clickable, we could do it as follows:

    Please select a shape: Four shapes are available: a red hollow box, a green circle, a blue
triangle, and a yellow four-pointed star. Red box. Green circle. Blue
triangle. Yellow star.

    4.8.13.2 Processing model If an img p186 element or an object p208 element representing an image has a usemap p268 attribute specified, user agents must process it as follows: 1. First, rules for parsing a hash-name reference p50 to a map p265 element must be followed. This will return either an element (the map) or null. 2. If that returned null, then abort these steps. The image is not associated with an image map after all. 3. Otherwise, the user agent must collect all the area p266 elements that are descendants of the map. Let those be the areas. Having obtained the list of area p266 elements that form the image map (the areas), interactive user agents must process the list in one of two ways. If the user agent intends to show the text that the img p186 element represents, then it must use the following steps. Note: In user agents that do not support images, or that have images disabled, object p208 elements cannot represent images, and thus this section never applies (the fallback content p92 is shown instead). The following steps therefore only apply to img p186 elements. 268 1. Remove all the area p266 elements in areas that have no href p383 attribute. 2. Remove all the area p266 elements in areas that have no alt p266 attribute, or whose alt p266 attribute's value is the empty string, if there is another area p266 element in areas with the same value in the href p383 attribute and with a non-empty alt p266 attribute. 3. Each remaining area p266 element in areas represents a hyperlink p383 . Those hyperlinks should all be made available to the user in a manner associated with the text of the img p186 . In this context, user agents may represent area p266 and img p186 elements with no specified alt attributes, or whose alt attributes are the empty string or some other non-visible text, in a user-agentdefined fashion intended to indicate the lack of suitable author-provided text. If the user agent intends to show the image and allow interaction with the image to select hyperlinks, then the image must be associated with a set of layered shapes, taken from the area p266 elements in areas, in reverse tree order (so the last specified area p266 element in the map is the bottom-most shape, and the first element in the map, in tree order, is the top-most shape). Each area p266 element in areas must be processed as follows to obtain a shape to layer onto the image: 1. Find the state that the element's shape p267 attribute represents. 2. Use the rules for parsing a list of integers p38 to parse the element's coords p267 attribute, if it is present, and let the result be the coords list. If the attribute is absent, let the coords list be the empty list. 3. If the number of items in the coords list is less than the minimum number given for the area p266 element's current state, as per the following table, then the shape is empty; abort these steps. State Circle state Minimum number of items p267 Default state p267 Polygon state p267 3 0 6 Rectangle state p267 4 4. Check for excess items in the coords list as per the entry in the following list corresponding to the shape p267 attribute's state: p267 ↪ Circle state Drop any items in the list beyond the third. p267 ↪ Default state Drop all items in the list. p267 ↪ Polygon state Drop the last item if there's an odd number of items. p267 ↪ Rectangle state Drop any items in the list beyond the fourth. 5. If the shape p267 attribute represents the rectangle state p267 , and the first number in the list is numerically less than the third number in the list, then swap those two numbers around. 6. If the shape p267 attribute represents the rectangle state p267 , and the second number in the list is numerically less than the fourth number in the list, then swap those two numbers around. 7. If the shape p267 attribute represents the circle state p267 , and the third number in the list is less than or equal to zero, then the shape is empty; abort these steps. 8. Now, the shape represented by the element is the one described for the entry in the list below corresponding to the state of the shape p267 attribute: p267 ↪ Circle state Let x be the first number in coords, y be the second number, and r be the third number. The shape is a circle whose center is x CSS pixels from the left edge of the image and x CSS pixels from the top edge of the image, and whose radius is r pixels. p267 ↪ Default state The shape is a rectangle that exactly covers the entire image. p267 ↪ Polygon state Let xi be the (2i)th entry in coords, and yi be the (2i+1)th entry in coords (the first entry in coords being the one with index 0). Let the coordinates be (xi, yi), interpreted in CSS pixels measured from the top left of the image, for all integer values of i from 0 to (N/2)-1, where N is the number of items in coords. The shape is a polygon whose vertices are given by the coordinates, and whose interior is established using the even-odd rule. [GRAPHICS] p701 269 p267 ↪ Rectangle state Let x1 be the first number in coords, y1 be the second number, x2 be the third number, and y2 be the fourth number. The shape is a rectangle whose top-left corner is given by the coordinate (x1, y1) and whose bottom right corner is given by the coordinate (x2, y2), those coordinates being interpreted as CSS pixels from the top left corner of the image. For historical reasons, the coordinates must be interpreted relative to the displayed image, even if it stretched using CSS or the image element's width and height attributes. Mouse clicks on an image associated with a set of layered shapes per the above algorithm must be dispatched to the top-most shape covering the point that the pointing device indicated (if any), and then, must be dispatched again (with a new Event p31 object) to the image element itself. User agents may also allow individual area p266 elements representing hyperlinks p383 to be selected and activated (e.g. using a keyboard); events from this are not also propagated to the image. Note: Because a map p265 element (and its area p266 elements) can be associated with multiple img p186 and object p208 elements, it is possible for an area p266 element to correspond to multiple focusable areas of the document. Image maps are live p27 ; if the DOM is mutated, then the user agent must act as if it had rerun the algorithms for image maps. 4.8.14 MathML The math element from the MathML namespace p70 falls into the embedded content p92 , phrasing content p91 , and flow content p91 categories for the purposes of the content models in this specification. User agents must handle text other than inter-element whitespace p89 found in MathML elements whose content models do not allow straight text by pretending for the purposes of MathML content models, layout, and rendering that that text is actually wrapped in an mtext element in the MathML namespace p70 . (Such text is not, however, conforming.) User agents must act as if any MathML element whose contents does not match the element's content model was replaced, for the purposes of MathML layout and rendering, by an merror element in the MathML namespace p70 containing some appropriate error message. To enable authors to use MathML tools that only accept MathML in its XML form, interactive HTML user agents are encouraged to provide a way to export any MathML fragment as an XML namespace-well-formed XML fragment. The semantics of MathML elements are defined by the MathML specification and other relevant specifications. [MATHML] p702 Here is an example of the use of MathML in an HTML document: The quadratic formula

    The quadratic formula

    x = b ± b 2 4 a c 2 a 270

    4.8.15 SVG The svg element from the SVG namespace p70 falls into the embedded content p92 , phrasing content p91 , and flow content p91 categories for the purposes of the content models in this specification. To enable authors to use SVG tools that only accept SVG in its XML form, interactive HTML user agents are encouraged to provide a way to export any SVG fragment as an XML namespace-well-formed XML fragment. When the SVG foreignObject element contains elements from the HTML namespace p70 , such elements must all be flow content p91 . [SVG] p704 The content model for title elements in the SVG namespace p70 inside HTML documents p71 is phrasing content p91 . (This further constrains the requirements given in the SVG specification.) The semantics of SVG elements are defined by the SVG specification and other relevant specifications. [SVG] p704 The SVG specification includes requirements regarding the handling of elements in the DOM that are not in the SVG namespace, that are in SVG fragments, and that are not included in a foreignObject element. This specification does not define any processing for elements in SVG fragments that are not in the HTML namespace; they are considered neither conforming nor non-conforming from the perspective of this specification. 4.8.16 Dimension attributes Author requirements: The width and height attributes on img p186 , iframe p199 , embed p205 , object p208 , video p213 , and, when their type p304 attribute is in the Image Button p321 state, input p303 elements may be specified to give the dimensions of the visual content of the element (the width and height respectively, relative to the nominal direction of the output medium), in CSS pixels. The attributes, if specified, must have values that are valid nonnegative integers p35 . The specified dimensions given may differ from the dimensions specified in the resource itself, since the resource may have a resolution that differs from the CSS pixel resolution. (On screens, CSS pixels have a resolution of 96ppi, but in general the CSS pixel resolution depends on the reading distance.) If both attributes are specified, then one of the following statements must be true: • specified width - 0.5 ≤ specified height * target ratio ≤ specified width + 0.5 • specified height - 0.5 ≤ specified width / target ratio ≤ specified height + 0.5 • specified height = specified width = 0 The target ratio is the ratio of the intrinsic width to the intrinsic height in the resource. The specified width and specified height are the values of the width p271 and height p271 attributes respectively. The two attributes must be omitted if the resource in question does not have both an intrinsic width and an intrinsic height. If the two attributes are both zero, it indicates that the element is not intended for the user (e.g. it might be a part of a service to count page views). Note: The dimension attributes are not intended to be used to stretch the image. User agent requirements: User agents are expected to use these attributes as hints for the rendering p650 . The width and height IDL attributes on the iframe p199 , embed p205 , object p208 , and video p213 elements must reflect p57 the respective content attributes of the same name. 4.9 Tabular data 4.9.1 The table element Categories Flow content p91 . Contexts in which this element may be used: Where flow content p91 is expected. 271 Content model: In this order: optionally a caption p277 element, followed by either zero or more colgroup p278 elements, followed optionally by a thead p280 element, followed optionally by a tfoot p280 element, followed by either zero or more tbody p279 elements or one or more tr p281 elements, followed optionally by a tfoot p280 element (but there can only be one tfoot p280 element child in total). Content attributes: Global attributes p82 summary p275 (but see prose) DOM interface: interface HTMLTableElement : HTMLElement { attribute HTMLTableCaptionElement caption; HTMLElement createCaption(); void deleteCaption(); attribute HTMLTableSectionElement tHead; HTMLElement createTHead(); void deleteTHead(); attribute HTMLTableSectionElement tFoot; HTMLElement createTFoot(); void deleteTFoot(); readonly attribute HTMLCollection tBodies; HTMLElement createTBody(); readonly attribute HTMLCollection rows; HTMLElement insertRow(in optional long index); void deleteRow(in long index); attribute DOMString summary; }; The table p271 element represents p638 data with more than one dimension, in the form of a table p285 . The table p271 element takes part in the table model p285 . Tables must not be used as layout aids. Historically, some Web authors have misused tables in HTML as a way to control their page layout. This usage is non-conforming, because tools attempting to extract tabular data from such documents would obtain very confusing results. In particular, users of accessibility tools like screen readers are likely to find it very difficult to navigate pages with tables used for layout. Note: There are a variety of alternatives to using HTML tables for layout, primarily using CSS positioning and the CSS table model. User agents that do table analysis on arbitrary content are encouraged to find heuristics to determine which tables actually contain data and which are merely being used for layout. This specification does not define a precise heuristic. Tables have rows and columns given by their descendants. A table must not have an empty row or column, as described in the description of the table model p285 . For tables that consist of more than just a grid of cells with headers in the first row and headers in the first column, and for any table in general where the reader might have difficulty understanding the content, authors should include explanatory information introducing the table. This information is useful for all users, but is especially useful for users who cannot see the table, e.g. users of screen readers. Such explanatory information should introduce the purpose of the table, outline its basic cell structure, highlight any trends or patterns, and generally teach the user how to use the table. For instance, the following table: Characteristics with positive and negative sides Negative Characteristic Positive Sad Mood Happy Failing Grade Passing ...might benefit from a description explaining the way the table is laid out, something like "Characteristics are given in the second column, with the negative side in the left column and the positive side in the right column". 272 There are a variety of ways to include this information, such as: In prose, surrounding the table

    In the following table, characteristics are given in the second column, with the negative side in the left column and the positive side in the right column.

    Characteristics with positive and negative sides
    Negative Characteristic Positive
    Sad Mood Happy
    Failing Grade Passing
    In the table's caption p277
    Characteristics with positive and negative sides.

    Characteristics are given in the second column, with the negative side in the left column and the positive side in the right column.

    Negative Characteristic Positive
    Sad Mood Happy
    Failing Grade Passing
    In the table's caption p277 , in a details p367 element
    Characteristics with positive and negative sides.
    Help

    Characteristics are given in the second column, with the negative side in the left column and the positive side in the right column.

    Negative Characteristic Positive
    Sad Mood Happy
    Failing 273 Grade Passing
    Next to the table, in the same figure p158
    Characteristics with positive and negative sides

    Characteristics are given in the second column, with the negative side in the left column and the positive side in the right column.

    Negative Characteristic Positive
    Sad Mood Happy
    Failing Grade Passing
    Next to the table, in a figure p158 's figcaption p159
    Characteristics with positive and negative sides

    Characteristics are given in the second column, with the negative side in the left column and the positive side in the right column.

    Negative Characteristic Positive
    Sad Mood Happy
    Failing Grade Passing
    Authors may also use other techniques, or combinations of the above techniques, as appropriate. The best option, of course, rather than writing a description explaining the way the table is laid out, is to adjust the table such that no explanation is needed. In the case of the table used in the examples above, a simple rearrangement of the table so that the headers are on the top and left sides removes the need for an explanation as well as removing the need for the use of headers p284 attributes: 274
    Characteristics with positive and negative sides
    Characteristic Negative Positive
    Mood Sad Happy
    Grade Failing Passing
    The summary attribute on table p271 elements was suggested in earlier versions of the language as a technique for providing explanatory text for complex tables for users of screen readers. One of the techniques p272 described above should be used instead. Note: In particular, authors are encouraged to consider whether their explanatory text for tables is likely to be useful to the visually impaired: if their text would not be useful, then it is best to not include a summary p275 attribute. Similarly, if their explanatory text could help someone who is not visually impaired, e.g. someone who is seeing the table for the first time, then the text would be more useful before the table or in the caption p277 . For example, describing the conclusions of the data in a table is useful to everyone; explaining how to read the table, if not obvious from the headers alone, is useful to everyone; describing the structure of the table, if it is easy to grasp visually, may not be useful to everyone, but it might also not be useful to users who can quickly navigate the table with an accessibility tool. If a table p271 element has a summary p275 attribute, the user agent may report the contents of that attribute to the user. This box is non-normative. Implementation requirements are given below this box. table . caption p276 [ = value ] Returns the table's caption p277 element. Can be set, to replace the caption p277 element. If the new value is not a caption p277 element, throws a HIERARCHY_REQUEST_ERR p70 exception. caption = table . createCaption p276 () Ensures the table has a caption p277 element, and returns it. table . deleteCaption p276 () Ensures the table does not have a caption p277 element. table . tHead p276 [ = value ] Returns the table's thead p280 element. Can be set, to replace the thead p280 element. If the new value is not a thead p280 element, throws a HIERARCHY_REQUEST_ERR p70 exception. thead = table . createTHead p276 () Ensures the table has a thead p280 element, and returns it. table . deleteTHead p276 () Ensures the table does not have a thead p280 element. table . tFoot p276 [ = value ] Returns the table's tfoot p280 element. Can be set, to replace the tfoot p280 element. If the new value is not a tfoot p280 element, throws a HIERARCHY_REQUEST_ERR p70 exception. tfoot = table . createTFoot p276 () Ensures the table has a tfoot p280 element, and returns it. table . deleteTFoot p276 () Ensures the table does not have a tfoot p280 element. table . tBodies p276 Returns an HTMLCollection p59 of the tbody p279 elements of the table. 275 tbody = table . createTBody p277 () Creates a tbody p279 element, inserts it into the table, and returns it. table . rows p277 Returns an HTMLCollection p59 of the tr p281 elements of the table. tr = table . insertRow p277 (index) Creates a tr p281 element, along with a tbody p279 if required, inserts them into the table at the position given by the argument, and returns the tr p281 . The position is relative to the rows in the table. The index −1 is equivalent to inserting at the end of the table. If the given position is less than −1 or greater than the number of rows, throws an INDEX_SIZE_ERR p70 exception. table . deleteRow p277 (index) Removes the tr p281 element with the given position in the table. The position is relative to the rows in the table. The index −1 is equivalent to deleting the last row of the table. If the given position is less than −1 or greater than the index of the last row, or if there are no rows, throws an INDEX_SIZE_ERR p70 exception. The caption IDL attribute must return, on getting, the first caption p277 element child of the table p271 element, if any, or null otherwise. On setting, if the new value is a caption p277 element, the first caption p277 element child of the table p271 element, if any, must be removed, and the new value must be inserted as the first node of the table p271 element. If the new value is not a caption p277 element, then a HIERARCHY_REQUEST_ERR p70 DOM exception must be raised instead. The createCaption() method must return the first caption p277 element child of the table p271 element, if any; otherwise a new caption p277 element must be created, inserted as the first node of the table p271 element, and then returned. The deleteCaption() method must remove the first caption p277 element child of the table p271 element, if any. The tHead IDL attribute must return, on getting, the first thead p280 element child of the table p271 element, if any, or null otherwise. On setting, if the new value is a thead p280 element, the first thead p280 element child of the table p271 element, if any, must be removed, and the new value must be inserted immediately before the first element in the table p271 element that is neither a caption p277 element nor a colgroup p278 element, if any, or at the end of the table if there are no such elements. If the new value is not a thead p280 element, then a HIERARCHY_REQUEST_ERR p70 DOM exception must be raised instead. The createTHead() method must return the first thead p280 element child of the table p271 element, if any; otherwise a new thead p280 element must be created and inserted immediately before the first element in the table p271 element that is neither a caption p277 element nor a colgroup p278 element, if any, or at the end of the table if there are no such elements, and then that new element must be returned. The deleteTHead() method must remove the first thead p280 element child of the table p271 element, if any. The tFoot IDL attribute must return, on getting, the first tfoot p280 element child of the table p271 element, if any, or null otherwise. On setting, if the new value is a tfoot p280 element, the first tfoot p280 element child of the table p271 element, if any, must be removed, and the new value must be inserted immediately before the first element in the table p271 element that is neither a caption p277 element, a colgroup p278 element, nor a thead p280 element, if any, or at the end of the table if there are no such elements. If the new value is not a tfoot p280 element, then a HIERARCHY_REQUEST_ERR p70 DOM exception must be raised instead. The createTFoot() method must return the first tfoot p280 element child of the table p271 element, if any; otherwise a new tfoot p280 element must be created and inserted immediately before the first element in the table p271 element that is neither a caption p277 element, a colgroup p278 element, nor a thead p280 element, if any, or at the end of the table if there are no such elements, and then that new element must be returned. The deleteTFoot() method must remove the first tfoot p280 element child of the table p271 element, if any. The tBodies attribute must return an HTMLCollection p59 rooted at the table p271 node, whose filter matches only tbody p279 elements that are children of the table p271 element. 276 The createTBody() method must create a new tbody p279 element, insert it immediately after the last tbody p279 element in the table p271 element, if any, or at the end of the table p271 element if the table p271 element has no tbody p279 element children, and then must return the new tbody p279 element. The rows attribute must return an HTMLCollection p59 rooted at the table p271 node, whose filter matches only tr p281 elements that are either children of the table p271 element, or children of thead p280 , tbody p279 , or tfoot p280 elements that are themselves children of the table p271 element. The elements in the collection must be ordered such that those elements whose parent is a thead p280 are included first, in tree order, followed by those elements whose parent is either a table p271 or tbody p279 element, again in tree order, followed finally by those elements whose parent is a tfoot p280 element, still in tree order. The behavior of the insertRow(index) method depends on the state of the table. When it is called, the method must act as required by the first item in the following list of conditions that describes the state of the table and the index argument: p277 collection: ↪ If index is less than −1 or greater than the number of elements in rows The method must raise an INDEX_SIZE_ERR p70 exception. p277 collection has zero elements in it, and the table p271 has no tbody p279 elements in it: ↪ If the rows The method must create a tbody p279 element, then create a tr p281 element, then append the tr p281 element to the tbody p279 element, then append the tbody p279 element to the table p271 element, and finally return the tr p281 element. p277 collection has zero elements in it: ↪ If the rows The method must create a tr p281 element, append it to the last tbody p279 element in the table, and return the tr p281 element. p277 collection: ↪ If index is missing, equal to −1, or equal to the number of items in rows The method must create a tr p281 element, and append it to the parent of the last tr p281 element in the rows p277 collection. Then, the newly created tr p281 element must be returned. ↪ Otherwise: The method must create a tr p281 element, insert it immediately before the indexth tr p281 element in the rows p277 collection, in the same parent, and finally must return the newly created tr p281 element. When the deleteRow(index) method is called, the user agent must run the following steps: 1. If index is equal to −1, then index must be set to the number if items in the rows p277 collection, minus one. 2. Now, if index is less than zero, or greater than or equal to the number of elements in the rows p277 collection, the method must instead raise an INDEX_SIZE_ERR p70 exception, and these steps must be aborted. 3. Otherwise, the method must remove the indexth element in the rows p277 collection from its parent. The summary IDL attribute must reflect p57 the content attribute of the same name. 4.9.2 The caption element Categories None. Contexts in which this element may be used: As the first element child of a table p271 element. Content model: Flow content p91 , but with no descendant table p271 elements. Content attributes: Global attributes p82 DOM interface: interface HTMLTableCaptionElement : HTMLElement {}; The caption p277 element represents p638 the title of the table p271 that is its parent, if it has a parent and that is a table p271 element. The caption p277 element takes part in the table model p285 . 277 When a table p271 element is the only content in a figure p158 element other than the figcaption p159 , the caption p277 element should be omitted in favor of the figcaption p159 . A caption can introduce context for a table, making it significantly easier to understand. Consider, for instance, the following table: 1 2 3 4 5 6 1 2 3 4 5 6 7 2 3 4 5 6 7 8 3 4 5 6 7 8 9 4 5 6 5 6 7 6 7 8 7 8 9 8 9 10 9 1011 101112 In the abstract, this table is not clear. However, with a caption giving the table's number (for reference in the main prose) and explaining its use, it makes more sense:

    Table 1.

    This table shows the total score obtained from rolling two six-sided dice. The first row represents the value of the first die, the first column the value of the second die. The total is given in the cell that corresponds to the values of the two dice. This provides the user with more context: Table 1. This table shows the total score obtained from rolling two six-sided dice. The first row represents the value of the first die, the first column the value of the second die. The total is given in the cell that corresponds to the values of the two dice. 1 2 3 4 5 6 1 2 3 4 5 6 7 2 3 4 5 6 7 8 3 4 5 6 7 8 9 4 5 6 5 6 7 6 7 8 7 8 9 8 9 10 9 1011 101112 4.9.3 The colgroup element Categories None. Contexts in which this element may be used: As a child of a table p271 element, after any caption p277 elements and before any thead p280 , tbody p279 , tfoot p280 , and tr p281 elements. Content model: If the span p278 attribute is present: Empty. If the span p278 attribute is absent: Zero or more col p279 elements. Content attributes: Global attributes p82 span p278 DOM interface: interface HTMLTableColElement : HTMLElement { attribute unsigned long span; }; The colgroup p278 element represents p638 a group p285 of one or more columns p285 in the table p271 that is its parent, if it has a parent and that is a table p271 element. If the colgroup p278 element contains no col p279 elements, then the element may have a span content attribute specified, whose value must be a valid non-negative integer p35 greater than zero. The colgroup p278 element and its span p278 attribute take part in the table model p285 . 278 The span IDL attribute must reflect p57 the content attribute of the same name. The value must be limited to only non-negative numbers greater than zero p58 . 4.9.4 The col element Categories None. Contexts in which this element may be used: As a child of a colgroup p278 element that doesn't have a span p279 attribute. Content model: Empty. Content attributes: Global attributes p82 span p279 DOM interface: HTMLTableColElement p278 , same as for colgroup p278 elements. This interface defines one member, span p279 . If a col p279 element has a parent and that is a colgroup p278 element that itself has a parent that is a table p271 element, then the col p279 element represents p638 one or more columns p285 in the column group p285 represented by that colgroup p278 . The element may have a span content attribute specified, whose value must be a valid non-negative integer p35 greater than zero. The col p279 element and its span p279 attribute take part in the table model p285 . The span IDL attribute must reflect p57 the content attribute of the same name. The value must be limited to only non-negative numbers greater than zero p58 . 4.9.5 The tbody element Categories None. Contexts in which this element may be used: As a child of a table p271 element, after any caption p277 , colgroup p278 , and thead p280 elements, but only if there are no tr p281 elements that are children of the table p271 element. Content model: Zero or more tr p281 elements Content attributes: Global attributes p82 DOM interface: interface HTMLTableSectionElement : HTMLElement { readonly attribute HTMLCollection rows; HTMLElement insertRow(in optional long index); void deleteRow(in long index); }; The HTMLTableSectionElement p279 interface is also used for thead p280 and tfoot p280 elements. The tbody p279 element represents p638 a block p285 of rows p285 that consist of a body of data for the parent table p271 element, if the tbody p279 element has a parent and it is a table p271 . The tbody p279 element takes part in the table model p285 . This box is non-normative. Implementation requirements are given below this box. tbody . rows p280 Returns an HTMLCollection p59 of the tr p281 elements of the table section. 279 tr = tbody . insertRow p280 ( [ index ] ) Creates a tr p281 element, inserts it into the table section at the position given by the argument, and returns the tr p281 . The position is relative to the rows in the table section. The index −1, which is the default if the argument is omitted, is equivalent to inserting at the end of the table section. If the given position is less than −1 or greater than the number of rows, throws an INDEX_SIZE_ERR p70 exception. tbody . deleteRow p280 (index) Removes the tr p281 element with the given position in the table section. The position is relative to the rows in the table section. The index −1 is equivalent to deleting the last row of the table section. If the given position is less than −1 or greater than the index of the last row, or if there are no rows, throws an INDEX_SIZE_ERR p70 exception. The rows attribute must return an HTMLCollection p59 rooted at the element, whose filter matches only tr p281 elements that are children of the element. The insertRow(index) method must, when invoked on an element table section, act as follows: If index is less than −1 or greater than the number of elements in the rows p280 collection, the method must raise an INDEX_SIZE_ERR p70 exception. If index is missing, equal to −1, or equal to the number of items in the rows p280 collection, the method must create a tr p281 element, append it to the element table section, and return the newly created tr p281 element. Otherwise, the method must create a tr p281 element, insert it as a child of the table section element, immediately before the indexth tr p281 element in the rows p280 collection, and finally must return the newly created tr p281 element. The deleteRow(index) method must remove the indexth element in the rows p280 collection from its parent. If index is less than zero or greater than or equal to the number of elements in the rows p280 collection, the method must instead raise an INDEX_SIZE_ERR p70 exception. 4.9.6 The thead element Categories None. Contexts in which this element may be used: As a child of a table p271 element, after any caption p277 , and colgroup p278 elements and before any tbody p279 , tfoot p280 , and tr p281 elements, but only if there are no other thead p280 elements that are children of the table p271 element. Content model: Zero or more tr p281 elements Content attributes: Global attributes p82 DOM interface: HTMLTableSectionElement p279 , as defined for tbody p279 elements. The thead p280 element represents p638 the block p285 of rows p285 that consist of the column labels (headers) for the parent table p271 element, if the thead p280 element has a parent and it is a table p271 . The thead p280 element takes part in the table model p285 . 4.9.7 The tfoot element Categories None. 280 Contexts in which this element may be used: As a child of a table p271 element, after any caption p277 , colgroup p278 , and thead p280 elements and before any tbody p279 and tr p281 elements, but only if there are no other tfoot p280 elements that are children of the table p271 element. As a child of a table p271 element, after any caption p277 , colgroup p278 , thead p280 , tbody p279 , and tr p281 elements, but only if there are no other tfoot p280 elements that are children of the table p271 element. Content model: Zero or more tr p281 elements Content attributes: Global attributes p82 DOM interface: HTMLTableSectionElement p279 , as defined for tbody p279 elements. The tfoot p280 element represents p638 the block p285 of rows p285 that consist of the column summaries (footers) for the parent table p271 element, if the tfoot p280 element has a parent and it is a table p271 . The tfoot p280 element takes part in the table model p285 . 4.9.8 The tr element Categories None. Contexts in which this element may be used: As a child of a thead p280 As a child of a tbody p279 As a child of a tfoot p280 As a child of a table p271 if there are no tbody p279 element. element. element. element, after any caption p277 , colgroup p278 , and thead p280 elements, but only elements that are children of the table p271 element. Content model: When the parent node is a thead p280 element: Zero or more th p283 elements Otherwise: Zero or more td p282 or th p283 elements Content attributes: Global attributes p82 DOM interface: interface HTMLTableRowElement : HTMLElement { readonly attribute long rowIndex; readonly attribute long sectionRowIndex; readonly attribute HTMLCollection cells; HTMLElement insertCell(in optional long index); void deleteCell(in long index); }; The tr p281 element represents p638 a row p285 of cells p285 in a table p285 . The tr p281 element takes part in the table model p285 . This box is non-normative. Implementation requirements are given below this box. tr . rowIndex p282 Returns the position of the row in the table's rows p277 list. Returns −1 if the element isn't in a table. tr . sectionRowIndex p282 Returns the position of the row in the table section's rows p280 list. Returns −1 if the element isn't in a table section. 281 tr . cells p282 Returns an HTMLCollection p59 of the td p282 and th p283 elements of the row. cell = tr . insertCell p282 ( [ index ] ) Creates a td p282 element, inserts it into the table row at the position given by the argument, and returns the td p282 . The position is relative to the cells in the row. The index −1, which is the default if the argument is omitted, is equivalent to inserting at the end of the row. If the given position is less than −1 or greater than the number of cells, throws an INDEX_SIZE_ERR p70 exception. tr . deleteCell p282 (index) Removes the td p282 or th p283 element with the given position in the row. The position is relative to the cells in the row. The index −1 is equivalent to deleting the last cell of the row. If the given position is less than −1 or greater than the index of the last cell, or if there are no cells, throws an INDEX_SIZE_ERR p70 exception. The rowIndex attribute must, if the element has a parent table p271 element, or a parent tbody p279 , thead p280 , or tfoot p280 element and a grandparent table p271 element, return the index of the tr p281 element in that table p271 element's rows p277 collection. If there is no such table p271 element, then the attribute must return −1. The sectionRowIndex attribute must, if the element has a parent table p271 , tbody p279 , thead p280 , or tfoot p280 element, return the index of the tr p281 element in the parent element's rows collection (for tables, that's the HTMLTableElement.rows p277 collection; for table sections, that's the HTMLTableRowElement.rows p280 collection). If there is no such parent element, then the attribute must return −1. The cells attribute must return an HTMLCollection p59 rooted at the tr p281 element, whose filter matches only td p282 and th p283 elements that are children of the tr p281 element. The insertCell(index) method must act as follows: If index is less than −1 or greater than the number of elements in the cells p282 collection, the method must raise an INDEX_SIZE_ERR p70 exception. If index is missing, equal to −1, or equal to the number of items in cells p282 collection, the method must create a td p282 element, append it to the tr p281 element, and return the newly created td p282 element. Otherwise, the method must create a td p282 element, insert it as a child of the tr p281 element, immediately before the indexth td p282 or th p283 element in the cells p282 collection, and finally must return the newly created td p282 element. The deleteCell(index) method must remove the indexth element in the cells p282 collection from its parent. If index is less than zero or greater than or equal to the number of elements in the cells p282 collection, the method must instead raise an INDEX_SIZE_ERR p70 exception. 4.9.9 The td element Categories Sectioning root p144 . Contexts in which this element may be used: As a child of a tr p281 element. Content model: Flow content p91 . Content attributes: Global attributes p82 colspan p284 rowspan p284 headers p284 DOM interface: interface HTMLTableDataCellElement : HTMLTableCellElement {}; 282 The td p282 element represents p638 a data cell p285 in a table. The td p282 element and its colspan p284 , rowspan p284 , and headers p284 attributes take part in the table model p285 . 4.9.10 The th element Categories None. Contexts in which this element may be used: As a child of a tr p281 element. Content model: Phrasing content p91 . Content attributes: Global attributes p82 colspan p284 rowspan p284 headers p284 scope p283 DOM interface: interface HTMLTableHeaderCellElement : HTMLTableCellElement { attribute DOMString scope; }; The th p283 element represents p638 a header cell p285 in a table. The th p283 element may have a scope content attribute specified. The scope p283 attribute is an enumerated attribute p34 with five states, four of which have explicit keywords: The row keyword, which maps to the row state The row state means the header cell applies to some of the subsequent cells in the same row(s). The col keyword, which maps to the column state The column state means the header cell applies to some of the subsequent cells in the same column(s). The rowgroup keyword, which maps to the row group state The row group state means the header cell applies to all the remaining cells in the row group. A th p283 element's scope p283 attribute must not be in the row group p283 state if the element is not anchored in a row group p285 . The colgroup keyword, which maps to the column group state The column group state means the header cell applies to all the remaining cells in the column group. A th p283 element's scope p283 attribute must not be in the column group p283 state if the element is not anchored in a column group p285 . The auto state The auto state makes the header cell apply to a set of cells selected based on context. The scope p283 attribute's missing value default is the auto state. The th p283 element and its colspan p284 , rowspan p284 , headers p284 , and scope p283 attributes take part in the table model p285 . The scope IDL attribute must reflect p57 the content attribute of the same name. The following example shows how the scope p283 attribute's rowgroup p283 value affects which data cells a header cell applies to. Here is a markup fragment showing a table:
    ID Measurement Average Maximum Cats 93 Legs 3.5 4 10 Tails 1 1 English speakers 283
    32 Legs 2.67 4
    35 Tails 0.33 1
    This would result in the following table: ID Measurement Average Maximum Cats 93 Legs 3.5 4 10 Tails 1 1 32 Legs 2.67 4 35 Tails 0.33 1 English speakers The headers in the first row all apply directly down to the rows in their column. The headers with the explicit scope p283 attributes apply to all the cells in their row group other than the cells in the first column. The remaining headers apply just to the cells to the right of them. 4.9.11 Attributes common to td p282 and th p283 elements The td p282 and th p283 elements may have a colspan content attribute specified, whose value must be a valid nonnegative integer p35 greater than zero. The td p282 and th p283 elements may also have a rowspan content attribute specified, whose value must be a valid non-negative integer p35 . These attributes give the number of columns and rows respectively that the cell is to span. These attributes must not be used to overlap cells, as described in the description of the table model p285 . The td p282 and th p283 element may have a headers content attribute specified. The headers p284 attribute, if specified, must contain a string consisting of an unordered set of unique space-separated tokens p49 , each of which must have the value of an ID of a th p283 element taking part in the same table p285 as the td p282 or th p283 element (as defined by the table model p285 ). A th p283 element with ID id is said to be directly targeted by all td p282 and th p283 elements in the same table p285 that have headers p284 attributes whose values include as one of their tokens the ID id. A th p283 element A is said to be targeted by a th p283 or td p282 element B if either A is directly targeted by B or if there exists an element C that is itself targeted by the element B and A is directly targeted by C. A th p283 element must not be targeted by itself. The colspan p284 , rowspan p284 , and headers p284 attributes take part in the table model p285 . 284 The td p282 and th p283 elements implement interfaces that inherit from the HTMLTableCellElement p285 interface: interface HTMLTableCellElement : HTMLElement { attribute unsigned long colSpan; attribute unsigned long rowSpan; [PutForwards=value] readonly attribute DOMSettableTokenList headers; readonly attribute long cellIndex; }; This box is non-normative. Implementation requirements are given below this box. cell . cellIndex p285 Returns the position of the cell in the row's cells p282 list. This does not necessarily correspond to the x-position of the cell in the table, since earlier cells might cover multiple rows or columns. Returns 0 if the element isn't in a row. The colSpan IDL attribute must reflect p57 the content attribute of the same name. The value must be limited to only non-negative numbers greater than zero p58 . The rowSpan IDL attribute must reflect p57 the content attribute of the same name. Its default value, which must be used if parsing the attribute as a non-negative integer p35 returns an error, is 1. The headers IDL attribute must reflect p57 the content attribute of the same name. The cellIndex IDL attribute must, if the element has a parent tr p281 element, return the index of the cell's element in the parent element's cells p282 collection. If there is no such parent element, then the attribute must return 0. 4.9.12 Processing model The various table elements and their content attributes together define the table model. A table consists of cells aligned on a two-dimensional grid of slots with coordinates (x, y). The grid is finite, and is either empty or has one or more slots. If the grid has one or more slots, then the x coordinates are always in the range 0 ≤ x < xwidth, and the y coordinates are always in the range 0 ≤ y < yheight. If one or both of xwidth and yheight are zero, then the table is empty (has no slots). Tables correspond to table p271 elements. A cell is a set of slots anchored at a slot (cellx, celly), and with a particular width and height such that the cell covers all the slots with coordinates (x, y) where cellx ≤ x < cellx+width and celly ≤ y < celly+height. Cells can either be data cells or header cells. Data cells correspond to td p282 elements, and header cells correspond to th p283 elements. Cells of both types can have zero or more associated header cells. It is possible, in certain error cases, for two cells to occupy the same slot. A row is a complete set of slots from x=0 to x=xwidth-1, for a particular value of y. Rows correspond to tr p281 elements. A column is a complete set of slots from y=0 to y=yheight-1, for a particular value of x. Columns can correspond to col p279 elements. In the absence of col p279 elements, columns are implied. A row group is a set of rows p285 anchored at a slot (0, groupy) with a particular height such that the row group covers all the slots with coordinates (x, y) where 0 ≤ x < xwidth and groupy ≤ y < groupy+height. Row groups correspond to tbody p279 , thead p280 , and tfoot p280 elements. Not every row is necessarily in a row group. A column group is a set of columns p285 anchored at a slot (groupx, 0) with a particular width such that the column group covers all the slots with coordinates (x, y) where groupx ≤ x < groupx+width and 0 ≤ y < yheight. Column groups correspond to colgroup p278 elements. Not every column is necessarily in a column group. Row groups p285 cannot overlap each other. Similarly, column groups p285 cannot overlap each other. A cell p285 cannot cover slots that are from two or more row groups p285 . It is, however, possible for a cell to be in multiple column groups p285 . All the slots that form part of one cell are part of zero or one row groups p285 and zero or more column groups p285 . In addition to cells p285 , columns p285 , rows p285 , row groups p285 , and column groups p285 , tables p285 can have a caption p277 element associated with them. This gives the table a heading, or legend. A table model error is an error with the data represented by table p271 elements and their descendants. Documents must not have table model errors. 285 4.9.12.1 Forming a table To determine which elements correspond to which slots in a table p285 associated with a table p271 element, to determine the dimensions of the table (xwidth and yheight), and to determine if there are any table model errors p285 , user agents must use the following algorithm: 1. Let xwidth be zero. 2. Let yheight be zero. 3. Let pending tfoot p280 elements be a list of tfoot p280 elements, initially empty. 4. Let the table be the table p285 represented by the table p271 element. The xwidth and yheight variables give the table's dimensions. The table is initially empty. 5. If the table p271 element has no children elements, then return the table (which will be empty), and abort these steps. 6. Associate the first caption p277 element child of the table p271 element with the table. If there are no such children, then it has no associated caption p277 element. 7. Let the current element be the first element child of the table p271 element. If a step in this algorithm ever requires the current element to be advanced to the next child of the table when there is no such next child, then the user agent must jump to the step labeled end, near the end of this algorithm. 8. While the current element is not one of the following elements, advance p286 the current element to the next child of the table p271 : • • • • • 9. colgroup p278 thead p280 tbody p279 tfoot p280 tr p281 If the current element is a colgroup p278 , follow these substeps: 1. Column groups: Process the current element according to the appropriate case below: p279 element children ↪ If the current element has any col Follow these steps: 1. Let xstart have the value of xwidth. 2. Let the current column be the first col p279 element child of the colgroup p278 element. 3. Columns: If the current column col p279 element has a span p279 attribute, then parse its value using the rules for parsing non-negative integers p35 . If the result of parsing the value is not an error or zero, then let span be that value. Otherwise, if the col p279 element has no span p279 attribute, or if trying to parse the attribute's value resulted in an error or zero, then let span be 1. 4. Increase xwidth by span. 5. Let the last span columns p285 in the table correspond to the current column col p279 element. 6. If current column is not the last col p279 element child of the colgroup p278 element, then let the current column be the next col p279 element child of the colgroup p278 element, and return to the step labeled columns. 7. Let all the last columns p285 in the table from x=xstart to x=xwidth-1 form a new column group p285 , anchored at the slot (xstart, 0), with width xwidth-xstart, corresponding to the colgroup p278 element. p279 element children ↪ If the current element has no col 1. 286 If the colgroup p278 element has a span p278 attribute, then parse its value using the rules for parsing non-negative integers p35 . If the result of parsing the value is not an error or zero, then let span be that value. Otherwise, if the colgroup p278 element has no span p278 attribute, or if trying to parse the attribute's value resulted in an error or zero, then let span be 1. 2. Increase xwidth by span. 3. Let the last span columns p285 in the table form a new column group p285 , anchored at the slot (xwidth-span, 0), with width span, corresponding to the colgroup p278 element. 2. Advance p286 the current element to the next child of the table p271 . 3. While the current element is not one of the following elements, advance p286 the current element to the next child of the table p271 : • • • • • 4. colgroup p278 thead p280 tbody p279 tfoot p280 tr p281 If the current element is a colgroup p278 element, jump to the step labeled column groups above. 10. Let ycurrent be zero. 11. Let the list of downward-growing cells be an empty list. 12. Rows: While the current element is not one of the following elements, advance p286 the current element to the next child of the table p271 : • • • • thead p280 tbody p279 tfoot p280 tr p281 13. If the current element is a tr p281 , then run the algorithm for processing rows p288 , advance p286 the current element to the next child of the table p271 , and return to the step labeled rows. 14. Run the algorithm for ending a row group p288 . 15. If the current element is a tfoot p280 , then add that element to the list of pending tfoot p280 elements, advance p286 the current element to the next child of the table p271 , and return to the step labeled rows. 16. The current element is either a thead p280 or a tbody p279 . Run the algorithm for processing row groups p287 . 17. Advance p286 the current element to the next child of the table p271 . 18. Return to the step labeled rows. 19. End: For each tfoot p280 element in the list of pending tfoot p280 elements, in tree order, run the algorithm for processing row groups p287 . 20. If there exists a row p285 or column p285 in the table containing only slots p285 that do not have a cell p285 anchored to them, then this is a table model error p285 . 21. Return the table. The algorithm for processing row groups, which is invoked by the set of steps above for processing thead p280 , tbody p279 , and tfoot p280 elements, is: 1. Let ystart have the value of yheight. 2. For each tr p281 element that is a child of the element being processed, in tree order, run the algorithm for processing rows p288 . 3. If yheight > ystart, then let all the last rows p285 in the table from y=ystart to y=yheight-1 form a new row group p285 , anchored at the slot with coordinate (0, ystart), with height yheight-ystart, corresponding to the element being processed. 4. Run the algorithm for ending a row group p288 . 287 The algorithm for ending a row group, which is invoked by the set of steps above when starting and ending a block of rows, is: 1. 2. While ycurrent is less than yheight, follow these steps: 1. Run the algorithm for growing downward-growing cells p288 . 2. Increase ycurrent by 1. Empty the list of downward-growing cells. The algorithm for processing rows, which is invoked by the set of steps above for processing tr p281 elements, is: 1. If yheight is equal to ycurrent, then increase yheight by 1. (ycurrent is never greater than yheight.) 2. Let xcurrent be 0. 3. Run the algorithm for growing downward-growing cells p288 . 4. If the tr p281 element being processed has no td p282 or th p283 element children, then increase ycurrent by 1, abort this set of steps, and return to the algorithm above. 5. Let current cell be the first td p282 or th p283 element in the tr p281 element being processed. 6. Cells: While xcurrent is less than xwidth and the slot with coordinate (xcurrent, ycurrent) already has a cell assigned to it, increase xcurrent by 1. 7. If xcurrent is equal to xwidth, increase xwidth by 1. (xcurrent is never greater than xwidth.) 8. If the current cell has a colspan p284 attribute, then parse that attribute's value p35 , and let colspan be the result. If parsing that value failed, or returned zero, or if the attribute is absent, then let colspan be 1, instead. 9. If the current cell has a rowspan p284 attribute, then parse that attribute's value p35 , and let rowspan be the result. If parsing that value failed or if the attribute is absent, then let rowspan be 1, instead. 10. If rowspan is zero, then let cell grows downward be true, and set rowspan to 1. Otherwise, let cell grows downward be false. 11. If xwidth < xcurrent+colspan, then let xwidth be xcurrent+colspan. 12. If yheight < ycurrent+rowspan, then let yheight be ycurrent+rowspan. 13. Let the slots with coordinates (x, y) such that xcurrent ≤ x < xcurrent+colspan and ycurrent ≤ y < ycurrent+rowspan be covered by a new cell p285 c, anchored at (xcurrent, ycurrent), which has width colspan and height rowspan, corresponding to the current cell element. If the current cell element is a th p283 element, let this new cell c be a header cell; otherwise, let it be a data cell. To establish which header cells apply to the current cell element, use the algorithm for assigning header cells p289 described in the next section. If any of the slots involved already had a cell p285 covering them, then this is a table model error p285 . Those slots now have two cells overlapping. 14. If cell grows downward is true, then add the tuple {c, xcurrent, colspan} to the list of downward-growing cells. 15. Increase xcurrent by colspan. 16. If current cell is the last td p282 or th p283 element in the tr p281 element being processed, then increase ycurrent by 1, abort this set of steps, and return to the algorithm above. 17. Let current cell be the next td p282 or th p283 element in the tr p281 element being processed. 18. Return to the step labelled cells. When the algorithms above require the user agent to run the algorithm for growing downward-growing cells, the user agent must, for each {cell, cellx, width} tuple in the list of downward-growing cells, if any, extend the cell p285 cell so that it also covers the slots with coordinates (x, ycurrent), where cellx ≤ x < cellx+width. 288 4.9.12.2 Forming relationships between data cells and header cells Each cell can be assigned zero or more header cells. The algorithm for assigning header cells to a cell principal cell is as follows. 1. Let header list be an empty list of cells. 2. Let (principalx, principaly) be the coordinate of the slot to which the principal cell is anchored. 3.↪ If the principal cell has a headers p284 attribute specified 1. Take the value of the principal cell's headers p284 attribute and split it on spaces p49 , letting id list be the list of tokens obtained. 2. For each token in the id list, if the first element in the Document p31 with an ID equal to the token is a cell in the same table p285 , and that cell is not the principal cell, then add that cell to header list. p284 attribute specified ↪ If principal cell does not have a headers 1. Let principalwidth be the width of the principal cell. 2. Let principalheight be the height of the principal cell. 3. For each value of y from principaly to principaly+principalheight-1, run the internal algorithm for scanning and assigning header cells p289 , with the principal cell, the header list, the initial coordinate (principalx,y), and the increments Δx=−1 and Δy=0. 4. For each value of x from principalx to principalx+principalwidth-1, run the internal algorithm for scanning and assigning header cells p289 , with the principal cell, the header list, the initial coordinate (x,principaly), and the increments Δx=0 and Δy=−1. 5. If the principal cell is anchored in a row group p285 , then add all header cells that are row group headers p290 and are anchored in the same row group with an x-coordinate less than or equal to principalx+principalwidth-1 and a y-coordinate less than or equal to principaly+principalheight-1 to header list. 6. If the principal cell is anchored in a column group p285 , then add all header cells that are column group headers p290 and are anchored in the same column group with an xcoordinate less than or equal to principalx+principalwidth-1 and a y-coordinate less than or equal to principaly+principalheight-1 to header list. 4. Remove all the empty cells p290 from the header list. 5. Remove any duplicates from the header list. 6. Remove principal cell from the header list if it is there. 7. Assign the headers in the header list to the principal cell. The internal algorithm for scanning and assigning header cells, given a principal cell, a header list, an initial coordinate (initialx, initialy), and Δx and Δy increments, is as follows: 1. Let x equal initialx. 2. Let y equal initialy. 3. Let opaque headers be an empty list of cells. 4.↪ If principal cell is a header cell Let in header block be true, and let headers from current header block be a list of cells containing just the principal cell. ↪ Otherwise Let in header block be false and let headers from current header block be an empty list of cells. 5. Loop: Increment x by Δx; increment y by Δy. Note: For each invocation of this algorithm, one of Δx and Δy will be −1, and the other will be 0. 6. If either x or y is less than 0, then abort this internal algorithm. 289 7. If there is no cell covering slot (x, y), or if there is more than one cell covering slot (x, y), return to the substep labeled loop. 8. Let current cell be the cell covering slot (x, y). 9.↪ If current cell is a header cell 1. Set in header block to true. 2. Add current cell to headers from current header block. 3. Let blocked be false. 4.↪ If Δx is 0 If there are any cells in the opaque headers list anchored with the same xcoordinate as the current cell, and with the same width as current cell, then let blocked be true. If the current cell is not a column header p290 , then let blocked be true. ↪ If Δy is 0 If there are any cells in the opaque headers list anchored with the same ycoordinate as the current cell, and with the same height as current cell, then let blocked be true. If the current cell is not a row header p290 , then let blocked be true. 5. If blocked is false, then add the current cell to the headers list. ↪ If current cell is a data cell and in header block is true Set in header block to false. Add all the cells in headers from current header block to the opaque headers list, and empty the headers from current header block list. 10. Return to the step labeled loop. A header cell anchored at the slot with coordinate (x, y) with width width and height height is said to be a column header if any of the following conditions are true: • The cell's scope p283 attribute is in the column p283 state, or • The cell's scope p283 attribute is in the auto p283 state, and there are no data cells in any of the cells covering slots with y-coordinates y .. y+height-1. A header cell anchored at the slot with coordinate (x, y) with width width and height height is said to be a row header if any of the following conditions are true: • The cell's scope p283 attribute is in the row p283 state, or • The cell's scope p283 attribute is in the auto p283 state, the cell is not a column header p290 , and there are no data cells in any of the cells covering slots with x-coordinates x .. x+width-1. A header cell is said to be a column group header if its scope p283 attribute is in the column group p283 state. A header cell is said to be a row group header if its scope p283 attribute is in the row group p283 state. A cell is said to be an empty cell if it contains no elements and its text content, if any, consists only of White_Space p34 characters. 4.9.13 Examples This section is non-normative. The following shows how might one mark up the bottom part of table 45 of the Smithsonian physical tables, Volume 71: 290
    Specification values: Steel, Castings, Ann. A.S.T.M. A27-16, Class B;* P max. 0.06; S max. 0.05.
    Grade. Yield Point. Ultimate tensile strength Per cent elong. 50.8mm or 2 in. Per cent reduct. area.
    kg/mm2 lb/in2
    Hard 0.45 ultimate 56.2 80,000 15 20
    Medium 0.45 ultimate 49.2 70,000 18 25
    Soft 0.45 ultimate 42.2 60,000 22 30
    This table could look like this: Specification values: Steel, Castings, Ann. A.S.T.M. A27-16, Class B;* P max. 0.06; S max. 0.05. Grade. Hard . . . . . Medium . . . . Soft . . . . . . Yield Point. 0.45 ultimate 0.45 ultimate 0.45 ultimate Ultimate tensile strength kg/mm 56.2 49.2 42.2 2 lb/in 2 80,000 70,000 60,000 Per cent elong. 50.8 mm or 2 in. Per cent reduct. area. 15 18 22 20 25 30 The following shows how one might mark up the gross margin table on page 46 of Apple, Inc's 10-K filing for fiscal year 2008:
    2008 2007 2006
    Net sales $ 32,479 $ 24,006 $ 19,315
    Cost of sales 21,334 15,852 13,717
    Gross margin $ 11,145 $ 8,154 291 $ 5,598
    Gross margin percentage 34.3% 34.0% 29.0%
    This table could look like this: 2008 2007 2006 Net sales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Cost of sales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Gross margin . . . . . . . . . . . . . . . . . . . . . . . . . . . . $ 32,479 21,334 $ 11,145 $ 24,006 15,852 $ 8,154 $ 19,315 13,717 $ 5,598 Gross margin percentage . . . . . . . . . . . . . . . . . . . 34.3% 34.0% 29.0% The following shows how one might mark up the operating expenses table from lower on the same page of that document:
    2008 2007 2006
    Research and development $ 1,109 $ 782 $ 712
    Percentage of net sales 3.4% 3.3% 3.7%
    Selling, general, and administrative $ 3,761 $ 2,963 $ 2,433
    Percentage of net sales 11.6% 12.3% 12.6%
    This table could look like this: Research and development . . . . . . . . . . . . . . . . . . . . . Percentage of net sales . . . . . . . . . . . . . . . . . . . . . . Selling, general, and administrative . . . . . . . . . . . . . . Percentage of net sales . . . . . . . . . . . . . . . . . . . . . . 2008 2007 2006 $ 1,109 3.4% $ 3,761 11.6% $ 782 3.3% $ 2,963 12.3% $ 712 3.7% $ 2,433 12.6% 4.10 Forms 4.10.1 Introduction This section is non-normative. Forms allow unscripted client-server interaction: given a form, a user can provide data, submit it to the server, and have the server act on it accordingly (e.g. returning the results of a search or calculation). The elements used in forms can also be used for user interaction with no associated submission mechanism, in conjunction with scripts. Writing a form consists of several steps, which can be performed in any order: writing the user interface, implementing the server-side processing, and configuring the user interface to communicate with the server. 4.10.1.1 Writing a form's user interface This section is non-normative. For the purposes of this brief introduction, we will create a pizza ordering form. Any form starts with a form p297 element, inside which are placed the controls. Most controls are represented by the input p303 element, which by default provides a one-line text field. To label a control, the label p301 element is used; the label text and the control itself go inside the label p301 element. Each part of a form is considered a paragraph p93 , and is typically separated from other parts using p p148 elements. Putting this together, here is how one might ask for the customer's name:

    292 To let the user select the size of the pizza, we can use a set of radio buttons. Radio buttons also use the input p303 element, this time with a type p304 attribute with the value radio p319 . To make the radio buttons work as a group, they are given a common name using the name p354 attribute. To group a batch of controls together, such as, in this case, the radio buttons, one can use the fieldset p300 element. The title of such a group of controls is given by the first element in the fieldset p300 , which has to be a legend p301 element.

    Pizza Size

    Note: Changes from the previous step are highlighted. To pick toppings, we can use checkboxes. These use the input p303 element with a type p304 attribute with the value checkbox p318 :

    Pizza Size

    Pizza Toppings

    The pizzeria for which this form is being written is always making mistakes, so it needs a way to contact the customer. For this purpose, we can use form controls specifically for telephone numbers (input p303 elements with their type p304 attribute set to tel p308 ) and e-mail addresses (input p303 elements with their type p304 attribute set to email p309 ):

    Pizza Size

    Pizza Toppings

    We can use an input p303 element with its type p304 attribute set to time p314 to ask for a delivery time. Many of these form controls have attributes to control exactly what values can be specified; in this case, three attributes of particular interest are min p328 , max p328 , and step p329 . These set the minimum time, the maximum time, and the interval between allowed values (in seconds). This pizzeria only delivers between 11am and 9pm, and doesn't promise anything better than 15 minute increments, which we can mark up as follows:

    293
    Pizza Size

    Pizza Toppings

    The textarea p341 element can be used to provide a free-form text field. In this instance, we are going to use it to provide a space for the customer to give delivery instructions:

    Pizza Size

    Pizza Toppings

    Finally, to make the form submittable we use the button p332 element:

    Pizza Size

    Pizza Toppings

    4.10.1.2 Implementing the server-side processing for a form This section is non-normative. 294 The exact details for writing a server-side processor are out of scope for this specification. For the purposes of this introduction, we will assume that the script at https://pizza.example.com/order.cgi is configured to accept submissions using the application/x-www-form-urlencoded p356 format, expecting the following parameters sent in an HTTP POST body: custname Customer's name custtel Customer's telephone number custemail Customer's e-mail address size The pizza size, either small, medium, or large toppings The topping, specified once for each selected topping, with the allowed values being bacon, cheese, onion, and mushroom delivery The requested delivery time comments The delivery instructions 4.10.1.3 Configuring a form to communicate with a server This section is non-normative. Form submissions are exposed to servers in a variety of ways, most commonly as HTTP GET or POST requests. To specify the exact method used, the method p355 attribute is specified on the form p297 element. This doesn't specify how the form data is encoded, though; to specify that, you use the enctype p356 attribute. You also have to specify the URL p51 of the service that will handle the submitted data, using the action p355 attribute. For each form control you want submitted, you then have to give a name that will be used to refer to the data in the submission. We already specified the name for the group of radio buttons; the same attribute (name p354 ) also specifies the submission name. Radio buttons can be distinguished from each other in the submission by giving them different values, using the value p306 attribute. Multiple controls can have the same name; for example, here we give all the checkboxes the same name, and the server distinguishes which checkbox was checked by seeing which values are submitted with that name — like the radio buttons, they are also given unique values with the value p306 attribute. Given the settings in the previous section, this all becomes:

    Pizza Size

    Pizza Toppings

    295 For example, if the customer entered "Denise Lawrence" as their name, "555-321-8642" as their telephone number, did not specify an e-mail address, asked for a medium-sized pizza, selected the Extra Cheese and Mushroom toppings, entered a delivery time of 7pm, and left the delivery instructions text field blank, the user agent would submit the following to the online Web service: custname=Denise+Lawrence&custtel=555-321-8624&custemail=&size=medium&topping=cheese&topping=mushroom& 4.10.1.4 Client-side form validation This section is non-normative. Forms can be annotated in such a way that the user agent will check the user's input before the form is submitted. The server still has to verify the input is valid (since hostile users can easily bypass the form validation), but it allows the user to avoid the wait incurred by having the server be the sole checker of the user's input. The simplest annotation is the required p326 attribute, which can be specified on input p303 elements to indicate that the form is not to be submitted until a value is given. By adding this attribute to the customer name and delivery time fields, we allow the user agent to notify the user when the user submits the form without filling in those fields:

    Pizza Size

    Pizza Toppings

    It is also possible to limit the length of the input, using the maxlength p355 attribute. By adding this to the textarea p341 element, we can limit users to 1000 characters, preventing them from writing huge essays to the busy delivery drivers instead of staying focused and to the point:

    Pizza Size

    Pizza Toppings

    296

    4.10.2 Categories Mostly for historical reasons, elements in this section fall into several overlapping (but subtly different) categories in addition to the usual ones like flow content p91 , phrasing content p91 , and interactive content p92 . A number of the elements are form-associated elements, which means they can have a form owner p353 and, to expose this, have a form p353 content attribute with a matching form p354 IDL attribute. ⇒ button p332 , fieldset p300 , input p303 , keygen p344 , label p301 , meter p349 , object p208 , output p346 , progress p348 , select p334 , textarea p341 The form-associated elements p297 fall into several subcategories: Listed elements Denotes elements that are listed in the form.elements p299 and fieldset.elements p301 APIs. ⇒ button p332 , fieldset p300 , input p303 , keygen p344 , object p208 , output p346 , select p334 , textarea p341 Labelable elements Denotes elements that can be associated with label p301 elements. ⇒ button p332 , input p303 , keygen p344 , meter p349 , output p346 , progress p348 , select p334 , textarea p341 Submittable elements Denotes elements that can be used for constructing the form data set p361 when a form p297 element is submitted p361 . ⇒ button p332 , input p303 , keygen p344 , object p208 , select p334 , textarea p341 Resettable elements Denotes elements that can be affected when a form p297 element is reset p366 . ⇒ input p303 , keygen p344 , output p346 , select p334 , textarea p341 In addition, some submittable elements p297 can be, depending on their attributes, buttons. The prose below defines when an element is a button. Some buttons are specifically submit buttons. Note: The object p208 element is also a form-associated element p297 and can, with the use of a suitable plugin p27 , partake in form submission p360 . 4.10.3 The form element Categories Flow content p91 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Flow content p91 , but with no form p297 element descendants. Content attributes: Global attributes p82 accept-charset p298 action p355 autocomplete p298 enctype p356 method p355 name p298 novalidate p356 target p356 DOM interface: [OverrideBuiltins] interface HTMLFormElement : HTMLElement { attribute DOMString acceptCharset; attribute DOMString action; 297 attribute attribute attribute attribute attribute attribute boolean autocomplete; DOMString enctype; DOMString method; DOMString name; boolean noValidate; DOMString target; readonly attribute HTMLFormControlsCollection elements; readonly attribute long length; caller getter any item(in unsigned long index); caller getter any namedItem(in DOMString name); void submit(); void reset(); boolean checkValidity(); void dispatchFormInput(); void dispatchFormChange(); }; The form p297 element represents p638 a collection of form-associated elements p297 , some of which can represent editable values that can be submitted to a server for processing. The accept-charset attribute gives the character encodings that are to be used for the submission. If specified, the value must be an ordered set of unique space-separated tokens p49 , and each token must be an ASCII caseinsensitive p33 match for the preferred MIME name p28 of an ASCII-compatible character encoding p28 . [IANACHARSET] p701 The name attribute represents the form p297 's name within the forms p77 collection. The value must not be the empty string, and the value must be unique amongst the form p297 elements in the forms p77 collection that it is in, if any. The autocomplete attribute is an enumerated attribute p34 . The attribute has two states. The on keyword maps to the on state, and the off keyword maps to the off state. The attribute may also be omitted. The missing value default is the on p298 state. The off p298 state indicates that by default, input p303 elements in the form will have their resulting autocompletion state p324 set to off; the on p298 state indicates that by default, input p303 elements in the form will have their resulting autocompletion state p324 set to on. The action p355 , enctype p356 , method p355 , novalidate p356 , and target p356 attributes are attributes for form submission p355 . This box is non-normative. Implementation requirements are given below this box. form . elements p299 Returns an HTMLCollection p59 of the form controls in the form (excluding image buttons for historical reasons). form . length p299 Returns the number of form controls in the form (excluding image buttons for historical reasons). element = form . item p299 (index) form[index] form(index) Returns the indexth element in the form (excluding image buttons for historical reasons). element = form . namedItem p299 (name) form[name] form(name) Returns the form control in the form with the given ID or name p354 (excluding image buttons for historical reasons). Once an element has been referenced using a particular name, that name will continue being available as a way to reference that element in this method, even if the element's actual ID or name p354 changes, for as long as the element remains in the Document p31 . If there are multiple matching items, then a NodeList p31 object containing all those elements is returned. 298 Returns null if no element with that ID p84 or name p354 could be found. form . submit p299 () Submits the form. form . reset p299 () Resets the form. form . checkValidity p300 () Returns true if the form's controls are all valid; otherwise, returns false. form . dispatchFormInput p300 () Dispatches a forminput event at all the form controls. form . dispatchFormChange p300 () Dispatches a formchange event at all the form controls. The autocomplete and name IDL attributes must reflect p57 the respective content attributes of the same name. The acceptCharset IDL attribute must reflect p57 the accept-charset p298 content attribute. The elements IDL attribute must return an HTMLFormControlsCollection p61 rooted at the Document p31 node, whose filter matches listed elements p297 whose form owner p353 is the form p297 element, with the exception of input p303 elements whose type p304 attribute is in the Image Button p321 state, which must, for historical reasons, be excluded from this particular collection. The length IDL attribute must return the number of nodes represented p59 by the elements p299 collection. The indices of the supported indexed properties at any instant are the indices supported by the object returned by the elements p299 attribute at that instant. The item(index) method must return the value returned by the method of the same name on the elements p299 collection, when invoked with the same argument. Each form p297 element has a mapping of names to elements called the past names map. It is used to persist names of controls even when they change names. The names of the supported named properties are the union of the names currently supported by the object returned by the elements p299 attribute, and the names currently in the past names map p299 . The namedItem(name) method, when called, must run the following steps: 1. 2. If name is one of the names of the supported named properties of the object returned by the elements p299 attribute, then run these substeps: 1. Let candidate be the object returned by the namedItem() p62 method on the object returned by the elements p299 attribute when passed the name argument. 2. If candidate is an element, then add a mapping from name to candidate in the form p297 element's past names map p299 , replacing the previous entry with the same name, if any. 3. Return candidate and abort these steps. Otherwise, name is the name of one of the entries in the form p297 element's past names map p299 : return the object associated with name in that map. If an element listed in the form p297 element's past names map p299 is removed from the Document p31 , then its entries must be removed from the map. The submit() method, when invoked, must submit p361 the form p297 element from the form p297 element itself, with the scripted-submit flag set. The reset() method, when invoked, must run the following steps: 1. If the form p297 element is marked as locked for reset p299 , then abort these steps. 2. Mark the form p297 element as locked for reset. 3. Reset p366 the form p297 element. 299 4. Unmark the form p297 element as locked for reset p299 . If the checkValidity() method is invoked, the user agent must statically validate the constraints p357 of the form p297 element, and return true if the constraint validation return a positive result, and false if it returned a negative result. If the dispatchFormInput() method is invoked, the user agent must broadcast forminput events p366 from the form p297 element. If the dispatchFormChange() method is invoked, the user agent must broadcast formchange events p366 from the form p297 element. This example shows two search forms:
    4.10.4 The fieldset element Categories Flow content p91 . Sectioning root p144 . Listed p297 form-associated element p297 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Optionally a legend p301 element, followed by flow content p91 . Content attributes: Global attributes p82 disabled p300 form p353 name p354 DOM interface: interface HTMLFieldSetElement : HTMLElement { attribute boolean disabled; readonly attribute HTMLFormElement form; attribute DOMString name; readonly attribute DOMString type; readonly attribute HTMLFormControlsCollection elements; readonly attribute boolean willValidate; readonly attribute ValidityState validity; readonly attribute DOMString validationMessage; boolean checkValidity(); void setCustomValidity(in DOMString error); }; The fieldset p300 element represents p638 a set of form controls optionally grouped under a common name. The name of the group is given by the first legend p301 element that is a child of the fieldset p300 element, if any. The remainder of the descendants form the group. The disabled attribute, when specified, causes all the form control descendants of the fieldset p300 element, excluding those that are descendants of the fieldset p300 element's first legend p301 element child, if any, to be disabled p354 . The form p353 attribute is used to explicitly associate the fieldset p300 element with its form owner p353 . The name p354 attribute represents the element's name. 300 This box is non-normative. Implementation requirements are given below this box. fieldset . type p301 Returns the string "fieldset". fieldset . elements p299 Returns an HTMLCollection p59 of the form controls in the element. The disabled IDL attribute must reflect p57 the content attribute of the same name. The type IDL attribute must return the string "fieldset". The elements IDL attribute must return an HTMLFormControlsCollection p61 rooted at the fieldset p300 element, whose filter matches listed elements p297 . The willValidate p358 , validity p359 , and validationMessage p359 attributes, and the checkValidity() p359 and setCustomValidity() p358 methods, are part of the constraint validation API p358 . Constraint validation: fieldset p300 elements are always barred from constraint validation p356 . The following snippet shows a fieldset with a checkbox in the legend that controls whether or not the fieldset is enabled. The contents of the fieldset consist of two required text fields and an optional year/ month control.

    4.10.5 The legend element Categories None. Contexts in which this element may be used: As the first child of a fieldset p300 element. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: interface HTMLLegendElement : HTMLElement { readonly attribute HTMLFormElement form; }; The legend p301 element represents p638 a caption for the rest of the contents of the legend p301 element's parent fieldset p300 element, if any. This box is non-normative. Implementation requirements are given below this box. legend . form p301 Returns the element's form p297 element, if any, or null otherwise. The form IDL attribute's behavior depends on whether the legend p301 element is in a fieldset p300 element or not. If the legend p301 has a fieldset p300 element as its parent, then the form p301 IDL attribute must return the same value as the form p354 IDL attribute on that fieldset p300 element. Otherwise, it must return null. 4.10.6 The label element 301 Categories Flow content p91 . Phrasing content p91 . Interactive content p92 . Form-associated element p297 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 , but with no descendant labelable form-associated elements p297 unless it is the element's labeled control p302 , and no descendant label p301 elements. Content attributes: Global attributes p82 form p353 for p302 DOM interface: interface HTMLLabelElement : HTMLElement { readonly attribute HTMLFormElement form; attribute DOMString htmlFor; readonly attribute HTMLElement control; }; The label p301 represents p638 a caption in a user interface. The caption can be associated with a specific form control, known as the label p301 element's labeled control, either using for p302 attribute, or by putting the form control inside the label p301 element itself. Except where otherwise specified by the following rules, a label p301 element has no labeled control p302 . The for attribute may be specified to indicate a form control with which the caption is to be associated. If the attribute is specified, the attribute's value must be the ID of a labelable form-associated element p297 in the same Document p31 as the label p301 element. If the attribute is specified and there is an element in the Document p31 whose ID is equal to the value of the for p302 attribute, and the first such element is a labelable form-associated element p297 , then that element is the label p301 element's labeled control p302 . If the for p302 attribute is not specified, but the label p301 element has a labelable form-associated element p297 descendant, then the first such descendant in tree order p27 is the label p301 element's labeled control p302 . The label p301 element's exact default presentation and behavior, in particular what its activation behavior p93 might be, if anything, should match the platform's label behavior. For example, on platforms where clicking a checkbox label checks the checkbox, clicking the label p301 in the following snippet could trigger the user agent to run synthetic click activation steps p92 on the input p303 element, as if the element itself had been triggered by the user: On other platforms, the behavior might be just to focus the control, or do nothing. This box is non-normative. Implementation requirements are given below this box. label . control p302 Returns the form control that is associated with this element. The form p353 attribute is used to explicitly associate the label p301 element with its form owner p353 . The htmlFor IDL attribute must reflect p57 the for p302 content attribute. The control IDL attribute must return the label p301 element's labeled control p302 , if any, or null if there isn't one. This box is non-normative. Implementation requirements are given below this box. control . labels p303 Returns a NodeList p31 of all the label p301 elements that the form control is associated with. 302 Labelable form-associated elements p297 have a NodeList p31 object associated with them that represents the list of label p301 elements, in tree order p27 , whose labeled control p302 is the element in question. The labels IDL attribute of labelable form-associated elements p297 , on getting, must return that NodeList p31 object. The following example shows three form controls each with a label, two of which have small text showing the right format for users to use.

    4.10.7 The input element Categories Flow content p91 . Phrasing content p91 . If the type p304 attribute is not in the Hidden p307 state: Interactive content p92 . Listed p297 , labelable p297 , submittable p297 , and resettable p297 form-associated element p297 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Empty. Content attributes: Global attributes p82 accept p320 alt p322 autocomplete p324 autofocus p354 checked p306 disabled p354 form p353 formaction p355 formenctype p356 formmethod p355 formnovalidate p356 formtarget p356 height p271 list p324 max p328 maxlength p327 min p328 multiple p327 name p354 pattern p328 placeholder p329 readonly p325 required p326 size p326 src p321 step p329 type p304 value p306 width p271 DOM interface: interface HTMLInputElement : HTMLElement { attribute DOMString accept; attribute DOMString alt; attribute boolean autocomplete; attribute boolean autofocus; attribute boolean defaultChecked; attribute boolean checked; attribute boolean disabled; readonly attribute HTMLFormElement form; readonly attribute FileList files; 303 attribute attribute attribute attribute attribute attribute attribute readonly attribute attribute attribute attribute attribute attribute attribute attribute attribute attribute attribute attribute attribute attribute attribute attribute attribute attribute readonly attribute attribute DOMString formAction; DOMString formEnctype; DOMString formMethod; boolean formNoValidate; DOMString formTarget; DOMString height; boolean indeterminate; HTMLElement list; DOMString max; long maxLength; DOMString min; boolean multiple; DOMString name; DOMString pattern; DOMString placeholder; boolean readOnly; boolean required; unsigned long size; DOMString src; DOMString step; DOMString type; DOMString defaultValue; DOMString value; Date valueAsDate; double valueAsNumber; HTMLOptionElement selectedOption; DOMString width; void stepUp(in optional long n); void stepDown(in optional long n); readonly attribute boolean willValidate; readonly attribute ValidityState validity; readonly attribute DOMString validationMessage; boolean checkValidity(); void setCustomValidity(in DOMString error); readonly attribute NodeList labels; void select(); attribute unsigned long selectionStart; attribute unsigned long selectionEnd; void setSelectionRange(in unsigned long start, in unsigned long end); }; The input p303 element represents p638 a typed data field, usually with a form control to allow the user to edit the data. The type attribute controls the data type (and associated control) of the element. It is an enumerated attribute p34 . The following table lists the keywords and states for the attribute — the keywords in the left column map to the states in the cell in the second column on the same row as the keyword. Keyword p307 Data type Control type hidden Hidden An arbitrary string n/a text Text p307 Text with no line breaks Text field search Search p307 Text with no line breaks Search field tel Telephone p308 Text with no line breaks A text field url URL p308 An absolute IRI A text field email E-mail p309 An e-mail address or list of e-mail addresses A text field Text with no line breaks (sensitive information) Text field that obscures data entry p310 password Password datetime Date and Time p310 A date and time (year, month, day, hour, minute, second, fraction of a second) with the time zone set to UTC A date and time control date Date p311 A date (year, month, day) with no time zone A date control month Month p312 A date consisting of a year and a month with no time zone A month control A date consisting of a week-year number and a week number with no time zone A week control week 304 State Week p313 Keyword State Time p314 time datetime- Local Date local and Time p314 Data type Control type A time (hour, minute, seconds, fractional seconds) with no time zone A time control A date and time (year, month, day, hour, minute, second, fraction of a second) with no A date and time time zone control number Number p315 A numerical value A text field or spinner control range Range p316 A numerical value, with the extra semantic that the exact value is not important A slider control or similar color Color p318 An sRGB color with 8-bit red, green, and blue components A color well checkbox Checkbox p318 A set of zero or more values from a predefined list A checkbox radio Radio Button p319 An enumerated value A radio button file File Upload p320 Zero or more files each with a MIME type p26 and optionally a file name A label and a button submit Submit Button p321 An enumerated value, with the extra semantic that it must be the last value selected and initiates form submission A button image Image Button p321 A coordinate, relative to a particular image's size, with the extra semantic that it must Either a clickable be the last value selected and initiates form submission image, or a button reset Reset Button p323 n/a A button button Button p323 n/a A button The missing value default is the Text p307 state. Which of the accept p320 , alt p322 , autocomplete p324 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , list p324 , max p328 , maxlength p327 , min p328 , multiple p327 , pattern p328 , placeholder p329 , readonly p325 , required p326 , size p326 , src p321 , step p329 , and width p271 content attributes, the checked p331 , files p331 , valueAsDate p331 , valueAsNumber p331 , list p332 , and selectedOption p332 IDL attributes, the select() p517 method, the selectionStart p517 and selectionEnd p517 IDL attributes, the setSelectionRange() p517 method, the stepUp() p331 and stepDown() p331 methods, and the input p332 and change p332 events apply to an input p303 element depends on the state of its type p304 attribute. The following table is non-normative and summarizes which of those content attributes, IDL attributes, methods, and events apply to each state: Hidden p307 EText p307 , Password p310 Date and Local Date Range p316 Color p318 Checkbox p318 , p309 and Time p310 , Radio Search p307 , mail Time p314 , Date p311 , Button p319 URL p308 , p315 Month p312 , Number Telephone p308 Week p313 , Time p314 Content attributes accept p320 · p322 · · · · · · · · · · · · · · · · · autocomplete p324 · Yes Yes Yes Yes Yes Yes Yes · checked p306 · · · · · · · · Yes formaction p355 · · · · · · · · · formenctype p356 · · · · · · · · · formmethod p355 · · · · · · · · · alt p356 · · · · · · · · · formtarget p356 · · · · · · · · · height p271 · · · · · · · · · list p324 · Yes Yes · Yes Yes Yes Yes · max p328 · · · · Yes Yes Yes · · maxlength p327 · Yes Yes Yes · · · · · · · · · Yes Yes Yes · · formnovalidate min p328 p327 · · Yes · · · · · · pattern p328 · Yes Yes Yes · · · · · placeholder p329 · Yes Yes Yes · · · · · readonly p325 · Yes Yes Yes Yes Yes · · · required p326 · Yes Yes Yes Yes Yes · · Yes size p326 · Yes Yes Yes · · · · · · · · · · · · · · · · · · Yes Yes Yes · · · · · · · · · · · · · · · · · · · Yes multiple src p321 step p329 width p271 IDL attributes and methods checked p331 305 Hidden p307 EText p307 , Password p310 Date and Local Date Range p316 Color p318 Checkbox p318 , p309 and Time p310 , Radio Search p307 , mail Time p314 , Date p311 , Button p319 URL p308 , p315 Month p312 , Number Telephone p308 Week p313 , Time p314 files p331 · · · · · · · · · value p330 default p331 value p330 value p330 value p330 value p330 value p330 value p330 value p330 default/on p331 valueAsDate p331 · · · · Yes · · · · valueAsNumber p331 · · · · Yes Yes Yes · · list p332 · Yes Yes · Yes Yes Yes Yes · selectedOption p332 · Yes Yes · Yes Yes Yes Yes · · Yes Yes Yes · · · · · select() p517 p517 · Yes Yes Yes · · · · · selectionEnd p517 · Yes Yes Yes · · · · · setSelectionRange() p517 · Yes Yes Yes · · · · · stepDown() p331 · · · · Yes Yes Yes · · stepUp() p331 · · · · Yes Yes Yes · · · Yes Yes Yes Yes Yes Yes Yes · · Yes Yes Yes Yes Yes Yes Yes Yes selectionStart Events input p332 event change p332 event When an input p303 element's type p304 attribute changes state, and when the element is first created, the element's rendering and behavior must change to the new state's accordingly and the value sanitization algorithm, if one is defined for the type p304 attribute's new state, must be invoked. Each input p303 element has a value p354 , which is exposed by the value p330 IDL attribute. Some states define an algorithm to convert a string to a number, an algorithm to convert a number to a string, an algorithm to convert a string to a Date object, and an algorithm to convert a Date object to a string, which are used by max p328 , min p328 , step p329 , valueAsDate p331 , valueAsNumber p331 , stepDown() p331 , and stepUp() p331 . Each input p303 element has a boolean dirty value flag. When it is true, the element is said to have a dirty value. The dirty value flag p306 must be initially set to false when the element is created, and must be set to true whenever the user interacts with the control in a way that changes the value p354 . The value content attribute gives the default value p354 of the input p303 element. When the value p306 content attribute is added, set, or removed, if the control does not have a dirty value p306 , the user agent must set the value p354 of the element to the value of the value p306 content attribute, if there is one, or the empty string otherwise, and then run the current value sanitization algorithm p306 , if one is defined. Each input p303 element has a checkedness p354 , which is exposed by the checked p331 IDL attribute. Each input p303 element has a boolean dirty checkedness flag. When it is true, the element is said to have a dirty checkedness. The dirty checkedness flag p306 must be initially set to false when the element is created, and must be set to true whenever the user interacts with the control in a way that changes the checkedness p354 . The checked content attribute is a boolean attribute p34 that gives the default checkedness p354 of the input p303 element. When the checked p306 content attribute is added, if the control does not have dirty checkedness p306 , the user agent must set the checkedness p354 of the element to true; when the checked p306 content attribute is removed, if the control does not have dirty checkedness p306 , the user agent must set the checkedness p354 of the element to false. The reset algorithm p366 for input p303 elements is to set the dirty value flag p306 and dirty checkedness flag p306 back to false, set the value p354 of the element to the value of the value p306 content attribute, if there is one, or the empty string otherwise, set the checkedness p354 of the element to true if the element has a checked p306 content attribute and false if it does not, and then invoke the value sanitization algorithm p306 , if the type p304 attribute's current state defines one. Each input p303 element is either mutable or immutable. Except where otherwise specified, an input p303 element is always mutable p306 . Similarly, except where otherwise specified, the user agent should not allow the user to modify the element's value p354 or checkedness p354 . When an input p303 element is disabled p354 , it is immutable p306 . When an input p303 element does not have a Document p31 node as one of its ancestors (i.e. when it is not in the document), it is immutable p306 . Note: The readonly p325 attribute can also in some cases (e.g. for the Date p311 state, but not the Checkbox p318 state) make an input p303 element immutable p306 . 306 When an input p303 element is cloned, the element's value p354 , dirty value flag p306 , checkedness p354 , and dirty checkedness flag p306 must be propagated to the clone when it is created. The form p353 attribute is used to explicitly associate the input p303 element with its form owner p353 . The name p354 attribute represents the element's name. The disabled p354 attribute is used to make the control non-interactive and to prevent its value from being submitted. The autofocus p354 attribute controls focus. The indeterminate IDL attribute must initially be set to false. On getting, it must return the last value it was set to. On setting, it must be set to the new value. It has no effect except for changing the appearance of checkbox p318 controls. The accept, alt, autocomplete, max, min, multiple, pattern, placeholder, required, size, src, step, and type IDL attributes must reflect p57 the respective content attributes of the same name. The maxLength IDL attribute must reflect p57 the maxlength p327 content attribute, limited to only non-negative numbers p58 . The readOnly IDL attribute must reflect p57 the readonly p325 content attribute. The defaultChecked IDL attribute must reflect p57 the checked p306 content attribute. The defaultValue IDL attribute must reflect p57 the value p306 content attribute. The willValidate p358 , validity p359 , and validationMessage p359 attributes, and the checkValidity() p359 and setCustomValidity() p358 methods, are part of the constraint validation API p358 . The labels p303 attribute provides a list of the element's label p301 s. The select() p517 , selectionStart p517 , selectionEnd p517 , and setSelectionRange() p517 methods and attributes expose the element's text selection. 4.10.7.1 States of the type p304 attribute 4.10.7.1.1 Hidden state When an input p303 element's type p304 attribute is in the Hidden p307 state, the rules in this section apply. The input p303 element represents p638 a value that is not intended to be examined or manipulated by the user. Constraint validation: If an input p303 element's type p304 attribute is in the Hidden p307 state, it is barred from constraint validation p356 . If the name p306 attribute is present and has a value that is a case-sensitive p33 match for the string "_charset_", then the element's value p306 attribute must be omitted. Bookkeeping details ▪The value p330 IDL attribute applies to this element and is in mode default p331 . ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , autocomplete p324 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , list p324 , max p328 , maxlength p327 , min p328 , multiple p327 , pattern p328 , placeholder p329 , readonly p325 , required p326 , size p326 , src p321 , step p329 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , list p332 , selectedOption p332 , selectionStart p517 , selectionEnd p517 , valueAsDate p331 , and valueAsNumber p331 IDL attributes; select() p517 , setSelectionRange() p517 , stepDown() p331 , and stepUp() p331 methods. ▪The input p332 and change p332 events do not apply. 4.10.7.1.2 Text state and Search state When an input p303 element's type p304 attribute is in the Text p307 state or the Search p307 state, the rules in this section apply. The input p303 element represents p638 a one line plain text edit control for the element's value p354 . Note: The difference between the Text p307 state and the Search p307 state is primarily stylistic: on platforms where search fields are distinguished from regular text fields, the Search p307 state might result in an appearance consistent with the platform's search fields rather than appearing like a regular text field. If the element is mutable p306 , its value p354 should be editable by the user. User agents must not allow users to insert U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) characters into the element's value p354 . The value p306 attribute, if specified, must have a value that contains no U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) characters. The value sanitization algorithm p306 is as follows: Strip line breaks p34 from the value p354 . Bookkeeping details ▪The following common input p303 element content attributes, IDL attributes, and methods apply to the element: autocomplete p324 , list p324 , maxlength p327 , pattern p328 , placeholder p329 , readonly p325 , required p326 , and size p326 content attributes; list p332 , 307 selectedOption p332 , selectionStart p517 , selectionEnd p517 , and value p330 IDL attributes; select() p517 and setSelectionRange() p517 methods. ▪The value p330 IDL attribute is in mode value p330 . ▪The input p332 and change p332 events apply. ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , max p328 , min p328 , multiple p327 , src p321 , step p329 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , valueAsDate p331 , and valueAsNumber p331 IDL attributes; stepDown() p331 and stepUp() p331 methods. 4.10.7.1.3 Telephone state When an input p303 element's type p304 attribute is in the Telephone p308 state, the rules in this section apply. The input p303 element represents p638 a control for editing a telephone number given in the element's value p354 . If the element is mutable p306 , its value p354 should be editable by the user. User agents may change the punctuation of values p354 that the user enters. User agents must not allow users to insert U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) characters into the element's value p354 . The value p306 attribute, if specified, must have a value that contains no U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) characters. The value sanitization algorithm p306 is as follows: Strip line breaks p34 from the value p354 . Note: Unlike the URL p308 and E-mail p309 types, the Telephone p308 type does not enforce a particular syntax. This is intentional; in practice, telephone number fields tend to be free-form fields, because there are a wide variety of valid phone numbers. Systems that need to enforce a particular format are encouraged to use the setCustomValidity() p358 method to hook into the client-side validation mechanism. Bookkeeping details ▪The following common input p303 element content attributes, IDL attributes, and methods apply to the element: autocomplete p324 , list p324 , maxlength p327 , pattern p328 , placeholder p329 , readonly p325 , required p326 , and size p326 content attributes; list p332 , selectedOption p332 , selectionStart p517 , selectionEnd p517 , and value p330 IDL attributes; select() p517 and setSelectionRange() p517 methods. ▪The value p330 IDL attribute is in mode value p330 . ▪The input p332 and change p332 events apply. ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , max p328 , min p328 , multiple p327 , src p321 , step p329 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , valueAsDate p331 , and valueAsNumber p331 IDL attributes; stepDown() p331 and stepUp() p331 methods. 4.10.7.1.4 URL state When an input p303 element's type p304 attribute is in the URL p308 state, the rules in this section apply. The input p303 element represents p638 a control for editing a single absolute URL p52 given in the element's value p354 . If the element is mutable p306 , the user agent should allow the user to change the URL represented by its value p354 . User agents may allow the user to set the value p354 to a string that is not a valid p51 absolute URL p52 , but may also or instead automatically escape characters entered by the user so that the value p354 is always a valid p51 absolute URL p52 (even if that isn't the actual value seen and edited by the user in the interface). User agents should allow the user to set the value p354 to the empty string. User agents must not allow users to insert U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) characters into the value p354 . The value p306 attribute, if specified, must have a value that is a valid p51 absolute URL p52 . The value sanitization algorithm p306 is as follows: Strip line breaks p34 from the value p354 . Constraint validation: While the value p354 of the element is not a valid p51 absolute URL p52 , the element is suffering from a type mismatch p357 . Bookkeeping details ▪The following common input p303 element content attributes, IDL attributes, and methods apply to the element: autocomplete p324 , list p324 , maxlength p327 , pattern p328 , placeholder p329 , readonly p325 , required p326 , and size p326 content attributes; list p332 , selectedOption p332 , selectionStart p517 , selectionEnd p517 , and value p330 IDL attributes; select() p517 and setSelectionRange() p517 methods. ▪The value p330 IDL attribute is in mode value p330 . 308 ▪The input p332 and change p332 events apply. ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , max p328 , min p328 , multiple p327 , src p321 , step p329 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , valueAsDate p331 , and valueAsNumber p331 IDL attributes; stepDown() p331 and stepUp() p331 methods. If a document contained the following markup: ...and the user had typed "www.w3", and the user agent had also found that the user had visited http://www.w3.org/Consortium/#membership and http://www.w3.org/TR/XForms/ in the recent past, then the rendering might look like this: The first four URIs in this sample consist of the four URIs in the author-specified list that match the text the user has entered, sorted lexically. Note how the UA is using the knowledge that the values are URIs to allow the user to omit the scheme part and perform intelligent matching on the domain name. The last two URIs (and probably many more, given the scrollbar's indications of more values being available) are the matches from the user agent's session history data. This data is not made available to the page DOM. In this particular case, the UA has no titles to provide for those values. 4.10.7.1.5 E-mail state When an input p303 element's type p304 attribute is in the E-mail p309 state, the rules in this section apply. The input p303 element represents p638 a control for editing a list of e-mail addresses given in the element's value p354 . If the element is mutable p306 , the user agent should allow the user to change the e-mail addresses represented by its value p354 . If the multiple p327 attribute is specified, then the user agent should allow the user to select or provide multiple addresses; otherwise, the user agent should act in a manner consistent with expecting the user to provide a single e-mail address. User agents may allow the user to set the value p354 to a string that is not a valid e-mail address list p310 . User agents should allow the user to set the value p354 to the empty string. User agents must not allow users to insert U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) characters into the value p354 . User agents may transform the value p354 for display and editing (e.g. converting punycode in the value p354 to IDN in the display and vice versa). If the multiple p327 attribute is specified on the element, then the value p306 attribute, if specified, must have a value that is a valid e-mail address list p310 ; otherwise, the value p306 attribute, if specified, must have a value that is a single valid e-mail address p310 . The value sanitization algorithm p306 is as follows: Strip line breaks p34 from the value p354 . Constraint validation: If the multiple p327 attribute is specified on the element, then, while the value p354 of the element is not a valid e-mail address list p310 , the element is suffering from a type mismatch p357 ; otherwise, while 309 the value p354 of the element is not a single valid e-mail address p310 , the element is suffering from a type mismatch p357 . A valid e-mail address list is a set of comma-separated tokens p50 , where each token is itself a valid e-mail address p310 . To obtain the list of tokens from a valid e-mail address list p310 , the user agent must split the string on commas p50 . A valid e-mail address is a string that matches the ABNF production 1*( atext / "." ) "@" ldhstr 1*( "." ldh-str ) where atext is defined in RFC 5322 section 3.2.3, and ldh-str is defined in RFC 1034 section 3.5. [ABNF] p700 [RFC5322] p703 [RFC1034] p702 Note: This requirement is a willful violation p17 of RFC 5322, which defines a syntax for e-mail addresses that is simultaneously too strict (before the "@" character), too vague (after the "@" character), and too lax (allowing comments, white space characters, and quoted strings in manners unfamiliar to most users) to be of practical use here. Bookkeeping details ▪The following common input p303 element content attributes, IDL attributes, and methods apply to the element: autocomplete p324 , list p324 , maxlength p327 , multiple p327 , pattern p328 , placeholder p329 , readonly p325 , required p326 , and size p326 content attributes; list p332 , selectedOption p332 , selectionStart p517 , selectionEnd p517 , and value p330 IDL attributes; select() p517 and setSelectionRange() p517 methods. ▪The value p330 IDL attribute is in mode value p330 . ▪The input p332 and change p332 events apply. ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , max p328 , min p328 , src p321 , step p329 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , valueAsDate p331 , and valueAsNumber p331 IDL attributes; stepDown() p331 and stepUp() p331 methods. 4.10.7.1.6 Password state When an input p303 element's type p304 attribute is in the Password p310 state, the rules in this section apply. The input p303 element represents p638 a one line plain text edit control for the element's value p354 . The user agent should obscure the value so that people other than the user cannot see it. If the element is mutable p306 , its value p354 should be editable by the user. User agents must not allow users to insert U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) characters into the value p354 . The value p306 attribute, if specified, must have a value that contains no U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) characters. The value sanitization algorithm p306 is as follows: Strip line breaks p34 from the value p354 . Bookkeeping details ▪The following common input p303 element content attributes, IDL attributes, and methods apply to the element: autocomplete p324 , maxlength p327 , pattern p328 , placeholder p329 , readonly p325 , required p326 , and size p326 content attributes; selectionStart p517 , selectionEnd p517 , and value p330 IDL attributes; select() p517 , and setSelectionRange() p517 methods. ▪The value p330 IDL attribute is in mode value p330 . ▪The input p332 and change p332 events apply. ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , list p324 , max p328 , min p328 , multiple p327 , src p321 , step p329 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , list p332 , selectedOption p332 , valueAsDate p331 , and valueAsNumber p331 IDL attributes; stepDown() p331 and stepUp() p331 methods. 4.10.7.1.7 Date and Time state When an input p303 element's type p304 attribute is in the Date and Time p310 state, the rules in this section apply. The input p303 element represents p638 a control for setting the element's value p354 to a string representing a specific global date and time p44 . User agents may display the date and time in whatever time zone is appropriate for the user. If the element is mutable p306 , the user agent should allow the user to change the global date and time p44 represented by its value p354 , as obtained by parsing a global date and time p44 from it. User agents must not allow the user to set the value p354 to a string that is not a valid global date and time string p44 expressed in UTC, though user agents may allow the user to set and view the time in another time zone and silently translate the time to and from the UTC time zone in the value p354 . If the user agent provides a user interface for selecting a global date 310 and time p44 , then the value p354 must be set to a valid global date and time string p44 expressed in UTC representing the user's selection. User agents should allow the user to set the value p354 to the empty string. The value p306 attribute, if specified, must have a value that is a valid global date and time string p44 . The value sanitization algorithm p306 is as follows: If the value p354 of the element is a valid global date and time string p44 , then adjust the time so that the value p354 represents the same point in time but expressed in the UTC time zone, otherwise, set it to the empty string instead. The min p328 attribute, if specified, must have a value that is a valid global date and time string p44 . The max p328 attribute, if specified, must have a value that is a valid global date and time string p44 . The step p329 attribute is expressed in seconds. The step scale factor p329 is 1000 (which converts the seconds to milliseconds, as used in the other algorithms). The default step p329 is 60 seconds. When the element is suffering from a step mismatch p357 , the user agent may round the element's value p354 to the nearest global date and time p44 for which the element would not suffer from a step mismatch p357 . The algorithm to convert a string to a number p306 , given a string input, is as follows: If parsing a global date and time p44 from input results in an error, then return an error; otherwise, return the number of milliseconds elapsed from midnight UTC on the morning of 1970-01-01 (the time represented by the value "1970-01-01T00:00:00.0Z") to the parsed global date and time p44 , ignoring leap seconds. The algorithm to convert a number to a string p306 , given a number input, is as follows: Return a valid global date and time string p44 expressed in UTC that represents the global date and time p44 that is input milliseconds after midnight UTC on the morning of 1970-01-01 (the time represented by the value "1970-01-01T00:00:00.0Z"). The algorithm to convert a string to a Date object p306 , given a string input, is as follows: If parsing a global date and time p44 from input results in an error, then return an error; otherwise, return a Date object representing the parsed global date and time p44 , expressed in UTC. The algorithm to convert a Date object to a string p306 , given a Date object input, is as follows: Return a valid global date and time string p44 expressed in UTC that represents the global date and time p44 that is represented by input. Bookkeeping details ▪The following common input p303 element content attributes, IDL attributes, and methods apply to the element: autocomplete p324 , list p324 , max p328 , min p328 , readonly p325 , required p326 , and step p329 content attributes; list p332 , value p330 , valueAsDate p331 , valueAsNumber p331 , and selectedOption p332 IDL attributes; stepDown() p331 and stepUp() p331 methods. ▪The value p330 IDL attribute is in mode value p330 . ▪The input p332 and change p332 events apply. ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , maxlength p327 , multiple p327 , pattern p328 , placeholder p329 , size p326 , src p321 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , selectionStart p517 , and selectionEnd p517 IDL attributes; select() p517 and setSelectionRange() p517 methods. The following fragment shows part of a calendar application. A user can specify a date and time for a meeting (in his local time zone, probably, though the user agent can allow the user to change that), and since the submitted data includes the time-zone offset, the application can ensure that the meeting is shown at the correct time regardless of the time zones used by all the participants.
    Add Meeting

    Had the application used the datetime-local p314 type instead, the calendar application would have also had to explicitly determine which time zone the user intended. 4.10.7.1.8 Date state When an input p303 element's type p304 attribute is in the Date p311 state, the rules in this section apply. The input p303 element represents p638 a control for setting the element's value p354 to a string representing a specific date p41 . If the element is mutable p306 , the user agent should allow the user to change the date p41 represented by its value p354 , as obtained by parsing a date p41 from it. User agents must not allow the user to set the value p354 to a string that is not a valid date string p41 . If the user agent provides a user interface for selecting a date p41 , then the 311 value p354 must be set to a valid date string p41 representing the user's selection. User agents should allow the user to set the value p354 to the empty string. The value p306 attribute, if specified, must have a value that is a valid date string p41 . The value sanitization algorithm p306 is as follows: If the value p354 of the element is not a valid date string p41 , then set it to the empty string instead. The min p328 attribute, if specified, must have a value that is a valid date string p41 . The max p328 attribute, if specified, must have a value that is a valid date string p41 . The step p329 attribute is expressed in days. The step scale factor p329 is 86,400,000 (which converts the days to milliseconds, as used in the other algorithms). The default step p329 is 1 day. When the element is suffering from a step mismatch p357 , the user agent may round the element's value p354 to the nearest date p41 for which the element would not suffer from a step mismatch p357 . The algorithm to convert a string to a number p306 , given a string input, is as follows: If parsing a date p41 from input results in an error, then return an error; otherwise, return the number of milliseconds elapsed from midnight UTC on the morning of 1970-01-01 (the time represented by the value "1970-01-01T00:00:00.0Z") to midnight UTC on the morning of the parsed date p41 , ignoring leap seconds. The algorithm to convert a number to a string p306 , given a number input, is as follows: Return a valid date string p41 that represents the date p41 that, in UTC, is current input milliseconds after midnight UTC on the morning of 1970-01-01 (the time represented by the value "1970-01-01T00:00:00.0Z"). The algorithm to convert a string to a Date object p306 , given a string input, is as follows: If parsing a date p41 from input results in an error, then return an error; otherwise, return a Date object representing midnight UTC on the morning of the parsed date p41 . The algorithm to convert a Date object to a string p306 , given a Date object input, is as follows: Return a valid date string p41 that represents the date p41 current at the time represented by input in the UTC time zone. Bookkeeping details ▪The following common input p303 element content attributes, IDL attributes, and methods apply to the element: autocomplete p324 , list p324 , max p328 , min p328 , readonly p325 , required p326 , and step p329 content attributes; list p332 , value p330 , valueAsDate p331 , valueAsNumber p331 , and selectedOption p332 IDL attributes; stepDown() p331 and stepUp() p331 methods. ▪The value p330 IDL attribute is in mode value p330 . ▪The input p332 and change p332 events apply. ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , maxlength p327 , multiple p327 , pattern p328 , placeholder p329 , size p326 , src p321 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , selectionStart p517 , and selectionEnd p517 IDL attributes; select() p517 and setSelectionRange() p517 methods. 4.10.7.1.9 Month state When an input p303 element's type p304 attribute is in the Month p312 state, the rules in this section apply. The input p303 element represents p638 a control for setting the element's value p354 to a string representing a specific month p41 . If the element is mutable p306 , the user agent should allow the user to change the month p41 represented by its value p354 , as obtained by parsing a month p41 from it. User agents must not allow the user to set the value p354 to a string that is not a valid month string p41 . If the user agent provides a user interface for selecting a month p41 , then the value p354 must be set to a valid month string p41 representing the user's selection. User agents should allow the user to set the value p354 to the empty string. The value p306 attribute, if specified, must have a value that is a valid month string p41 . The value sanitization algorithm p306 is as follows: If the value p354 of the element is not a valid month string p41 , then set it to the empty string instead. The min p328 attribute, if specified, must have a value that is a valid month string p41 . The max p328 attribute, if specified, must have a value that is a valid month string p41 . The step p329 attribute is expressed in months. The step scale factor p329 is 1 (there is no conversion needed as the algorithms use months). The default step p329 is 1 month. When the element is suffering from a step mismatch p357 , the user agent may round the element's value p354 to the nearest month p41 for which the element would not suffer from a step mismatch p357 . 312 The algorithm to convert a string to a number p306 , given a string input, is as follows: If parsing a month p41 from input results in an error, then return an error; otherwise, return the number of months between January 1970 and the parsed month p41 . The algorithm to convert a number to a string p306 , given a number input, is as follows: Return a valid month string p41 that represents the month p41 that has input months between it and January 1970. The algorithm to convert a string to a Date object p306 , given a string input, is as follows: If parsing a month p41 from input results in an error, then return an error; otherwise, return a Date object representing midnight UTC on the morning of the first day of the parsed month p41 . The algorithm to convert a Date object to a string p306 , given a Date object input, is as follows: Return a valid month string p41 that represents the month p41 current at the time represented by input in the UTC time zone. Bookkeeping details ▪The following common input p303 element content attributes, IDL attributes, and methods apply to the element: autocomplete p324 , list p324 , max p328 , min p328 , readonly p325 , required p326 , and step p329 content attributes; list p332 , value p330 , valueAsDate p331 , valueAsNumber p331 , and selectedOption p332 IDL attributes; stepDown() p331 and stepUp() p331 methods. ▪The value p330 IDL attribute is in mode value p330 . ▪The input p332 and change p332 events apply. ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , maxlength p327 , multiple p327 , pattern p328 , placeholder p329 , size p326 , src p321 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , selectionStart p517 , and selectionEnd p517 IDL attributes; select() p517 and setSelectionRange() p517 methods. 4.10.7.1.10 Week state When an input p303 element's type p304 attribute is in the Week p313 state, the rules in this section apply. The input p303 element represents p638 a control for setting the element's value p354 to a string representing a specific week p45 . If the element is mutable p306 , the user agent should allow the user to change the week p45 represented by its value p354 , as obtained by parsing a week p46 from it. User agents must not allow the user to set the value p354 to a string that is not a valid week string p46 . If the user agent provides a user interface for selecting a week p45 , then the value p354 must be set to a valid week string p46 representing the user's selection. User agents should allow the user to set the value p354 to the empty string. The value p306 attribute, if specified, must have a value that is a valid week string p46 . The value sanitization algorithm p306 is as follows: If the value p354 of the element is not a valid week string p46 , then set it to the empty string instead. The min p328 attribute, if specified, must have a value that is a valid week string p46 . The max p328 attribute, if specified, must have a value that is a valid week string p46 . The step p329 attribute is expressed in weeks. The step scale factor p329 is 604,800,000 (which converts the weeks to milliseconds, as used in the other algorithms). The default step p329 is 1 week. The default step base p329 is −259,200,000 (the start of week 1970-W01). When the element is suffering from a step mismatch p357 , the user agent may round the element's value p354 to the nearest week p45 for which the element would not suffer from a step mismatch p357 . The algorithm to convert a string to a number p306 , given a string input, is as follows: If parsing a week string p46 from input results in an error, then return an error; otherwise, return the number of milliseconds elapsed from midnight UTC on the morning of 1970-01-01 (the time represented by the value "1970-01-01T00:00:00.0Z") to midnight UTC on the morning of the Monday of the parsed week p45 , ignoring leap seconds. The algorithm to convert a number to a string p306 , given a number input, is as follows: Return a valid week string p46 that represents the week p45 that, in UTC, is current input milliseconds after midnight UTC on the morning of 1970-01-01 (the time represented by the value "1970-01-01T00:00:00.0Z"). The algorithm to convert a string to a Date object p306 , given a string input, is as follows: If parsing a week p46 from input results in an error, then return an error; otherwise, return a Date object representing midnight UTC on the morning of the Monday of the parsed week p45 . The algorithm to convert a Date object to a string p306 , given a Date object input, is as follows: Return a valid week string p46 that represents the week p45 current at the time represented by input in the UTC time zone. Bookkeeping details 313 ▪The following common input p303 element content attributes, IDL attributes, and methods apply to the element: autocomplete p324 , list p324 , max p328 , min p328 , readonly p325 , required p326 , and step p329 content attributes; list p332 , value p330 , valueAsDate p331 , valueAsNumber p331 , and selectedOption p332 IDL attributes; stepDown() p331 and stepUp() p331 methods. ▪The value p330 IDL attribute is in mode value p330 . ▪The input p332 and change p332 events apply. ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , maxlength p327 , multiple p327 , pattern p328 , placeholder p329 , size p326 , src p321 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , selectionStart p517 , and selectionEnd p517 IDL attributes; select() p517 and setSelectionRange() p517 methods. 4.10.7.1.11 Time state When an input p303 element's type p304 attribute is in the Time p314 state, the rules in this section apply. The input p303 element represents p638 a control for setting the element's value p354 to a string representing a specific time p42 . If the element is mutable p306 , the user agent should allow the user to change the time p42 represented by its value p354 , as obtained by parsing a time p42 from it. User agents must not allow the user to set the value p354 to a string that is not a valid time string p42 . If the user agent provides a user interface for selecting a time p42 , then the value p354 must be set to a valid time string p42 representing the user's selection. User agents should allow the user to set the value p354 to the empty string. The value p306 attribute, if specified, must have a value that is a valid time string p42 . The value sanitization algorithm p306 is as follows: If the value p354 of the element is not a valid time string p42 , then set it to the empty string instead. The min p328 attribute, if specified, must have a value that is a valid time string p42 . The max p328 attribute, if specified, must have a value that is a valid time string p42 . The step p329 attribute is expressed in seconds. The step scale factor p329 is 1000 (which converts the seconds to milliseconds, as used in the other algorithms). The default step p329 is 60 seconds. When the element is suffering from a step mismatch p357 , the user agent may round the element's value p354 to the nearest time p42 for which the element would not suffer from a step mismatch p357 . The algorithm to convert a string to a number p306 , given a string input, is as follows: If parsing a time p42 from input results in an error, then return an error; otherwise, return the number of milliseconds elapsed from midnight to the parsed time p42 on a day with no time changes. The algorithm to convert a number to a string p306 , given a number input, is as follows: Return a valid time string p42 that represents the time p42 that is input milliseconds after midnight on a day with no time changes. The algorithm to convert a string to a Date object p306 , given a string input, is as follows: If parsing a time p42 from input results in an error, then return an error; otherwise, return a Date object representing the parsed time p42 in UTC on 1970-01-01. The algorithm to convert a Date object to a string p306 , given a Date object input, is as follows: Return a valid time string p42 that represents the UTC time p42 component that is represented by input. Bookkeeping details ▪The following common input p303 element content attributes, IDL attributes, and methods apply to the element: autocomplete p324 , list p324 , max p328 , min p328 , readonly p325 , required p326 , and step p329 content attributes; list p332 , value p330 , valueAsDate p331 , valueAsNumber p331 , and selectedOption p332 IDL attributes; stepDown() p331 and stepUp() p331 methods. ▪The value p330 IDL attribute is in mode value p330 . ▪The input p332 and change p332 events apply. ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , maxlength p327 , multiple p327 , pattern p328 , placeholder p329 , size p326 , src p321 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , selectionStart p517 , and selectionEnd p517 IDL attributes; select() p517 and setSelectionRange() p517 methods. 4.10.7.1.12 Local Date and Time state When an input p303 element's type p304 attribute is in the Local Date and Time p314 state, the rules in this section apply. The input p303 element represents p638 a control for setting the element's value p354 to a string representing a local date and time p43 , with no time-zone offset information. 314 If the element is mutable p306 , the user agent should allow the user to change the date and time p43 represented by its value p354 , as obtained by parsing a date and time p43 from it. User agents must not allow the user to set the value p354 to a string that is not a valid local date and time string p43 . If the user agent provides a user interface for selecting a local date and time p43 , then the value p354 must be set to a valid local date and time string p43 representing the user's selection. User agents should allow the user to set the value p354 to the empty string. The value p306 attribute, if specified, must have a value that is a valid local date and time string p43 . The value sanitization algorithm p306 is as follows: If the value p354 of the element is not a valid local date and time string p43 , then set it to the empty string instead. The min p328 attribute, if specified, must have a value that is a valid local date and time string p43 . The max p328 attribute, if specified, must have a value that is a valid local date and time string p43 . The step p329 attribute is expressed in seconds. The step scale factor p329 is 1000 (which converts the seconds to milliseconds, as used in the other algorithms). The default step p329 is 60 seconds. When the element is suffering from a step mismatch p357 , the user agent may round the element's value p354 to the nearest local date and time p43 for which the element would not suffer from a step mismatch p357 . The algorithm to convert a string to a number p306 , given a string input, is as follows: If parsing a date and time p43 from input results in an error, then return an error; otherwise, return the number of milliseconds elapsed from midnight on the morning of 1970-01-01 (the time represented by the value "1970-01-01T00:00:00.0") to the parsed local date and time p43 , ignoring leap seconds. The algorithm to convert a number to a string p306 , given a number input, is as follows: Return a valid local date and time string p43 that represents the date and time that is input milliseconds after midnight on the morning of 1970-01-01 (the time represented by the value "1970-01-01T00:00:00.0"). Bookkeeping details ▪The following common input p303 element content attributes, IDL attributes, and methods apply to the element: autocomplete p324 , list p324 , max p328 , min p328 , readonly p325 , required p326 , and step p329 content attributes; list p332 , value p330 , valueAsNumber p331 , and selectedOption p332 IDL attributes; stepDown() p331 and stepUp() p331 methods. ▪The value p330 IDL attribute is in mode value p330 . ▪The input p332 and change p332 events apply. ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , maxlength p327 , multiple p327 , pattern p328 , placeholder p329 , size p326 , src p321 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , selectionStart p517 , selectionEnd p517 , and valueAsDate p331 IDL attributes; select() p517 and setSelectionRange() p517 methods. The following example shows part of a flight booking application. The application uses an input p303 element with its type p304 attribute set to datetime-local p314 , and it then interprets the given date and time in the time zone of the selected airport.
    Destination

    If the application instead used the datetime p310 type, then the user would have to work out the time-zone conversions himself, which is clearly not a good user experience! 4.10.7.1.13 Number state When an input p303 element's type p304 attribute is in the Number p315 state, the rules in this section apply. The input p303 element represents p638 a control for setting the element's value p354 to a string representing a number. If the element is mutable p306 , the user agent should allow the user to change the number represented by its value p354 , as obtained from applying the rules for parsing floating point number values p36 to it. User agents must 315 not allow the user to set the value p354 to a string that is not a valid floating point number p36 . If the user agent provides a user interface for selecting a number, then the value p354 must be set to the best representation of the number representing the user's selection as a floating point number p36 . User agents should allow the user to set the value p354 to the empty string. The value p306 attribute, if specified, must have a value that is a valid floating point number p36 . The value sanitization algorithm p306 is as follows: If the value p354 of the element is not a valid floating point number p36 , then set it to the empty string instead. The min p328 attribute, if specified, must have a value that is a valid floating point number p36 . The max p328 attribute, if specified, must have a value that is a valid floating point number p36 . The step scale factor p329 is 1. The default step p329 is 1 (allowing only integers, unless the min p328 attribute has a non-integer value). When the element is suffering from a step mismatch p357 , the user agent may round the element's value p354 to the nearest number for which the element would not suffer from a step mismatch p357 . The algorithm to convert a string to a number p306 , given a string input, is as follows: If applying the rules for parsing floating point number values p36 to input results in an error, then return an error; otherwise, return the resulting number. The algorithm to convert a number to a string p306 , given a number input, is as follows: Return a valid floating point number p36 that represents input. Bookkeeping details ▪The following common input p303 element content attributes, IDL attributes, and methods apply to the element: autocomplete p324 , list p324 , max p328 , min p328 , readonly p325 , required p326 , and step p329 content attributes; list p332 , value p330 , valueAsNumber p331 , and selectedOption p332 IDL attributes; stepDown() p331 and stepUp() p331 methods. ▪The value p330 IDL attribute is in mode value p330 . ▪The input p332 and change p332 events apply. ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , maxlength p327 , multiple p327 , pattern p328 , placeholder p329 , size p326 , src p321 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , selectionStart p517 , selectionEnd p517 , and valueAsDate p331 IDL attributes; select() p517 and setSelectionRange() p517 methods. 4.10.7.1.14 Range state When an input p303 element's type p304 attribute is in the Range p316 state, the rules in this section apply. The input p303 element represents p638 a control for setting the element's value p354 to a string representing a number, but with the caveat that the exact value is not important, letting UAs provide a simpler interface than they do for the Number p315 state. Note: In this state, the range and step constraints are enforced even during user input, and there is no way to set the value to the empty string. If the element is mutable p306 , the user agent should allow the user to change the number represented by its value p354 , as obtained from applying the rules for parsing floating point number values p36 to it. User agents must not allow the user to set the value p354 to a string that is not a valid floating point number p36 . If the user agent provides a user interface for selecting a number, then the value p354 must be set to a best representation of the number representing the user's selection as a floating point number p36 . User agents must not allow the user to set the value p354 to the empty string. The value p306 attribute, if specified, must have a value that is a valid floating point number p36 . The value sanitization algorithm p306 is as follows: If the value p354 of the element is not a valid floating point number p36 , then set it to a valid floating point number p36 that represents the default value p316 . The min p328 attribute, if specified, must have a value that is a valid floating point number p36 . The default minimum p328 is 0. The max p328 attribute, if specified, must have a value that is a valid floating point number p36 . The default maximum p328 is 100. The default value is the minimum p328 plus half the difference between the minimum p328 and the maximum p328 , unless the maximum p328 is less than the minimum p328 , in which case the default value p316 is the minimum p328 . When the element is suffering from an underflow p357 , the user agent must set the element's value p354 to a valid floating point number p36 that represents the minimum p328 . 316 When the element is suffering from an overflow p357 , if the maximum p328 is not less than the minimum p328 , the user agent must set the element's value p354 to a valid floating point number p36 that represents the maximum p328 . The step scale factor p329 is 1. The default step p329 is 1 (allowing only integers, unless the min p328 attribute has a non-integer value). When the element is suffering from a step mismatch p357 , the user agent must round the element's value p354 to the nearest number for which the element would not suffer from a step mismatch p357 , and which is greater than or equal to the minimum p328 , and, if the maximum p328 is not less than the minimum p328 , which is less than or equal to the maximum p328 . The algorithm to convert a string to a number p306 , given a string input, is as follows: If applying the rules for parsing floating point number values p36 to input results in an error, then return an error; otherwise, return the resulting number. The algorithm to convert a number to a string p306 , given a number input, is as follows: Return a valid floating point number p36 that represents input. Bookkeeping details ▪The following common input p303 element content attributes, IDL attributes, and methods apply to the element: autocomplete p324 , list p324 , max p328 , min p328 , and step p329 content attributes; list p332 , value p330 , valueAsNumber p331 , and selectedOption p332 IDL attributes; stepDown() p331 and stepUp() p331 methods. ▪The value p330 IDL attribute is in mode value p330 . ▪The input p332 and change p332 events apply. ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , maxlength p327 , multiple p327 , pattern p328 , placeholder p329 , readonly p325 , required p326 , size p326 , src p321 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , selectionStart p517 , selectionEnd p517 , and valueAsDate p331 IDL attributes; select() p517 and setSelectionRange() p517 methods. Here is an example of a range control using an autocomplete list with the list p324 attribute. This could be useful if there are values along the full range of the control that are especially important, such as preconfigured light levels or typical speed limits in a range control used as a speed control. The following markup fragment: ...with the following style sheet applied: input { height: 75px; width: 49px; background: #D5CCBB; color: black; } ...might render as: Note how the UA determined the orientation of the control from the ratio of the style-sheet-specified height and width properties. The colors were similiarly derived from the style sheet. The tick marks, however, were derived from the markup. In particular, the step p329 attribute has not affected the placement of tick marks, the UA deciding to only use the author-specified completion values and then adding longer tick marks at the extremes. Note also how the invalid value +50 was completely ignored. For another example, consider the following markup fragment: A user agent could display in a variety of ways, for instance: 317 Or, alternatively, for instance: The user agent could pick which one to display based on the dimensions given in the style sheet. This would allow it to maintain the same resolution for the tick marks, despite the differences in width. 4.10.7.1.15 Color state When an input p303 element's type p304 attribute is in the Color p318 state, the rules in this section apply. The input p303 element represents p638 a color well control, for setting the element's value p354 to a string representing a simple color p47 . Note: In this state, there is always a color picked, and there is no way to set the value to the empty string. If the element is mutable p306 , the user agent should allow the user to change the color represented by its value p354 , as obtained from applying the rules for parsing simple color values p47 to it. User agents must not allow the user to set the value p354 to a string that is not a valid lowercase simple color p47 . If the user agent provides a user interface for selecting a color, then the value p354 must be set to the result of using the rules for serializing simple color values p48 to the user's selection. User agents must not allow the user to set the value p354 to the empty string. The value p306 attribute, if specified, must have a value that is a valid simple color p47 . The value sanitization algorithm p306 is as follows: If the value p354 of the element is a valid simple color p47 , then set it to the value p354 of the element converted to ASCII lowercase p33 ; otherwise, set it to the string "#000000". Bookkeeping details ▪The following common input p303 element content attributes, IDL attributes, and methods apply to the element: autocomplete p324 and list p324 content attributes; list p332 , value p330 , and selectedOption p332 IDL attributes. ▪The value p330 IDL attribute is in mode value p330 . ▪The input p332 and change p332 events apply. ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , maxlength p327 , max p328 , min p328 , multiple p327 , pattern p328 , placeholder p329 , readonly p325 , required p326 , size p326 , src p321 , step p329 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , selectionStart p517 , selectionEnd p517 , valueAsDate p331 , and valueAsNumber p331 IDL attributes; select() p517 , setSelectionRange() p517 , stepDown() p331 , and stepUp() p331 methods. 4.10.7.1.16 Checkbox state When an input p303 element's type p304 attribute is in the Checkbox p318 state, the rules in this section apply. The input p303 element represents p638 a two-state control that represents the element's checkedness p354 state. If the element's checkedness p354 state is true, the control represents a positive selection, and if it is false, a negative selection. If the element's indeterminate p307 IDL attribute is set to true, then the control's selection should be obscured as if the control was in a third, indeterminate, state. Note: The control is never a true tri-state control, even if the element's indeterminate p307 IDL attribute is set to true. The indeterminate p307 IDL attribute only gives the appearance of a third state. If the element is mutable p306 , then: The pre-click activation steps p92 consist of setting the element's checkedness p354 to its opposite value (i.e. true if it is false, false if it is true), and of setting the element's indeterminate p307 IDL attribute to false. The canceled activation steps p92 consist of setting the checkedness p354 and the element's indeterminate p307 IDL attribute back to the values they had before the pre-click activation 318 steps p92 were run. The activation behavior p93 is to fire a simple event p496 that bubbles named change at the element, then broadcast formchange events p366 at the element's form owner p353 . Constraint validation: If the element is required p326 and its checkedness p354 is false, then the element is suffering from being missing p357 . This box is non-normative. Implementation requirements are given below this box. input . indeterminate p307 [ = value ] When set, overrides the rendering of checkbox p318 controls so that the current value is not visible. Bookkeeping details ▪The following common input p303 element content attributes and IDL attributes apply to the element: checked p306 , and required p326 content attributes; checked p331 and value p330 IDL attributes. ▪The value p330 IDL attribute is in mode default/on p331 . ▪The change p332 event applies. ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , autocomplete p324 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , list p324 , max p328 , maxlength p327 , min p328 , multiple p327 , pattern p328 , placeholder p329 , readonly p325 , size p326 , src p321 , step p329 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: files p331 , list p332 , selectedOption p332 , selectionStart p517 , selectionEnd p517 , valueAsDate p331 , and valueAsNumber p331 IDL attributes; select() p517 , setSelectionRange() p517 , stepDown() p331 , and stepUp() p331 methods. ▪The input p332 event does not apply. 4.10.7.1.17 Radio Button state When an input p303 element's type p304 attribute is in the Radio Button p319 state, the rules in this section apply. The input p303 element represents p638 a control that, when used in conjunction with other input p303 elements, forms a radio button group p319 in which only one control can have its checkedness p354 state set to true. If the element's checkedness p354 state is true, the control represents the selected control in the group, and if it is false, it indicates a control in the group that is not selected. The radio button group that contains an input p303 element a also contains all the other input p303 elements b that fulfill all of the following conditions: • The input p303 element b's type p304 attribute is in the Radio Button p319 state. • Either a and b have the same form owner p353 , or they both have no form owner p353 . • They both have a name p354 attribute, and the value of a's name p354 attribute is a compatibility caseless p33 match for the value of b's name p354 attribute. A document must not contain an input p303 element whose radio button group p319 contains only that element. When any of the following events occur, if the element's checkedness p354 state is true after the event, the checkedness p354 state of all the other elements in the same radio button group p319 must be set to false: • The element's checkedness p354 state is set to true (for whatever reason). • The element's name p354 attribute is added, removed, or changes value. • The element's form owner p353 changes. If the element is mutable p306 , then: The pre-click activation steps p92 consist of setting the element's checkedness p354 to true. The canceled activation steps p92 consist of setting the element's checkedness p354 to false. The activation behavior p93 is to fire a simple event p496 that bubbles named change at the element, then broadcast formchange events p366 at the element's form owner p353 . Constraint validation: If the element is required p326 and all of the input p303 elements in the radio button group p319 have a checkedness p354 that is false, then the element is suffering from being missing p357 . Note: If none of the radio buttons in a radio button group p319 are checked when they are inserted into the document, then they will all be initially unchecked in the interface, until such time as one of them is checked (either by the user or by script). Bookkeeping details ▪The following common input p303 element content attributes and IDL attributes apply to the element: checked p306 and required p326 content attributes; checked p331 and value p330 IDL attributes. 319 ▪The value p330 IDL attribute is in mode default/on p331 . ▪The change p332 event applies. ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , autocomplete p324 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , list p324 , max p328 , maxlength p327 , min p328 , multiple p327 , pattern p328 , placeholder p329 , readonly p325 , size p326 , src p321 , step p329 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: files p331 , list p332 , selectedOption p332 , selectionStart p517 , selectionEnd p517 , valueAsDate p331 , and valueAsNumber p331 IDL attributes; select() p517 , setSelectionRange() p517 , stepDown() p331 , and stepUp() p331 methods. ▪The input p332 event does not apply. 4.10.7.1.18 File Upload state When an input p303 element's type p304 attribute is in the File Upload p320 state, the rules in this section apply. The input p303 element represents p638 a list of selected files, each file consisting of a file name, a file type, and a file body (the contents of the file). If the element is mutable p306 , the user agent should allow the user to change the files on the list, e.g. adding or removing files. Files can be from the filesystem or created on the fly, e.g. a picture taken from a camera connected to the user's device. Constraint validation: If the element is required p326 and the list of selected files p320 is empty, then the element is suffering from being missing p357 . Unless the multiple p327 attribute is set, there must be no more than one file in the list of selected files p320 . The accept attribute may be specified to provide user agents with a hint of what file types the server will be able to accept. If specified, the attribute must consist of a set of comma-separated tokens p50 , each of which must be an ASCII case-insensitive p33 match for one of the following: The string audio/* Indicates that sound files are accepted. The string video/* Indicates that video files are accepted. The string image/* Indicates that image files are accepted. A valid MIME type with no parameters p26 Indicates that files of the specified type are accepted. The tokens must not be ASCII case-insensitive p33 matches for any of the other tokens (i.e. duplicates are not allowed). To obtain the list of tokens from the attribute, the user agent must split the attribute value on commas p50 . User agents should prevent the user from selecting files that are not accepted by one (or more) of these tokens. For historical reasons, the value p330 IDL attribute prefixes the filename with the string "C:\fakepath\". Some legacy user agents actually included the full path (which was a security vulnerability). As a result of this, obtaining the filename from the value p330 IDL attribute in a backwards-compatible way is non-trivial. The following function extracts the filename in a suitably compatible manner: function extractFilename(path) { var x; x = path.lastIndexOf('\\'); if (x >= 0) // Windows-based path return path.substr(x+1); x = path.lastIndexOf('/'); if (x >= 0) // Unix-based path return path.substr(x+1); return path; // just the filename } This can be used as follows:

    The name of the file you picked is: (none)

    Bookkeeping details ▪The following common input p303 element content attributes apply to the element: ▪The following common input p303 element content attributes and IDL attributes apply to the element: accept p320 , multiple p327 , and required p326 ; files p331 and value p330 IDL attributes. ▪The value p330 IDL attribute is in mode filename p331 . ▪The change p332 event applies. ▪The following content attributes must not be specified and do not apply to the element: alt p322 , autocomplete p324 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , list p324 , max p328 , maxlength p327 , min p328 , pattern p328 , placeholder p329 , readonly p325 , size p326 , src p321 , step p329 , and width p271 . ▪The element's value p306 attribute must be omitted. ▪The following IDL attributes and methods do not apply to the element: checked p331 , list p332 , selectedOption p332 , selectionStart p517 , selectionEnd p517 , valueAsDate p331 , and valueAsNumber p331 IDL attributes; select() p517 , setSelectionRange() p517 , stepDown() p331 , and stepUp() p331 methods. ▪The input p332 event does not apply. 4.10.7.1.19 Submit Button state When an input p303 element's type p304 attribute is in the Submit Button p321 state, the rules in this section apply. The input p303 element represents p638 a button that, when activated, submits the form. If the element has a value p306 attribute, the button's label must be the value of that attribute; otherwise, it must be an implementation-defined string that means "Submit" or some such. The element is a button p297 , specifically a submit button p297 . If the element is mutable p306 , the user agent should allow the user to activate the element. The element's activation behavior p93 , if the element has a form owner p353 , is to submit p361 the form owner p353 from the input p303 element; otherwise, it is to do nothing. The formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , and formtarget p356 attributes are attributes for form submission p355 . Note: The formnovalidate p356 attribute can be used to make submit buttons that do not trigger the constraint validation. Bookkeeping details ▪The following common input p303 element content attributes and IDL attributes apply to the element: formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , and formtarget p356 content attributes; value p330 IDL attribute. ▪The value p330 IDL attribute is in mode default p331 . ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , autocomplete p324 , checked p306 , height p271 , list p324 , max p328 , maxlength p327 , min p328 , multiple p327 , pattern p328 , placeholder p329 , readonly p325 , required p326 , size p326 , src p321 , step p329 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , list p332 , selectedOption p332 , selectionStart p517 , selectionEnd p517 , valueAsDate p331 , and valueAsNumber p331 IDL attributes; select() p517 , setSelectionRange() p517 , stepDown() p331 , and stepUp() p331 methods. ▪The input p332 and change p332 events do not apply. 4.10.7.1.20 Image Button state When an input p303 element's type p304 attribute is in the Image Button p321 state, the rules in this section apply. The input p303 element represents p638 either an image from which a user can select a coordinate and submit the form, or alternatively a button from which the user can submit the form. The element is a button p297 , specifically a submit button p297 . The image is given by the src attribute. The src p321 attribute must be present, and must contain a valid nonempty URL p51 referencing a non-interactive, optionally animated, image resource that is neither paged nor scripted. When any of the following events occur, unless the user agent cannot support images, or its support for images has been disabled, or the user agent only fetches elements on demand, or the src p321 attribute's value is the empty string, the user agent must resolve p51 the value of the src p321 attribute, relative to the element, and if that is successful, must fetch p55 the resulting absolute URL p52 : 321 • The input p303 element's type p304 attribute is first set to the Image Button p321 state (possibly when the element is first created), and the src p321 attribute is present. • The input p303 element's type p304 attribute is changed back to the Image Button p321 state, and the src p321 attribute is present, and its value has changed since the last time the type p304 attribute was in the Image Button p321 state. • The input p303 element's type p304 attribute is in the Image Button p321 state, and the src p321 attribute is set or changed. Fetching the image must delay the load event p619 of the element's document until the task p489 that is queued p490 by the networking task source p491 once the resource has been fetched p55 (defined below) has been run. If the image was successfully obtained, with no network errors, and the image's type is a supported image type, and the image is a valid image of that type, then the image is said to be available. If this is true before the image is completely downloaded, each task p489 that is queued p490 by the networking task source p491 while the image is being fetched p55 must update the presentation of the image appropriately. The user agents should apply the image sniffing rules p57 to determine the type of the image, with the image's associated Content-Type headers p57 giving the official type. If these rules are not applied, then the type of the image must be the type given by the image's associated Content-Type headers p57 . User agents must not support non-image resources with the input p303 element. User agents must not run executable code embedded in the image resource. User agents must only display the first page of a multipage resource. User agents must not allow the resource to act in an interactive fashion, but should honor any animation in the resource. The task p489 that is queued p490 by the networking task source p491 once the resource has been fetched p55 , must, if the download was successful and the image is available p322 , queue a task p490 to fire a simple event p496 named load at the input p303 element; and otherwise, if the fetching process fails without a response from the remote server, or completes but the image is not a valid or supported image, queue a task p490 to fire a simple event p496 named error on the input p303 element. The alt attribute provides the textual label for the alternative button for users and user agents who cannot use the image. The alt p322 attribute must also be present, and must contain a non-empty string. The input p303 element supports dimension attributes p271 . If the src p321 attribute is set, and the image is available p322 and the user agent is configured to display that image, then: The element represents p638 a control for selecting a coordinate p322 from the image specified by the src p321 attribute; if the element is mutable p306 , the user agent should allow the user to select this coordinate p322 . The activation behavior p93 in this case consists of taking the user's selected coordinate p322 , and then, if the element has a form owner p353 , submitting p361 the input p303 element's form owner p353 from the input p303 element. If the user activates the control without explicitly selecting a coordinate, then the coordinate (0,0) must be assumed. Otherwise, the element represents p638 a submit button whose label is given by the value of the alt p322 attribute; if the element is mutable p306 , the user agent should allow the user to activate the button. The activation behavior p93 in this case consists of setting the selected coordinate p322 to (0,0), and then, if the element has a form owner p353 , submitting p361 the input p303 element's form owner p353 from the input p303 element. The selected coordinate must consist of an x-component and a y-component. The coordinates represent the position relative to the edge of the image, with the coordinate space having the positive x direction to the right, and the positive y direction downwards. The x-component must be a valid integer p35 representing a number x in the range −(borderleft+paddingleft) ≤ x ≤ width+borderright+paddingright, where width is the rendered width of the image, borderleft is the width of the border on the left of the image, paddingleft is the width of the padding on the left of the image, borderright is the width of the border on the right of the image, and paddingright is the width of the padding on the right of the image, with all dimensions given in CSS pixels. The y-component must be a valid integer p35 representing a number y in the range −(bordertop+paddingtop) ≤ y ≤ height+borderbottom+paddingbottom, where height is the rendered height of the image, bordertop is the width of the border above the image, paddingtop is the width of the padding above the image, borderbottom is the width of the border below the image, and paddingbottom is the width of the padding below the image, with all dimensions given in CSS pixels. Where a border or padding is missing, its width is zero CSS pixels. The formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , and formtarget p356 attributes are attributes for form submission p355 . 322 Bookkeeping details ▪The following common input p303 element content attributes and IDL attributes apply to the element: alt p322 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , src p321 , and width p271 content attributes; value p330 IDL attribute. ▪The value p330 IDL attribute is in mode default p331 . ▪The following content attributes must not be specified and do not apply to the element: accept p320 , autocomplete p324 , checked p306 , list p324 , max p328 , maxlength p327 , min p328 , multiple p327 , pattern p328 , placeholder p329 , readonly p325 , required p326 , size p326 , and step p329 . ▪The element's value p306 attribute must be omitted. ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , list p332 , selectedOption p332 , selectionStart p517 , selectionEnd p517 , valueAsDate p331 , and valueAsNumber p331 IDL attributes; select() p517 , setSelectionRange() p517 , stepDown() p331 , and stepUp() p331 methods. ▪The input p332 and change p332 events do not apply. Note: Many aspects of this state's behavior are similar to the behavior of the img p186 element. Readers are encouraged to read that section, where many of the same requirements are described in more detail. 4.10.7.1.21 Reset Button state When an input p303 element's type p304 attribute is in the Reset Button p323 state, the rules in this section apply. The input p303 element represents p638 a button that, when activated, resets the form. If the element has a value p306 attribute, the button's label must be the value of that attribute; otherwise, it must be an implementation-defined string that means "Reset" or some such. The element is a button p297 . If the element is mutable p306 , the user agent should allow the user to activate the element. The element's activation behavior p93 , if the element has a form owner p353 , is to reset p366 the form owner p353 ; otherwise, it is to do nothing. Constraint validation: The element is barred from constraint validation p356 . Bookkeeping details ▪The value p330 IDL attribute applies to this element and is in mode default p331 . ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , autocomplete p324 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , list p324 , max p328 , maxlength p327 , min p328 , multiple p327 , pattern p328 , placeholder p329 , readonly p325 , required p326 , size p326 , src p321 , step p329 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , list p332 , selectedOption p332 , selectionStart p517 , selectionEnd p517 , valueAsDate p331 , and valueAsNumber p331 IDL attributes; select() p517 , setSelectionRange() p517 , stepDown() p331 , and stepUp() p331 methods. ▪The input p332 and change p332 events do not apply. 4.10.7.1.22 Button state When an input p303 element's type p304 attribute is in the Button p323 state, the rules in this section apply. The input p303 element represents p638 a button with no default behavior. If the element has a value p306 attribute, the button's label must be the value of that attribute; otherwise, it must be the empty string. The element is a button p297 . If the element is mutable p306 , the user agent should allow the user to activate the element. The element's activation behavior p93 is to do nothing. Constraint validation: The element is barred from constraint validation p356 . Bookkeeping details ▪The value p330 IDL attribute applies to this element and is in mode default p331 . ▪The following content attributes must not be specified and do not apply to the element: accept p320 , alt p322 , autocomplete p324 , checked p306 , formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , formtarget p356 , height p271 , list p324 , max p328 , maxlength p327 , min p328 , multiple p327 , pattern p328 , placeholder p329 , readonly p325 , required p326 , size p326 , src p321 , step p329 , and width p271 . ▪The following IDL attributes and methods do not apply to the element: checked p331 , files p331 , list p332 , selectedOption p332 , selectionStart p517 , selectionEnd p517 , valueAsDate p331 , and valueAsNumber p331 IDL attributes; select() p517 , setSelectionRange() p517 , stepDown() p331 , and stepUp() p331 methods. ▪The input p332 and change p332 events do not apply. 323 4.10.7.2 Common input p303 element attributes These attributes only apply to an input p303 element if its type p304 attribute is in a state whose definition declares that the attribute applies. When an attribute doesn't apply to an input p303 element, user agents must ignore p27 the attribute, regardless of the requirements and definitions below. 4.10.7.2.1 The autocomplete p324 attribute User agents sometimes have features for helping users fill forms in, for example prefilling the user's address based on earlier user input. The autocomplete attribute is an enumerated attribute p34 . The attribute has three states. The on keyword maps to the on state, and the off keyword maps to the off state. The attribute may also be omitted. The missing value default is the default state. The off p324 state indicates either that the control's input data is particularly sensitive (for example the activation code for a nuclear weapon); or that it is a value that will never be reused (for example a one-time-key for a bank login) and the user will therefore have to explicitly enter the data each time, instead of being able to rely on the UA to prefill the value for him; or that the document provides its own autocomplete mechanism and does not want the user agent to provide autocompletion values. Conversely, the on p324 state indicates that the value is not particularly sensitive and the user can expect to be able to rely on his user agent to remember values he has entered for that control. The default p324 state indicates that the user agent is to use the autocomplete p298 attribute on the element's form owner p353 instead. (By default, the autocomplete p298 attribute of form p297 elements is in the on p298 state.) Each input p303 element has a resulting autocompletion state, which is either on or off. When an input p303 element is in one of the following conditions, the input p303 element's resulting autocompletion state p324 is on; otherwise, the input p303 element's resulting autocompletion state p324 is off: • • • Its autocomplete p324 attribute is in the on p324 state. Its autocomplete p324 attribute is in the default p324 state, and the element has no form owner p353 . Its autocomplete p324 attribute is in the default p324 state, and the element's form owner p353 's autocomplete p298 attribute is in the on p298 state. When an input p303 element's resulting autocompletion state p324 is on, the user agent may store the value entered by the user so that if the user returns to the page, the UA can prefill the form. Otherwise, the user agent should not remember the control's value p354 , and should not offer past values to the user. In addition, if the resulting autocompletion state p324 is off, values are reset p466 when traversing the history p465 . The autocompletion mechanism must be implemented by the user agent acting as if the user had modified the element's value p354 , and must be done at a time where the element is mutable p306 (e.g. just after the element has been inserted into the document, or when the user agent stops parsing p618 ). Banks frequently do not want UAs to prefill login information:

    A user agent may allow the user to override the resulting autocompletion state p324 and set it to always on, always allowing values to be remembered and prefilled), or always off, never remembering values. However, the ability to override the resulting autocompletion state p324 to on should not be trivially accessible, as there are significant security implications for the user if all values are always remembered, regardless of the site's preferences. 4.10.7.2.2 The list p324 attribute The list attribute is used to identify an element that lists predefined options suggested to the user. If present, its value must be the ID of a datalist p338 element in the same document. The suggestions source element is the first element in the document in tree order p27 to have an ID equal to the value of the list p324 attribute, if that element is a datalist p338 element. If there is no list p324 attribute, or if there is no element with that ID, or if the first element with that ID is not a datalist p338 element, then there is no suggestions source element p324 . If there is a suggestions source element p324 , then, when the user agent is allowing the user to edit the input p303 element's value p354 , the user agent should offer the suggestions represented by the suggestions source element p324 to the user in a manner suitable for the type of control used. The user agent may use the suggestion's label p340 to identify the suggestion if appropriate. If the user selects a suggestion, then the input p303 element's value p354 must be set to the selected suggestion's value p340 , as if the user had written that value himself. 324 User agents must filter the suggestions to hide suggestions that the user would not be allowed to enter as the input p303 element's value p354 , and should filter the suggestions to hide suggestions that would cause the element to not satisfy its constraints p357 . If the list p324 attribute does not apply, there is no suggestions source element p324 . This URL field offers some suggestions. Other URLs from the user's history might show also; this is up to the user agent. This example demonstrates how to design a form that uses the autocompletion list feature while still degrading usefully in legacy user agents. If the autocompletion list is merely an aid, and is not important to the content, then simply using a datalist p338 element with children option p339 elements is enough. To prevent the values from being rendered in legacy user agents, they should be placed inside the value p340 attribute instead of inline.

    However, if the values need to be shown in legacy UAs, then fallback content can be placed inside the datalist p338 element, as follows:

    The fallback content will only be shown in UAs that don't support datalist p338 . The options, on the other hand, will be detected by all UAs, even though they are not direct children of the datalist p338 element. Note that if an option p339 element used in a datalist p338 is selected p340 , it will be selected by default by legacy UAs (because it affects the select p334 ), but it will not have any effect on the input p303 element in UAs that support datalist p338 . 4.10.7.2.3 The readonly p325 attribute The readonly attribute is a boolean attribute p34 that controls whether or not the use can edit the form control. When specified, the element is immutable p306 . Constraint validation: If the readonly p325 attribute is specified on an input p303 element, the element is barred from constraint validation p356 . 325 In the following example, the existing product identifiers cannot be modified, but they are still displayed as part of the form, for consistency with the row representing a new product (where the identifier is not yet filled in).
    Product ID Product name Price Action
    $
    $
    $

    4.10.7.2.4 The size p326 attribute The size attribute gives the number of characters that, in a visual rendering, the user agent is to allow the user to see while editing the element's value p354 . The size p326 attribute, if specified, must have a value that is a valid non-negative integer p35 greater than zero. If the attribute is present, then its value must be parsed using the rules for parsing non-negative integers p35 , and if the result is a number greater than zero, then the user agent should ensure that at least that many characters are visible. The size p307 IDL attribute is limited to only non-negative numbers greater than zero p58 . 4.10.7.2.5 The required p326 attribute The required attribute is a boolean attribute p34 . When specified, the element is required. Constraint validation: If the element is required p326 , and its value p330 IDL attribute applies and is in the mode value p330 , and the element is mutable p306 , and the element's value p354 is the empty string, then the element is suffering from being missing p357 . The following form has two required fields, one for an e-mail address and one for a password. It also has a third field that is only considerd valid if the user types the same password in the password field and this third field.

    Create new account

    326 4.10.7.2.6 The multiple p327 attribute The multiple attribute is a boolean attribute p34 that indicates whether the user is to be allowed to specify more than one value. The following extract shows how an e-mail client's "Cc" field could accept multiple e-mail addresses. If the user had, amongst many friends in his user contacts database, two friends "Arthur Dent" (with address "art@example.net") and "Adam Josh" (with address "adamjosh@example.net"), then, after the user has typed "a", the user agent might suggest these two e-mail addresses to the user. The page could also link in the user's contacts database from the site: ... Suppose the user had entered "bob@example.net" into this text field, and then started typing a second email address starting with "a". The user agent might show both the two friends mentioned earlier, as well as the "astrophy" and "astronomy" values given in the datalist p338 element. The following extract shows how an e-mail client's "Attachments" field could accept multiple files for upload. 4.10.7.2.7 The maxlength p327 attribute The maxlength attribute, when it applies, is a form control maxlength attribute p355 controlled by the input p303 element's dirty value flag p306 . If the input p303 element has a maximum allowed value length p355 , then the code-point length p34 of the value of the element's value p306 attribute must be equal to or less than the element's maximum allowed value length p355 . The following extract shows how a messaging client's text entry could be arbitrarily restricted to a fixed number of characters, thus forcing any conversion through this medium to be terse and discouraging intelligent discourse. What are you doing? 327 4.10.7.2.8 The pattern p328 attribute The pattern attribute specifies a regular expression against which the control's value p354 is to be checked. If specified, the attribute's value must match the JavaScript Pattern production. [ECMA262] p701 Constraint validation: If the element's value p354 is not the empty string, and the element's pattern p328 attribute is specified and the attribute's value, when compiled as a JavaScript regular expression with the global, ignoreCase, and multiline flags disabled (see ECMA262 Edition 5, sections 15.10.7.2 through 15.10.7.4), compiles successfully but the resulting regular expression does not match the entirety of the element's value p354 , then the element is suffering from a pattern mismatch p357 . [ECMA262] p701 Note: This implies that the regular expression language used for this attribute is the same as that used in JavaScript, except that the pattern p328 attribute must match the entire value, not just any subset (somewhat as if it implied a ^(?: at the start of the pattern and a )$ at the end). When an input p303 element has a pattern p328 attribute specified, authors should include a title p84 attribute to give a description of the pattern. User agents may use the contents of this attribute, if it is present, when informing the user that the pattern is not matched, or at any other suitable time, such as in a tooltip or read out by assistive technology when the control gains focus. For example, the following snippet: ...could cause the UA to display an alert such as: A part number is a digit followed by three uppercase letters. You cannot complete this form until the field is correct. When a control has a pattern p328 attribute, the title p84 attribute, if used, must describe the pattern. Additional information could also be included, so long as it assists the user in filling in the control. Otherwise, assistive technology would be impaired. For instance, if the title attribute contained the caption of the control, assistive technology could end up saying something like The text you have entered does not match the required pattern. Birthday, which is not useful. UAs may still show the title p107 in non-error situations (for example, as a tooltip when hovering over the control), so authors should be careful not to word title p107 s as if an error has necessarily occurred. 4.10.7.2.9 The min p328 and max p328 attributes The min and max attributes indicate the allowed range of values for the element. Their syntax is defined by the section that defines the type p304 attribute's current state. If the element has a min p328 attribute, and the result of applying the algorithm to convert a string to a number p306 to the value of the min p328 attribute is a number, then that number is the element's minimum; otherwise, if the type p304 attribute's current state defines a default minimum, then that is the minimum p328 ; otherwise, the element has no minimum p328 . Constraint validation: When the element has a minimum p328 , and the result of applying the algorithm to convert a string to a number p306 to the string given by the element's value p354 is a number, and the number obtained from that algorithm is less than the minimum p328 , the element is suffering from an underflow p357 . The min p328 attribute also defines the step base p329 . If the element has a max p328 attribute, and the result of applying the algorithm to convert a string to a number p306 to the value of the max p328 attribute is a number, then that number is the element's maximum; otherwise, if the type p304 attribute's current state defines a default maximum, then that is the maximum p328 ; otherwise, the element has no maximum p328 . Constraint validation: When the element has a maximum p328 , and the result of applying the algorithm to convert a string to a number p306 to the string given by the element's value p354 is a number, and the number obtained from that algorithm is more than the maximum p328 , the element is suffering from an overflow p357 . The max p328 attribute's value (the maximum p328 ) must not be less than the min p328 attribute's value (its minimum p328 ). 328 Note: If an element has a maximum p328 that is less than its minimum p328 , then so long as the element has a value p354 , it will either be suffering from an underflow p357 or suffering from an overflow p357 . The following date control limits input to dates that are before the 1980s: The following number control limits input to whole numbers greater than zero: 4.10.7.2.10 The step p329 attribute The step attribute indicates the granularity that is expected (and required) of the value p354 , by limiting the allowed values. The section that defines the type p304 attribute's current state also defines the default step, the step scale factor, and in some cases the default step base, which are used in processing the attribute as described below. The step p329 attribute, if specified, must either have a value that is a valid floating point number p36 that parses p36 to a number that is greater than zero, or must have a value that is an ASCII case-insensitive p33 match for the string "any". The attribute provides the allowed value step for the element, as follows: 1. If the attribute is absent, then the allowed value step p329 is the default step p329 multiplied by the step scale factor p329 . 2. Otherwise, if the attribute's value is an ASCII case-insensitive p33 match for the string "any", then there is no allowed value step p329 . 3. Otherwise, if the rules for parsing floating point number values p36 , when they are applied to the attribute's value, return an error, zero, or a number less than zero, then the allowed value step p329 is the default step p329 multiplied by the step scale factor p329 . 4. Otherwise, the allowed value step p329 is the number returned by the rules for parsing floating point number values p36 when they are applied to the attribute's value, multiplied by the step scale factor p329 . The step base is the result of applying the algorithm to convert a string to a number p306 to the value of the min p328 attribute, unless the element does not have a min p328 attribute specified or the result of applying that algorithm is an error, in which case the step base p329 is the default step base p329 , if one is defined, or zero, if not. Constraint validation: When the element has an allowed value step p329 , and the result of applying the algorithm to convert a string to a number p306 to the string given by the element's value p354 is a number, and that number subtracted from the step base p329 is not an integral multiple of the allowed value step p329 , the element is suffering from a step mismatch p357 . The following range control only accepts values in the range 0..1, and allows 256 steps in that range: The following control allows any time in the day to be selected, with any accuracy (e.g. thousandth-of-asecond accuracy or more): Normally, time controls are limited to an accuracy of one minute. 4.10.7.2.11 The placeholder p329 attribute The placeholder attribute represents a short hint (a word or short phrase) intended to aid the user with data entry. A hint could be a sample value or a brief description of the expected format. The attribute, if specified, must have a value that contains no U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) characters. Note: For a longer hint or other advisory text, the title p84 attribute is more appropriate. The placeholder p329 attribute should not be used as an alternative to a label p301 . User agents should present this hint to the user, after having stripped line breaks p34 from it, when the element's value p354 is the empty string and the control is not focused (e.g. by displaying it inside a blank unfocused control). Here is an example of a mail configuration user interface that uses the placeholder p329 attribute: 329
    Mail Account

    4.10.7.3 Common input p303 element APIs This box is non-normative. Implementation requirements are given below this box. input . value p330 [ = value ] Returns the current value p354 of the form control. Can be set, to change the value. Throws an INVALID_STATE_ERR p70 exception if it is set to any value other than the empty string when the control is a file upload control. input . checked p331 [ = value ] Returns the current checkedness p354 of the form control. Can be set, to change the checkedness p354 . input . files p331 Returns a FileList object listing the selected files p320 of the form control. Throws an INVALID_STATE_ERR p70 exception if the control isn't a file control. input . valueAsDate p331 [ = value ] Returns a Date object representing the form control's value p354 , if applicable; otherwise, returns null. Can be set, to change the value. Throws an INVALID_STATE_ERR p70 exception if the control isn't date- or time-based. input . valueAsNumber p331 [ = value ] Returns a number representing the form control's value p354 , if applicable; otherwise, returns null. Can be set, to change the value. Throws an INVALID_STATE_ERR p70 exception if the control is neither date- or time-based nor numeric. input . stepUp p331 ( [ n ] ) input . stepDown p331 ( [ n ] ) Changes the form control's value p354 by the value given in the step p329 attribute, multiplied by n. The default is 1. Throws INVALID_STATE_ERR p70 exception if the control is neither date- or time-based nor numeric, if the step p329 attribute's value is "any", if the current value p354 could not be parsed, or if stepping in the given direction by the given amount would take the value out of range. input . list p332 Returns the datalist p338 element indicated by the list p324 attribute. input . selectedOption p332 Returns the option p339 element from the datalist p338 element indicated by the list p324 attribute that matches the form control's value p354 . The value IDL attribute allows scripts to manipulate the value p354 of an input p303 element. The attribute is in one of the following modes, which define its behavior: value On getting, it must return the current value p354 of the element. On setting, it must set the element's value p354 to the new value, set the element's dirty value flag p306 to true, and then invoke the value sanitization algorithm p306 , if the element's type p304 attribute's current state defines one. 330 default On getting, if the element has a value p306 attribute, it must return that attribute's value; otherwise, it must return the empty string. On setting, it must set the element's value p306 attribute to the new value. default/on On getting, if the element has a value p306 attribute, it must return that attribute's value; otherwise, it must return the string "on". On setting, it must set the element's value p306 attribute to the new value. filename On getting, it must return the string "C:\fakepath\" followed by the filename of the first file in the list of selected files p320 , if any, or the empty string if the list is empty. On setting, if the new value is the empty string, it must empty the list of selected files p320 ; otherwise, it must throw an INVALID_STATE_ERR p70 exception. The checked IDL attribute allows scripts to manipulate the checkedness p354 of an input p303 element. On getting, it must return the current checkedness p354 of the element; and on setting, it must set the element's checkedness p354 to the new value and set the element's dirty checkedness flag p306 to true. The files IDL attribute allows scripts to access the element's selected files p320 . On getting, if the IDL attribute applies, it must return a FileList object that represents the current selected files p320 . The same object must be returned until the list of selected files p320 changes. If the IDL attribute does not apply, then it must instead throw an INVALID_STATE_ERR p70 exception. [FILEAPI] p701 The valueAsDate IDL attribute represents the value p354 of the element, interpreted as a date. On getting, if the valueAsDate p331 attribute does not apply, as defined for the input p303 element's type p304 attribute's current state, then return null. Otherwise, run the algorithm to convert a string to a Date object p306 defined for that state; if the algorithm returned a Date object, then return it, otherwise, return null. On setting, if the valueAsDate p331 attribute does not apply, as defined for the input p303 element's type p304 attribute's current state, then throw an INVALID_STATE_ERR p70 exception; otherwise, if the new value is null, then set the value p354 of the element to the empty string; otherwise, run the algorithm to convert a Date object to a string p306 , as defined for that state, on the new value, and set the value p354 of the element to resulting string. The valueAsNumber IDL attribute represents the value p354 of the element, interpreted as a number. On getting, if the valueAsNumber p331 attribute does not apply, as defined for the input p303 element's type p304 attribute's current state, then return a Not-a-Number (NaN) value. Otherwise, if the valueAsDate p331 attribute applies, run the algorithm to convert a string to a Date object p306 defined for that state; if the algorithm returned a Date object, then return the time value of the object (the number of milliseconds from midnight UTC the morning of 1970-01-01 to the time represented by the Date object), otherwise, return a Not-a-Number (NaN) value. Otherwise, run the algorithm to convert a string to a number p306 defined for that state; if the algorithm returned a number, then return it, otherwise, return a Not-a-Number (NaN) value. On setting, if the valueAsNumber p331 attribute does not apply, as defined for the input p303 element's type p304 attribute's current state, then throw an INVALID_STATE_ERR p70 exception. Otherwise, if the valueAsDate p331 attribute applies, run the algorithm to convert a Date object to a string p306 defined for that state, passing it a Date object whose time value is the new value, and set the value p354 of the element to resulting string. Otherwise, run the algorithm to convert a number to a string p306 , as defined for that state, on the new value, and set the value p354 of the element to resulting string. The stepDown(n) and stepUp(n) methods, when invoked, must run the following algorithm: 1. If the stepDown() p331 and stepUp() p331 methods do not apply, as defined for the input p303 element's type p304 attribute's current state, then throw an INVALID_STATE_ERR p70 exception, and abort these steps. 2. If the element has no allowed value step p329 , then throw an INVALID_STATE_ERR p70 exception, and abort these steps. 3. If applying the algorithm to convert a string to a number p306 to the string given by the element's value p354 results in an error, then throw an INVALID_STATE_ERR p70 exception, and abort these steps; otherwise, let value be the result of that algorithm. 4. Let n be the argument, or 1 if the argument was omitted. 5. Let delta be the allowed value step p329 multiplied by n. 6. If the method invoked was the stepDown() p331 method, negate delta. 331 7. Let value be the result of adding delta to value. 8. If the element has a minimum p328 , and the value is less than that minimum p328 , then throw a INVALID_STATE_ERR p70 exception. 9. If the element has a maximum p328 , and the value is greater than that maximum p328 , then throw a INVALID_STATE_ERR p70 exception. 10. Let value as string be the result of running the algorithm to convert a number to a string p306 , as defined for the input p303 element's type p304 attribute's current state, on value. 11. Set the value p354 of the element to value as string. The list IDL attribute must return the current suggestions source element p324 , if any, or null otherwise. The selectedOption IDL attribute must return the first option p339 element, in tree order p27 , to be a child of the suggestions source element p324 and whose value p340 matches the input p303 element's value p354 , if any. If there is no suggestions source element p324 , or if it contains no matching option p339 element, then the selectedOption p332 attribute must return null. 4.10.7.4 Common event behaviors When the input event applies, any time the user causes the element's value p354 to change, the user agent must queue a task p490 to fire a simple event p496 that bubbles named input at the input p303 element, then broadcast forminput events p366 at the input p303 element's form owner p353 . User agents may wait for a suitable break in the user's interaction before queuing the task; for example, a user agent could wait for the user to have not hit a key for 100ms, so as to only fire the event when the user pauses, instead of continuously for each keystroke. Examples of a user changing the element's value p354 would include the user typing into a text field, pasting a new value into the field, or undoing an edit in that field. Some user interactions do not cause changes to the value, e.g. hitting the "delete" key in an empty text field, or replacing some text in the field with text from the clipboard that happens to be exactly the same text. When the change event applies, if the element does not have an activation behavior p93 defined but uses a user interface that involves an explicit commit action, then any time the user commits a change to the element's value p354 or list of selected files p320 , the user agent must queue a task p490 to fire a simple event p496 that bubbles named change at the input p303 element, then broadcast formchange events p366 at the input p303 element's form owner p353 . An example of a user interface with a commit action would be a File Upload p320 control that consists of a single button that brings up a file selection dialog: when the dialog is closed, if that the file selection p320 changed as a result, then the user has committed a new file selection p320 . Another example of a user interface with a commit action would be a Date p311 control that allows both textbased user input and user selection from a drop-down calendar: while text input might not have an explicit commit step, selecting a date from the drop down calendar and then dismissing the drop down would be a commit action. When the user agent changes the element's value p354 on behalf of the user (e.g. as part of a form prefilling feature), the user agent must follow these steps: 1. If the input p332 event applies, queue a task p490 to fire a simple event p496 that bubbles named input at the input p303 element. 2. If the input p332 event applies, broadcast forminput events p366 at the input p303 element's form owner p353 . 3. If the change p332 event applies, queue a task p490 to fire a simple event p496 that bubbles named change at the input p303 element. 4. If the change p332 event applies, broadcast formchange events p366 at the input p303 element's form owner p353 . Note: In addition, when the change p332 event applies, change events can also be fired as part of the element's activation behavior p93 and as part of the unfocusing steps p511 . The task source p490 for these tasks p489 is the user interaction task source p491 . 4.10.8 The button element 332 Categories Flow content p91 . Phrasing content p91 . Interactive content p92 . Listed p297 , labelable p297 , and submittable p297 form-associated element p297 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 , but there must be no interactive content p92 descendant. Content attributes: Global attributes p82 autofocus p354 disabled p354 form p353 formaction p355 formenctype p356 formmethod p355 formnovalidate p356 formtarget p356 name p354 type p333 value p334 DOM interface: interface HTMLButtonElement : HTMLElement { attribute boolean autofocus; attribute boolean disabled; readonly attribute HTMLFormElement form; attribute DOMString formAction; attribute DOMString formEnctype; attribute DOMString formMethod; attribute DOMString formNoValidate; attribute DOMString formTarget; attribute DOMString name; attribute DOMString type; attribute DOMString value; readonly attribute boolean willValidate; readonly attribute ValidityState validity; readonly attribute DOMString validationMessage; boolean checkValidity(); void setCustomValidity(in DOMString error); readonly attribute NodeList labels; }; The button p332 element represents p638 a button. If the element is not disabled p354 , then the user agent should allow the user to activate the button. The element is a button p297 . The type attribute controls the behavior of the button when it is activated. It is an enumerated attribute p34 . The following table lists the keywords and states for the attribute — the keywords in the left column map to the states in the cell in the second column on the same row as the keyword. Keyword State Brief description submit Submit Button p334 Submits the form. reset Reset Button p334 button Button p334 Resets the form. Does nothing. The missing value default is the Submit Button p334 state. If the type p333 attribute is in the Submit Button p334 state, the element is specifically a submit button p297 . 333 Constraint validation: If the type p333 attribute is in the Reset Button p334 state or the Button p334 state, the element is barred from constraint validation p356 . If the element is not disabled p354 , the activation behavior p93 of the button p332 element is to run the steps defined in the following list for the current state of the element's type p333 attribute. Submit Button If the element has a form owner p353 , the element must submit p361 the form owner p353 from the button p332 element. Reset Button If the element has a form owner p353 , the element must reset p366 the form owner p353 . Button Do nothing. The form p353 attribute is used to explicitly associate the button p332 element with its form owner p353 . The name p354 attribute represents the element's name. The disabled p354 attribute is used to make the control non-interactive and to prevent its value from being submitted. The autofocus p354 attribute controls focus. The formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , and formtarget p356 attributes are attributes for form submission p355 . Note: The formnovalidate p356 attribute can be used to make submit buttons that do not trigger the constraint validation. The formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , and formtarget p356 must not be specified if the element's type p333 attribute is not in the Submit Button p334 state. The value attribute gives the element's value for the purposes of form submission. The element's value p354 is the value of the element's value p334 attribute, if there is one, or the empty string otherwise. Note: A button (and its value) is only included in the form submission if the button itself was used to initiate the form submission. The value and type IDL attributes must reflect p57 the respective content attributes of the same name. The willValidate p358 , validity p359 , and validationMessage p359 attributes, and the checkValidity() p359 and setCustomValidity() p358 methods, are part of the constraint validation API p358 . The labels p303 attribute provides a list of the element's label p301 s. The following button is labeled "Show hint" and pops up a dialog box when activated: 4.10.9 The select element Categories Flow content p91 . Phrasing content p91 . Interactive content p92 . Listed p297 , labelable p297 , submittable p297 , and resettable p297 form-associated element p297 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Zero or more option p339 or optgroup p338 elements. Content attributes: Global attributes p82 autofocus p354 disabled p354 form p353 multiple p335 name p354 size p335 334 DOM interface: interface HTMLSelectElement : HTMLElement { attribute boolean autofocus; attribute boolean disabled; readonly attribute HTMLFormElement form; attribute boolean multiple; attribute DOMString name; attribute unsigned long size; readonly attribute DOMString type; readonly attribute HTMLOptionsCollection options; attribute unsigned long length; caller getter any item(in unsigned long index); caller getter any namedItem(in DOMString name); void add(in HTMLElement element, in optional HTMLElement before); void add(in HTMLElement element, in long before); void remove(in long index); readonly attribute HTMLCollection selectedOptions; attribute long selectedIndex; attribute DOMString value; readonly attribute boolean willValidate; readonly attribute ValidityState validity; readonly attribute DOMString validationMessage; boolean checkValidity(); void setCustomValidity(in DOMString error); readonly attribute NodeList labels; }; The select p334 element represents a control for selecting amongst a set of options. The multiple attribute is a boolean attribute p34 . If the attribute is present, then the select p334 element represents p638 a control for selecting zero or more options from the list of options p335 . If the attribute is absent, then the select p334 element represents p638 a control for selecting a single option from the list of options p335 . The list of options for a select p334 element consists of all the option p339 element children of the select p334 element, and all the option p339 element children of all the optgroup p338 element children of the select p334 element, in tree order p27 . The size attribute gives the number of options to show to the user. The size p326 attribute, if specified, must have a value that is a valid non-negative integer p35 greater than zero. If the multiple p335 attribute is present, then the size p326 attribute's default value is 4. If the multiple p335 attribute is absent, then the size p326 attribute's default value is 1. If the multiple p335 attribute is absent, and the element is not disabled p354 , then the user agent should allow the user to pick an option p339 element in its list of options p335 that is itself not disabled p340 . Upon this option p339 element being picked (either through a click, or through unfocusing the element after changing its value, or through a menu command p379 , or through any other mechanism), and before the relevant user interaction event is queued (e.g. before the click p31 event), the user agent must set the selectedness p340 of the picked option p339 element to true and then queue a task p490 to fire a simple event p496 that bubbles named change at the select p334 element, using the user interaction task source p491 as the task source, then broadcast formchange events p366 at the element's form owner p353 . If the multiple p335 attribute is absent, whenever an option p339 element in the select p334 element's list of options p335 has its selectedness p340 set to true, and whenever an option p339 element with its selectedness p340 set to true is added to the select p334 element's list of options p335 , the user agent must set the selectedness p340 of all the other option p339 element in its list of options p335 to false. If the multiple p335 attribute is absent, whenever there are no option p339 elements in the select p334 element's list of options p335 that have their selectedness p340 set to true, the user agent must set the selectedness p340 of the first option p339 element in the list of options p335 in tree order p27 that is not disabled p340 , if any, to true. If the multiple p335 attribute is present, and the element is not disabled p354 , then the user agent should allow the user to toggle the selectedness p340 of the option p339 elements in its list of options p335 that are themselves not 335 disabled p340 (either through a click, or through a menu command p379 , or any other mechanism). Upon the selectedness p340 of one or more option p339 elements being changed by the user, and before the relevant user interaction event is queued (e.g. before a related click p31 event), the user agent must queue a task p490 to fire a simple event p496 that bubbles named change at the select p334 element, using the user interaction task source p491 as the task source, then broadcast formchange events p366 at the element's form owner p353 . The reset algorithm p366 for select p334 elements is to go through all the option p339 elements in the element's list of options p335 , and set their selectedness p340 to true if the option p339 element has a selected p340 attribute, and false otherwise. The form p353 attribute is used to explicitly associate the select p334 element with its form owner p353 . The name p354 attribute represents the element's name. The disabled p354 attribute is used to make the control non-interactive and to prevent its value from being submitted. The autofocus p354 attribute controls focus. This box is non-normative. Implementation requirements are given below this box. select . type p337 Returns "select-multiple" if the element has a multiple p335 attribute, and "select-one" otherwise. select . options p337 Returns an HTMLOptionsCollection p62 of the list of options p335 . select . length p337 [ = value ] Returns the number of elements in the list of options p335 . When set to a smaller number, truncates the number of option p339 elements in the select p334 . When set to a greater number, adds new blank option p339 elements to the select p334 . element = select . item p337 (index) select[index] select(index) Returns the item with index index from the list of options p335 . The items are sorted in tree order p27 . Returns null if index is out of range. element = select . namedItem p337 (name) select[name] select(name) Returns the item with ID or name p662 name from the list of options p335 . If there are multiple matching items, then a NodeList p31 object containing all those elements is returned. Returns null if no element with that ID could be found. select . add p337 (element [, before ]) Inserts element before the node given by before. The before argument can be a number, in which case element is inserted before the item with that number, or an element from the list of options p335 , in which case element is inserted before that element. If before is omitted, null, or a number out of range, then element will be added at the end of the list. This method will throw a HIERARCHY_REQUEST_ERR p70 exception if element is an ancestor of the element into which it is to be inserted. If element is not an option p339 or optgroup p338 element, then the method does nothing. select . selectedOptions p337 Returns an HTMLCollection p59 of the list of options p335 that are selected. select . selectedIndex p337 [ = value ] Returns the index of the first selected item, if any, or −1 if there is no selected item. Can be set, to change the selection. select . value p337 [ = value ] Returns the value p354 of the first selected item, if any, or the empty string if there is no selected item. Can be set, to change the selection. 336 The type IDL attribute, on getting, must return the string "select-one" if the multiple p335 attribute is absent, and the string "select-multiple" if the multiple p335 attribute is present. The options IDL attribute must return an HTMLOptionsCollection p62 rooted at the select p334 node, whose filter matches the elements in the list of options p335 . The options p337 collection is also mirrored on the HTMLSelectElement p335 object. The indices of the supported indexed properties at any instant are the indices supported by the object returned by the options p337 attribute at that instant. The names of the supported named properties at any instant are the names supported by the object returned by the options p337 attribute at that instant. The length IDL attribute must return the number of nodes represented p59 by the options p337 collection. On setting, it must act like the attribute of the same name on the options p337 collection. The item(index) method must return the value returned by the method of the same name on the options p337 collection, when invoked with the same argument. The namedItem(name) method must return the value returned by the method of the same name on the options p337 collection, when invoked with the same argument. Similarly, the add() and remove() methods must act like their namesake methods on that same options p337 collection. The selectedOptions IDL attribute must return an HTMLCollection p59 rooted at the select p334 node, whose filter matches the elements in the list of options p335 that have their selectedness p340 set to true. The selectedIndex IDL attribute, on getting, must return the index p340 of the first option p339 element in the list of options p335 in tree order p27 that has its selectedness p340 set to true, if any. If there isn't one, then it must return −1. On setting, the selectedIndex p337 attribute must set the selectedness p340 of all the option p339 elements in the list of options p335 to false, and then the option p339 element in the list of options p335 whose index p340 is the given new value, if any, must have its selectedness p340 set to true. The value IDL attribute, on getting, must return the value p340 of the first option p339 element in the list of options p335 in tree order p27 that has its selectedness p340 set to true, if any. If there isn't one, then it must return the empty string. On setting, the value p337 attribute must set the selectedness p340 of all the option p339 elements in the list of options p335 to false, and then first the option p339 element in the list of options p335 , in tree order p27 , whose value p340 is equal to the given new value, if any, must have its selectedness p340 set to true. The multiple and size IDL attributes must reflect p57 the respective content attributes of the same name. The size p337 IDL attribute limited to only non-negative numbers greater than zero p58 . The willValidate p358 , validity p359 , and validationMessage p359 attributes, and the checkValidity() p359 and setCustomValidity() p358 methods, are part of the constraint validation API p358 . The labels p303 attribute provides a list of the element's label p301 s. The following example shows how a select p334 element can be used to offer the user with a set of options from which the user can select a single option. The default option is preselected.

    Here, the user is offered a set of options from which he can select any number. By default, all five options are selected.

    4.10.10 The datalist element Categories Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Either: phrasing content p91 . Or: Zero or more option p339 elements. Content attributes: Global attributes p82 DOM interface: interface HTMLDataListElement : HTMLElement { readonly attribute HTMLCollection options; }; The datalist p338 element represents a set of option p339 elements that represent predefined options for other controls. The contents of the element represents fallback content for legacy user agents, intermixed with option p339 elements that represent the predefined options. In the rendering, the datalist p338 element represents p638 nothing and it, along with its children, should be hidden. The datalist p338 element is hooked up to an input p303 element using the list p324 attribute on the input p303 element. Each option p339 element that is a descendant of the datalist p338 element, that is not disabled p340 , and whose value p340 is a string that isn't the empty string, represents a suggestion. Each suggestion has a value p340 and a label p340 . This box is non-normative. Implementation requirements are given below this box. datalist . options p338 Returns an HTMLCollection p59 of the options elements of the table. The options IDL attribute must return an HTMLCollection p59 rooted at the datalist p338 node, whose filter matches option p339 elements. Constraint validation: If an element has a datalist p338 element ancestor, it is barred from constraint validation p356 . 4.10.11 The optgroup element Categories None. Contexts in which this element may be used: As a child of a select p334 element. Content model: Zero or more option p339 elements. Content attributes: Global attributes p82 disabled p339 label p339 DOM interface: interface HTMLOptGroupElement : HTMLElement { attribute boolean disabled; 338 attribute DOMString label; }; The optgroup p338 element represents p638 a group of option p339 elements with a common label. The element's group of option p339 elements consists of the option p339 elements that are children of the optgroup p338 element. When showing option p339 elements in select p334 elements, user agents should show the option p339 elements of such groups as being related to each other and separate from other option p339 elements. The disabled attribute is a boolean attribute p34 and can be used to disable p340 a group of option p339 elements together. The label attribute must be specified. Its value gives the name of the group, for the purposes of the user interface. User agents should use this attribute's value when labelling the group of option p339 elements in a select p334 element. The disabled and label attributes must reflect p57 the respective content attributes of the same name. The following snippet shows how a set of lessons from three courses could be offered in a select p334 dropdown widget:

    Which course would you like to watch today?

    4.10.12 The option element Categories None. Contexts in which this element may be used: As a child of a select p334 element. As a child of a datalist p338 element. As a child of an optgroup p338 element. Content model: Text p91 . Content attributes: Global attributes p82 disabled p340 label p340 selected p340 value p340 DOM interface: [NamedConstructor=Option(), NamedConstructor=Option(in DOMString text), NamedConstructor=Option(in DOMString text, in DOMString value), 339 NamedConstructor=Option(in DOMString text, in DOMString value, in boolean defaultSelected), NamedConstructor=Option(in DOMString text, in DOMString value, in boolean defaultSelected, in boolean selected)] interface HTMLOptionElement : HTMLElement { attribute boolean disabled; readonly attribute HTMLFormElement form; attribute DOMString label; attribute boolean defaultSelected; attribute boolean selected; attribute DOMString value; attribute DOMString text; readonly attribute long index; }; The option p339 element represents p638 an option in a select p334 element or as part of a list of suggestions in a datalist p338 element. The disabled attribute is a boolean attribute p34 . An option p339 element is disabled if its disabled p340 attribute is present or if it is a child of an optgroup p338 element whose disabled p339 attribute is present. An option p339 element that is disabled p340 must prevent any click p31 events that are queued p490 on the user interaction task source p491 from being dispatched on the element. The label attribute provides a label for element. The label of an option p339 element is the value of the label p340 attribute, if there is one, or the textContent p31 of the element, if there isn't. The value attribute provides a value for element. The value of an option p339 element is the value of the value p340 attribute, if there is one, or the textContent p31 of the element, if there isn't. The selected attribute represents the default selectedness p340 of the element. The selectedness of an option p339 element is a boolean state, initially false. If the element is disabled p340 , then the element's selectedness p340 is always false and cannot be set to true. Except where otherwise specified, when the element is created, its selectedness p340 must be set to true if the element has a selected p340 attribute. Whenever an option p339 element's selected p340 attribute is added, its selectedness p340 must be set to true. Note: The Option() p341 constructor with three or fewer arguments overrides the initial state of the selectedness p340 state to always be false even if the third argument is true (implying that a selected p340 attribute is to be set). The fourth argument can be used to explicitly set the initial selectedness p340 state when using the constructor. An option p339 element's index is the number of option p339 element that are in the same list of options p335 but that come before it in tree order p27 . If the option p339 element is not in a list of options p335 , then the option p339 element's index p340 is zero. This box is non-normative. Implementation requirements are given below this box. option . selected p341 Returns true if the element is selected, and false otherwise. option . index p341 Returns the index of the element in its select p334 element's options p337 list. option . form p341 Returns the element's form p297 element, if any, or null otherwise. option . text p341 Same as textContent p31 . option = new Option p341 ( [ text [, value [, defaultSelected [, selected ] ] ] ] ) Returns a new option p339 element. The text argument sets the contents of the element. 340 The value argument sets the value p340 attribute. The defaultSelected argument sets the selected p340 attribute. The selected argument sets whether or not the element is selected. If it is omitted, even if the defaultSelected argument is true, the element is not selected. The disabled and label IDL attributes must reflect p57 the respective content attributes of the same name. The defaultSelected IDL attribute must reflect p57 the selected p340 content attribute. The value IDL attribute, on getting, must return the value of the element's value p340 content attribute, if it has one, or else the value of the element's textContent p31 IDL attribute. On setting, the element's value p340 content attribute must be set to the new value. The selected IDL attribute must return true if the element's selectedness p340 is true, and false otherwise. The index IDL attribute must return the element's index p340 . The text IDL attribute, on getting, must return the same value as the textContent p31 IDL attribute on the element, and on setting, must act as if the textContent p31 IDL attribute on the element had been set to the new value. The form IDL attribute's behavior depends on whether the option p339 element is in a select p334 element or not. If the option p339 has a select p334 element as its parent, or has a colgroup p278 element as its parent and that colgroup p278 element has a select p334 element as its parent, then the form p341 IDL attribute must return the same value as the form p354 IDL attribute on that select p334 element. Otherwise, it must return null. Several constructors are provided for creating HTMLOptionElement p340 objects (in addition to the factory methods from DOM Core such as createElement()): Option(), Option(text), Option(text, value), Option(text, value, defaultSelected), and Option(text, value, defaultSelected, selected). When invoked as constructors, these must return a new HTMLOptionElement p340 object (a new option p339 element). If the text argument is present, the new object must have as its only child a Node p31 with node type TEXT_NODE (3) whose data is the value of that argument. If the value argument is present, the new object must have a value p340 attribute set with the value of the argument as its value. If the defaultSelected argument is present and true, the new object must have a selected p340 attribute set with no value. If the selected argument is present and true, the new object must have its selectedness p340 set to true; otherwise the fourth argument is absent or false, and the selectedness p340 must be set to false, even if the defaultSelected argument is present and true. The element's document must be the active document p439 of the browsing context p439 of the Window p443 object on which the interface object of the invoked constructor is found. 4.10.13 The textarea element Categories Flow content p91 . Phrasing content p91 . Interactive content p92 . Listed p297 , labelable p297 , submittable p297 , and resettable p297 form-associated element p297 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Text p91 . Content attributes: Global attributes p82 autofocus p354 cols p342 disabled p354 form p353 maxlength p343 name p354 placeholder p343 readonly p342 required p343 rows p343 wrap p343 341 DOM interface: interface HTMLTextAreaElement : HTMLElement { attribute boolean autofocus; attribute unsigned long cols; attribute boolean disabled; readonly attribute HTMLFormElement form; attribute long maxLength; attribute DOMString name; attribute DOMString placeholder; attribute boolean readOnly; attribute boolean required; attribute unsigned long rows; attribute DOMString wrap; readonly attribute attribute attribute readonly attribute DOMString type; DOMString defaultValue; DOMString value; unsigned long textLength; readonly attribute boolean willValidate; readonly attribute ValidityState validity; readonly attribute DOMString validationMessage; boolean checkValidity(); void setCustomValidity(in DOMString error); readonly attribute NodeList labels; void select(); attribute unsigned long selectionStart; attribute unsigned long selectionEnd; void setSelectionRange(in unsigned long start, in unsigned long end); }; The textarea p341 element represents p638 a multiline plain text edit control for the element's raw value. The contents of the control represent the control's default value. The raw value p342 of a textarea p341 control must be initially the empty string. The readonly attribute is a boolean attribute p34 used to control whether the text can be edited by the user or not. Constraint validation: If the readonly p342 attribute is specified on a textarea p341 element, the element is barred from constraint validation p356 . A textarea p341 element is mutable if it is neither disabled p354 nor has a readonly p342 attribute specified. When a textarea p341 is mutable p342 , its raw value p342 should be editable by the user. Any time the user causes the element's raw value p342 to change, the user agent must queue a task p490 to fire a simple event p496 that bubbles named input at the textarea p341 element, then broadcast forminput events p366 at the textarea p341 element's form owner p353 . User agents may wait for a suitable break in the user's interaction before queuing the task; for example, a user agent could wait for the user to have not hit a key for 100ms, so as to only fire the event when the user pauses, instead of continuously for each keystroke. A textarea p341 element has a dirty value flag, which must be initially set to false, and must be set to true whenever the user interacts with the control in a way that changes the raw value p342 . When the textarea p341 element's textContent p31 IDL attribute changes value, if the element's dirty value flag p342 is false, then the element's raw value p342 must be set to the value of the element's textContent p31 IDL attribute. The reset algorithm p366 for textarea p341 elements is to set the element's value p342 to the value of the element's textContent p31 IDL attribute. The cols attribute specifies the expected maximum number of characters per line. If the cols p342 attribute is specified, its value must be a valid non-negative integer p35 greater than zero. If applying the rules for parsing nonnegative integers p35 to the attribute's value results in a number greater than zero, then the element's character width is that value; otherwise, it is 20. The user agent may use the textarea p341 element's character width p342 as a hint to the user as to how many characters the server prefers per line (e.g. for visual user agents by making the width of the control be that many 342 characters). In visual renderings, the user agent should wrap the user's input in the rendering so that each line is no wider than this number of characters. The rows attribute specifies the number of lines to show. If the rows p343 attribute is specified, its value must be a valid non-negative integer p35 greater than zero. If applying the rules for parsing non-negative integers p35 to the attribute's value results in a number greater than zero, then the element's character height is that value; otherwise, it is 2. Visual user agents should set the height of the control to the number of lines given by character height p343 . The wrap attribute is an enumerated attribute p34 with two keywords and states: the soft keyword which maps to the Soft state, and the hard keyword which maps to the Hard state. The missing value default is the Soft p343 state. If the element's wrap p343 attribute is in the Hard p343 state, the cols p342 attribute must be specified. The element's value p354 is defined to be the element's raw value p342 with the following transformation applied: 1. Replace every occurrence of a U+000D CARRIAGE RETURN (CR) character not followed by a U+000A LINE FEED (LF) character, and every occurrence of a U+000A LINE FEED (LF) character not preceded by a U+000D CARRIAGE RETURN (CR) character, by a two-character string consisting of a U+000D CARRIAGE RETURN U+000A LINE FEED (CRLF) character pair. 2. If the element's wrap p343 attribute is in the Hard p343 state, insert U+000D CARRIAGE RETURN U+000A LINE FEED (CRLF) character pairs into the string using a UA-defined algorithm so that each line has no more than character width p342 characters. For the purposes of this requirement, lines are delimited by the start of the string, the end of the string, and U+000D CARRIAGE RETURN U+000A LINE FEED (CRLF) character pairs. The maxlength attribute is a form control maxlength attribute p355 controlled by the textarea p341 element's dirty value flag p342 . If the textarea p341 element has a maximum allowed value length p355 , then the element's children must be such that the code-point length p34 of the value of the element's textContent p31 IDL attribute is equal to or less than the element's maximum allowed value length p355 . The required attribute is a boolean attribute p34 . When specified, the user will be required to enter a value before submitting the form. Constraint validation: If the element has its required p343 attribute specified, and the element is mutable p342 , and the element's value p354 is the empty string, then the element is suffering from being missing p357 . The placeholder attribute represents a hint (a word or short phrase) intended to aid the user with data entry. A hint could be a sample value or a brief description of the expected format. The attribute, if specified, must have a value that contains no U+000A LINE FEED (LF) or U+000D CARRIAGE RETURN (CR) characters. Note: For a longer hint or other advisory text, the title p84 attribute is more appropriate. The placeholder p343 attribute should not be used as an alternative to a label p301 . User agents should present this hint to the user, after having stripped line breaks p34 from it, when the element's value p354 is the empty string and the control is not focused (e.g. by displaying it inside a blank unfocused control). The form p353 attribute is used to explicitly associate the textarea p341 element with its form owner p353 . The name p354 attribute represents the element's name. The disabled p354 attribute is used to make the control non-interactive and to prevent its value from being submitted. The autofocus p354 attribute controls focus. This box is non-normative. Implementation requirements are given below this box. textarea . type Returns the string "textarea". textarea . value Returns the current value of the element. Can be set, to change the value. The cols, placeholder, required, rows, and wrap attributes must reflect p57 the respective content attributes of the same name. The cols p343 and rows p343 attributes are limited to only non-negative numbers greater than zero p58 . The maxLength IDL attribute must reflect p57 the maxlength p343 content attribute, limited to only nonnegative numbers p58 . The readOnly IDL attribute must reflect p57 the readonly p342 content attribute. 343 The type IDL attribute must return the value "textarea". The defaultValue IDL attribute must act like the element's textContent p31 IDL attribute. The value attribute must, on getting, return the element's raw value p342 ; on setting, it must set the element's raw value p342 to the new value. The textLength IDL attribute must return the code-point length p34 of the element's value p354 . The willValidate p358 , validity p359 , and validationMessage p359 attributes, and the checkValidity() p359 and setCustomValidity() p358 methods, are part of the constraint validation API p358 . The labels p303 attribute provides a list of the element's label p301 s. The select() p517 , selectionStart p517 , selectionEnd p517 , and setSelectionRange() p517 methods and attributes expose the element's text selection. Here is an example of a textarea p341 being used for unrestricted free-form text input in a form:

    If you have any comments, please let us know:

    4.10.14 The keygen element Categories Flow content p91 . Phrasing content p91 . Interactive content p92 . Listed p297 , labelable p297 , submittable p297 , and resettable p297 form-associated element p297 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Empty. Content attributes: Global attributes p82 autofocus p354 challenge p344 disabled p354 form p353 keytype p344 name p354 DOM interface: interface HTMLKeygenElement : HTMLElement { attribute boolean autofocus; attribute DOMString challenge; attribute boolean disabled; readonly attribute HTMLFormElement form; attribute DOMString keytype; attribute DOMString name; readonly attribute DOMString type; readonly attribute boolean willValidate; readonly attribute ValidityState validity; readonly attribute DOMString validationMessage; boolean checkValidity(); void setCustomValidity(in DOMString error); readonly attribute NodeList labels; }; The keygen p344 element represents p638 a key pair generator control. When the control's form is submitted, the private key is stored in the local keystore, and the public key is packaged and sent to the server. The challenge attribute may be specified. Its value will be packaged with the submitted key. The keytype attribute is an enumerated attribute p34 . The following table lists the keywords and states for the attribute — the keywords in the left column map to the states listed in the cell in the second column on the same 344 row as the keyword. User agents are not required to support these values, and must only recognize values whose corresponding algorithms they support. Keyword State rsa RSA The invalid value default state is the unknown state. The missing value default state is the RSA state, if it is supported, or the unknown state otherwise. Note: This specification does not specify what key types user agents are to support — it is possible for a user agent to not support any key types at all. The user agent may expose a user interface for each keygen p344 element to allow the user to configure settings of the element's key pair generator, e.g. the key length. The reset algorithm p366 for keygen p344 elements is to set these various configuration settings back to their defaults. The element's value p354 is the string returned from the following algorithm: 1. Use the appropriate step from the following list: p344 attribute is in the RSA state ↪ If the keytype Generate an RSA key pair using the settings given by the user, if appropriate, using the md5WithRSAEncryption RSA signature algorithm (the signature algorithm with MD5 and the RSA encryption algorithm) referenced in section 2.2.1 ("RSA Signature Algorithm") of RFC 3279, and defined in RFC 2313. [RFC3279] p703 [RFC2313] p702 p344 attribute is in the unknown state ↪ Otherwise, the keytype The given key type is not supported. Return the empty string and abort this algorithm. Let private key be the generated private key. Let public key be the generated public key. Let signature algorithm be the selected signature algorithm. 2. If the element has a challenge p344 attribute, then let challenge be that attribute's value. Otherwise, let challenge be the empty string. 3. Let algorithm be an ASN.1 AlgorithmIdentifier structure as defined by RFC 5280, with the algorithm field giving the ASN.1 OID used to identify signature algorithm, using the OIDs defined in section 2.2 ("Signature Algorithms") of RFC 3279, and the parameters field set up as required by RFC 3279 for AlgorithmIdentifier structures for that algorithm. [X690] p705 [RFC5280] p703 [RFC3279] p703 4. Let spki be an ASN.1 SubjectPublicKeyInfo structure as defined by RFC 5280, with the algorithm field set to the algorithm structure from the previous step, and the subjectPublicKey field set to the BIT STRING value resulting from ASN.1 DER encoding the public key. [X690] p705 [RFC5280] p703 5. Let publicKeyAndChallenge be an ASN.1 PublicKeyAndChallenge p345 structure as defined below, with the spki field set to the spki structure from the previous step, and the challenge field set to the string challenge obtained earlier. [X690] p705 6. Let signature be the BIT STRING value resulting from ASN.1 DER encoding the signature generated by applying the signature algorithm to the byte string obtained by ASN.1 DER encoding the publicKeyAndChallenge structure, using private key as the signing key. [X690] p705 7. Let signedPublicKeyAndChallenge be an ASN.1 SignedPublicKeyAndChallenge p345 structure as defined below, with the publicKeyAndChallenge field set to the publicKeyAndChallenge structure, the signatureAlgorithm field set to the algorithm structure, and the signature field set to the BIT STRING signature from the previous step. [X690] p705 8. Return the result of base64 encoding the result of ASN.1 DER encoding the signedPublicKeyAndChallenge structure. [RFC3548] p703 [X690] p705 The data objects used by the above algorithm are defined as follows. These definitions use the same "ASN.1-like" syntax defined by RFC 5280. [RFC5280] p703 PublicKeyAndChallenge ::= SEQUENCE { spki SubjectPublicKeyInfo, challenge IA5STRING } SignedPublicKeyAndChallenge ::= SEQUENCE { 345 publicKeyAndChallenge PublicKeyAndChallenge, signatureAlgorithm AlgorithmIdentifier, signature BIT STRING } Constraint validation: The keygen p344 element is barred from constraint validation p356 . The form p353 attribute is used to explicitly associate the keygen p344 element with its form owner p353 . The name p354 attribute represents the element's name. The disabled p354 attribute is used to make the control non-interactive and to prevent its value from being submitted. The autofocus p354 attribute controls focus. This box is non-normative. Implementation requirements are given below this box. keygen . type Returns the string "keygen". The challenge IDL attribute must reflect p57 the content attributes of the same name. The keytype IDL attribute must reflect p57 the content attributes of the same name, limited to only known values p58 . The type IDL attribute must return the value "keygen". The willValidate p358 , validity p359 , and validationMessage p359 attributes, and the checkValidity() p359 and setCustomValidity() p358 methods, are part of the constraint validation API p358 . The labels p303 attribute provides a list of the element's label p301 s. Note: This specification does not specify how the private key generated is to be used. It is expected that after receiving the SignedPublicKeyAndChallenge p345 (SPKAC) structure, the server will generate a client certificate and offer it back to the user for download; this certificate, once downloaded and stored in the key store along with the private key, can then be used to authenticate to services that use SSL and certificate authentication. To generate a key pair, add the private key to the user's key store, and submit the public key to the server, markup such as the following can be used:

    The server will then receive a form submission with a packaged RSA public key as the value of "key". This can then be used for various purposes, such as generating a client certificate, as mentioned above. 4.10.15 The output element Categories Flow content p91 . Phrasing content p91 . Listed p297 , labelable p297 , and resettable p297 form-associated element p297 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 . Content attributes: Global attributes p82 for p347 form p353 name p354 DOM interface: interface HTMLOutputElement : HTMLElement { [PutForwards=value] readonly attribute DOMSettableTokenList htmlFor; 346 readonly attribute HTMLFormElement form; attribute DOMString name; readonly attribute DOMString type; attribute DOMString defaultValue; attribute DOMString value; readonly attribute boolean willValidate; readonly attribute ValidityState validity; readonly attribute DOMString validationMessage; boolean checkValidity(); void setCustomValidity(in DOMString error); readonly attribute NodeList labels; }; The output p346 element represents p638 the result of a calculation. The for content attribute allows an explicit relationship to be made between the result of a calculation and the elements that represent the values that went into the calculation or that otherwise influenced the calculation. The for p347 attribute, if specified, must contain a string consisting of an unordered set of unique space-separated tokens p49 , each of which must have the value of an ID of an element in the same Document p31 . The form p353 attribute is used to explicitly associate the output p346 element with its form owner p353 . The name p354 attribute represents the element's name. The element has a value mode flag which is either value or default. Initially, the value mode flag p347 must be set to default. When the value mode flag p347 is in mode default, the contents of the element represent both the value of the element and its default value. When the value mode flag p347 is in mode value, the contents of the element represent the value of the element only, and the default value is only accessible using the defaultValue p347 IDL attribute. The element also has a default value. Initially, the default value p347 must be the empty string. Whenever the element's descendants are changed in any way, if the value mode flag p347 is in mode default, the element's default value p347 must be set to the value of the element's textContent p31 IDL attribute. The reset algorithm p366 for output p346 elements is to set the element's textContent p31 IDL attribute to the value of the element's defaultValue p347 IDL attribute (thus replacing the element's child nodes), and then to set the element's value mode flag p347 to default. This box is non-normative. Implementation requirements are given below this box. output . value p347 [ = value ] Returns the element's current value. Can be set, to change the value. output . defaultValue p347 [ = value ] Returns the element's current default value. Can be set, to change the default value. output . type p347 Returns the string "output". The value IDL attribute must act like the element's textContent p31 IDL attribute, except that on setting, in addition, before the child nodes are changed, the element's value mode flag p347 must be set to value. The defaultValue IDL attribute, on getting, must return the element's default value p347 . On setting, the attribute must set the element's default value p347 , and, if the element's value mode flag p347 is in the mode default, set the element's textContent p31 IDL attribute as well. The type attribute must return the string "output". The htmlFor IDL attribute must reflect p57 the for p347 content attribute. 347 The willValidate p358 , validity p359 , and validationMessage p359 attributes, and the checkValidity() p359 and setCustomValidity() p358 methods, are part of the constraint validation API p358 . The labels p303 attribute provides a list of the element's label p301 s. Constraint validation: output p346 elements are always barred from constraint validation p356 . A simple calculator could use output p346 for its display of calculated results:
    + =
    4.10.16 The progress element Categories Flow content p91 . Phrasing content p91 . Labelable p297 form-associated element p297 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 , but there must be no progress p348 element descendants. Content attributes: Global attributes p82 value p348 max p348 form p353 DOM interface: interface HTMLProgressElement : HTMLElement { attribute float value; attribute float max; readonly attribute float position; readonly attribute HTMLFormElement form; readonly attribute NodeList labels; }; The progress p348 element represents p638 the completion progress of a task. The progress is either indeterminate, indicating that progress is being made but that it is not clear how much more work remains to be done before the task is complete (e.g. because the task is waiting for a remote host to respond), or the progress is a number in the range zero to a maximum, giving the fraction of work that has so far been completed. There are two attributes that determine the current task completion represented by the element. The value attribute specifies how much of the task has been completed, and the max attribute specifies how much work the task requires in total. The units are arbitrary and not specified. Authors are encouraged to also include the current value and the maximum value inline as text inside the element, so that the progress is made available to users of legacy user agents. Here is a snippet of a Web application that shows the progress of some automated task:

    Task Progress

    Progress: 0%

    (The updateProgress() method in this example would be called by some other code on the page to update the actual progress bar as the task progressed.) 348 The value p348 and max p348 attributes, when present, must have values that are valid floating point numbers p36 . The value p348 attribute, if present, must have a value equal to or greater than zero, and less than or equal to the value of the max p348 attribute, if present, or 1.0, otherwise. The max p348 attribute, if present, must have a value greater than zero. Note: The progress p348 element is the wrong element to use for something that is just a gauge, as opposed to task progress. For instance, indicating disk space usage using progress p348 would be inappropriate. Instead, the meter p349 element is available for such use cases. User agent requirements: If the value p348 attribute is omitted, then the progress bar is an indeterminate progress bar. Otherwise, it is a determinate progress bar. If the progress bar is a determinate progress bar and the element has a max p348 attribute, the user agent must parse the max p348 attribute's value according to the rules for parsing floating point number values p36 . If this does not result in an error, and if the parsed value is greater than zero, then the maximum value of the progress bar is that value. Otherwise, if the element has no max p348 attribute, or if it has one but parsing it resulted in an error, or if the parsed value was less than or equal to zero, then the maximum value of the progress bar is 1.0. If the progress bar is a determinate progress bar, user agents must parse the value p348 attribute's value according to the rules for parsing floating point number values p36 . If this does not result in an error, and if the parsed value is less than the maximum value and greater than zero, then the current value of the progress bar is that parsed value. Otherwise, if the parsed value was greater than or equal to the maximum value, then the current value of the progress bar is the maximum value of the progress bar. Otherwise, if parsing the value p348 attribute's value resulted in an error, or a number less than or equal to zero, then the current value of the progress bar is zero. UA requirements for showing the progress bar: When representing a progress p348 element to the user, the UA should indicate whether it is a determinate or indeterminate progress bar, and in the former case, should indicate the relative position of the current value relative to the maximum value. The max and value IDL attributes must reflect p57 the respective content attributes of the same name. When the relevant content attributes are absent, the IDL attributes must return zero. The form p353 attribute is used to explicitly associate the progress p348 element with its form owner p353 . This box is non-normative. Implementation requirements are given below this box. progress . position p349 For a determinate progress bar (one with known current and maximum values), returns the result of dividing the current value by the maximum value. For an indeterminate progress bar, returns −1. If the progress bar is an indeterminate progress bar, then the position IDL attribute must return −1. Otherwise, it must return the result of dividing the current value by the maximum value. The labels p303 attribute provides a list of the element's label p301 s. 4.10.17 The meter element Categories Flow content p91 . Phrasing content p91 . Labelable p297 form-associated element p297 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Phrasing content p91 , but there must be no meter p349 element descendants. Content attributes: Global attributes p82 value p350 min p350 max p350 low p350 high p350 optimum p350 form p353 349 DOM interface: interface HTMLMeterElement : HTMLElement { attribute float value; attribute float min; attribute float max; attribute float low; attribute float high; attribute float optimum; readonly attribute HTMLFormElement form; readonly attribute NodeList labels; }; The meter p349 element represents p638 a scalar measurement within a known range, or a fractional value; for example disk usage, the relevance of a query result, or the fraction of a voting population to have selected a particular candidate. This is also known as a gauge. Note: The meter p349 element should not be used to indicate progress (as in a progress bar). For that role, HTML provides a separate progress p348 element. Note: The meter p349 element also does not represent a scalar value of arbitrary range — for example, it would be wrong to use this to report a weight, or height, unless there is a known maximum value. There are six attributes that determine the semantics of the gauge represented by the element. The min attribute specifies the lower bound of the range, and the max attribute specifies the upper bound. The value attribute specifies the value to have the gauge indicate as the "measured" value. The other three attributes can be used to segment the gauge's range into "low", "medium", and "high" parts, and to indicate which part of the gauge is the "optimum" part. The low attribute specifies the range that is considered to be the "low" part, and the high attribute specifies the range that is considered to be the "high" part. The optimum attribute gives the position that is "optimum"; if that is higher than the "high" value then this indicates that the higher the value, the better; if it's lower than the "low" mark then it indicates that lower values are better, and naturally if it is in between then it indicates that neither high nor low values are good. Authoring requirements: The value p350 attribute must be specified. The value p350 , min p350 , low p350 , high p350 , max p350 , and optimum p350 attributes, when present, must have values that are valid floating point numbers p36 . In addition, the attributes' values are further constrained: Let value be the value p350 attribute's number. If the min p350 attribute attribute is specified, then let minimum be that attribute's value; otherwise, let it be zero. If the max p350 attribute attribute is specified, then let maximum be that attribute's value; otherwise, let it be 1.0. The following inequalities must hold, as applicable: • • • • • minimum ≤ value ≤ maximum minimum ≤ low p350 ≤ maximum (if low p350 is specified) minimum ≤ high p350 ≤ maximum (if high p350 is specified) minimum ≤ optimum p350 ≤ maximum (if optimum p350 is specified) low p350 ≤ high p350 (if both low p350 and high p350 are specified) Note: If no minimum or maximum is specified, then the range is assumed to be 0..1, and the value thus has to be within that range. Authors are encouraged to include a textual representation of the gauge's state in the element's contents, for users of user agents that do not support the meter p349 element. The following examples show three gauges that would all be three-quarters full: Storage space usage: 6 blocks used (out of 8 total) Voter turnout: 75% Tickets sold: 350 The following example is incorrect use of the element, because it doesn't give a range (and since the default maximum is 1, both of the gauges would end up looking maxed out):

    The grapefruit pie had a radius of 12cm and a height of 2cm.

    Instead, one would either not include the meter element, or use the meter element with a defined range to give the dimensions in context compared to other pies:

    The grapefruit pie had a radius of 12cm and a height of 2cm.

    Radius:
    12cm
    Height:
    2cm
    There is no explicit way to specify units in the meter p349 element, but the units may be specified in the title p84 attribute in free-form text. The example above could be extended to mention the units:
    Radius:
    12cm
    Height:
    2cm
    User agent requirements: User agents must parse the min p350 , max p350 , value p350 , low p350 , high p350 , and optimum p350 attributes using the rules for parsing floating point number values p36 . User agents must then use all these numbers to obtain values for six points on the gauge, as follows. (The order in which these are evaluated is important, as some of the values refer to earlier ones.) The minimum value If the min p350 attribute is specified and a value could be parsed out of it, then the minimum value is that value. Otherwise, the minimum value is zero. The maximum value If the max p350 attribute is specified and a value could be parsed out of it, the maximum value is that value. Otherwise, the maximum value is 1.0. If the maximum value would be less than the minimum value, then the maximum value is actually the same as the minimum value. The actual value If the value p350 attribute is specified and a value could be parsed out of it, then that value is the actual value. Otherwise, the actual value is zero. If the actual value would be less than the minimum value, then the actual value is actually the same as the minimum value. If, on the other hand, the actual value would be greater than the maximum value, then the actual value is the maximum value. The low boundary If the low p350 attribute is specified and a value could be parsed out of it, then the low boundary is that value. Otherwise, the low boundary is the same as the minimum value. If the low boundary is then less than the minimum value, then the low boundary is actually the same as the minimum value. Similarly, if the low boundary is greater than the maximum value, then it is actually the maximum value instead. The high boundary If the high p350 attribute is specified and a value could be parsed out of it, then the high boundary is that value. Otherwise, the high boundary is the same as the maximum value. If the high boundary is then less than the low boundary, then the high boundary is actually the same as the low boundary. Similarly, if the high boundary is greater than the maximum value, then it is actually the maximum value instead. The optimum point If the optimum p350 attribute is specified and a value could be parsed out of it, then the optimum point is that value. Otherwise, the optimum point is the midpoint between the minimum value and the maximum value. 351 If the optimum point is then less than the minimum value, then the optimum point is actually the same as the minimum value. Similarly, if the optimum point is greater than the maximum value, then it is actually the maximum value instead. All of which will result in the following inequalities all being true: • • • minimum value ≤ actual value ≤ maximum value minimum value ≤ low boundary ≤ high boundary ≤ maximum value minimum value ≤ optimum point ≤ maximum value UA requirements for regions of the gauge: If the optimum point is equal to the low boundary or the high boundary, or anywhere in between them, then the region between the low and high boundaries of the gauge must be treated as the optimum region, and the low and high parts, if any, must be treated as suboptimal. Otherwise, if the optimum point is less than the low boundary, then the region between the minimum value and the low boundary must be treated as the optimum region, the region between the low boundary and the high boundary must be treated as a suboptimal region, and the region between the high boundary and the maximum value must be treated as an even less good region. Finally, if the optimum point is higher than the high boundary, then the situation is reversed; the region between the high boundary and the maximum value must be treated as the optimum region, the region between the high boundary and the low boundary must be treated as a suboptimal region, and the remaining region between the low boundary and the minimum value must be treated as an even less good region. UA requirements for showing the gauge: When representing a meter p349 element to the user, the UA should indicate the relative position of the actual value to the minimum and maximum values, and the relationship between the actual value and the three regions of the gauge. The following markup:

    Suggested groups

    Hide suggested groups Might be rendered as follows: User agents may combine the value of the title p84 attribute and the other attributes to provide context-sensitive help or inline text detailing the actual values. 352 For example, the following snippet: ...might cause the user agent to display a gauge with a tooltip saying "Value: 23.2 out of 60." on one line and "seconds" on a second line. The form p353 attribute is used to explicitly associate the meter p349 element with its form owner p353 . The min, max, value, low, high, and optimum IDL attributes must reflect p57 the respective content attributes of the same name. When the relevant content attributes are absent, the IDL attributes must return zero. The labels p303 attribute provides a list of the element's label p301 s. The following example shows how a gauge could fall back to localized or pretty-printed text.

    Disk usage: 170 261 928 bytes used out of 233 257 824 bytes available

    4.10.18 Association of controls and forms A form-associated element p297 can have a relationship with a form p297 element, which is called the element's form owner. If a form-associated element p297 is not associated with a form p297 element, its form owner p353 is said to be null. A form-associated element p297 is, by default, associated with its nearest ancestor form p297 element (as described below), but may have a form attribute specified to override this. If a form-associated element p297 has a form p353 attribute specified, then its value must be the ID of a form p297 element in the element's owner Document p31 . When a form-associated element p297 is created, its form owner p353 must be initialized to null (no owner). When a form-associated element p297 is to be associated with a form, its form owner p353 must be set to that form. When a form-associated element p297 's ancestor chain changes, e.g. because it or one of its ancestors was inserted p27 or removed p27 from a Document p31 , then the user agent must reset the form owner p353 of that element. When a form-associated element p297 's form p353 attribute is added, removed, or has its value changed, then the user agent must reset the form owner p353 of that element. When a form-associated element p297 has a form p353 attribute and the ID of any of the elements in the Document p31 changes, then the user agent must reset the form owner p353 of that form-associated element p297 . When a form-associated element p297 has a form p353 attribute and an element with an ID is inserted into p27 or removed from p27 the Document p31 , then the user agent must reset the form owner p353 of that form-associated element p297 . When the user agent is to reset the form owner of a form-associated element p297 , it must run the following steps: 1. If the element's form owner p353 is not null, and the element's form p353 content attribute is not present, and the element's form owner p353 is its nearest form p297 element ancestor after the change to the ancestor chain, then do nothing, and abort these steps. 2. Let the element's form owner p353 be null. 3. If the element has a form p353 content attribute, then run these substeps: 1. If the first element in the Document p27 to have an ID that is case-sensitively p33 equal to the element's form p353 content attribute's value is a form p297 element, then associate p353 the formassociated element p297 with that form p297 element. 2. Abort the "reset the form owner" steps. 4. Otherwise, if the form-associated element p297 in question has an ancestor form p297 element, then associate p353 the form-associated element p297 with the nearest such ancestor form p297 element. 5. Otherwise, the element is left unassociated. In the following non-conforming snippet: ...
    353
    ... The form owner p353 of "d" would be the inner nested form "c", while the form owner p353 of "e" would be the outer form "a". This is because despite the association of "e" with "c" in the HTML parser p554 , when the innerHTML p102 algorithm moves the nodes from the temporary document to the "b" element, the nodes see their ancestor chain change, and thus all the "magic" associations done by the parser are reset to normal ancestor associations. This example is a non-conforming document, though, as it is a violation of the content models to nest form p297 elements. This box is non-normative. Implementation requirements are given below this box. element . form p354 Returns the element's form owner p353 . Returns null if there isn't one. Form-associated elements p297 have a form IDL attribute, which, on getting, must return the element's form owner p353 , or null if there isn't one. 4.10.19 Attributes common to form controls 4.10.19.1 Naming form controls The name content attribute gives the name of the form control, as used in form submission p360 and in the form p297 element's elements p299 object. If the attribute is specified, its value must not be the empty string. The name IDL attribute must reflect p57 the name p354 content attribute. 4.10.19.2 Enabling and disabling form controls The disabled content attribute is a boolean attribute p34 . A form control is disabled if its disabled p354 attribute is set, or if it is a descendant of a fieldset p300 element whose disabled p300 attribute is set and is not a descendant of that fieldset p300 element's first legend p301 element child, if any. A form control that is disabled p354 must prevent any click p31 events that are queued p490 on the user interaction task source p491 from being dispatched on the element. Constraint validation: If an element is disabled p354 , it is barred from constraint validation p356 . The disabled IDL attribute must reflect p57 the disabled p354 content attribute. 4.10.19.3 A form control's value Form controls have a value and a checkedness. (The latter is only used by input p303 elements.) These are used to describe how the user interacts with the control. 4.10.19.4 Autofocusing a form control The autofocus content attribute allows the user to indicate that a control is to be focused as soon as the page is loaded, allowing the user to just start typing without having to manually focus the main control. The autofocus p354 attribute is a boolean attribute p34 . There must not be more than one element in the document with the autofocus p354 attribute specified. Whenever an element with the autofocus p354 attribute specified is inserted into a document p27 whose browsing context p439 did not have the sandboxed automatic features browsing context flag p203 set when the Document p31 354 was created, the user agent should queue a task p490 that checks to see if the element is focusable p510 , and if so, runs the focusing steps p511 for that element. User agents may also change the scrolling position of the document, or perform some other action that brings the element to the user's attention. The task source p490 for this task is the DOM manipulation task source p491 . User agents may ignore this attribute if the user has indicated (for example, by starting to type in a form control) that he does not wish focus to be changed. Note: Focusing the control does not imply that the user agent must focus the browser window if it has lost focus. The autofocus IDL attribute must reflect p57 the content attribute of the same name. In the following snippet, the text control would be focused when the document was loaded. 4.10.19.5 Limiting user input length A form control maxlength attribute, controlled by a dirty value flag declares a limit on the number of characters a user can input. If an element has its form control maxlength attribute p355 specified, the attribute's value must be a valid nonnegative integer p35 . If the attribute is specified and applying the rules for parsing non-negative integers p35 to its value results in a number, then that number is the element's maximum allowed value length. If the attribute is omitted or parsing its value results in an error, then there is no maximum allowed value length p355 . Constraint validation: If an element has a maximum allowed value length p355 , and its dirty value flag is true, and the code-point length p34 of the element's value p354 is greater than the element's maximum allowed value length p355 , then the element is suffering from being too long p357 . User agents may prevent the user from causing the element's value p354 to be set to a value whose code-point length p34 is greater than the element's maximum allowed value length p355 . 4.10.19.6 Form submission Attributes for form submission can be specified both on form p297 elements and on submit buttons p297 (elements that represent buttons that submit forms, e.g. an input p303 element whose type p304 attribute is in the Submit Button p321 state). The attributes for form submission p355 that may be specified on form p297 elements are action p355 , enctype p356 , method p355 , novalidate p356 , and target p356 . The corresponding attributes for form submission p355 that may be specified on submit buttons p297 are formaction p355 , formenctype p356 , formmethod p355 , formnovalidate p356 , and formtarget p356 . When omitted, they default to the values given on the corresponding attributes on the form p297 element. The action and formaction content attributes, if specified, must have a value that is a valid URL p51 . The action of an element is the value of the element's formaction p355 attribute, if the element is a submit button p297 and has such an attribute, or the value of its form owner p353 's action p355 attribute, if it has one, or else the empty string. The method and formmethod content attributes are enumerated attributes p34 with the following keywords and states: • The keyword GET, mapping to the state GET, indicating the HTTP GET method. • The keyword POST, mapping to the state POST, indicating the HTTP POST method. • The keyword PUT, mapping to the state PUT, indicating the HTTP PUT method. • The keyword DELETE, mapping to the state DELETE, indicating the HTTP DELETE method. The missing value default for these attributes is the GET p355 state. The method of an element is one of those four states. If the element is a submit button p297 and has a formmethod p355 attribute, then the element's method p355 is that attribute's state; otherwise, it is the form owner p353 's method p355 attribute's state. 355 The enctype and formenctype content attributes are enumerated attributes p34 with the following keywords and states: • The "application/x-www-form-urlencoded" keyword and corresponding state. • The "multipart/form-data" keyword and corresponding state. • The "text/plain" keyword and corresponding state. The missing value default for these attributes is the application/x-www-form-urlencoded p356 state. The enctype of an element is one of those three states. If the element is a submit button p297 and has a formenctype p356 attribute, then the element's enctype p356 is that attribute's state; otherwise, it is the form owner p353 's enctype p356 attribute's state. The target and formtarget content attributes, if specified, must have values that are valid browsing context names or keywords p442 . The target of an element is the value of the element's formtarget p356 attribute, if the element is a submit button p297 and has such an attribute; or the value of its form owner p353 's target p356 attribute, if it has such an attribute; or, if one of the child nodes of the head element p76 is a base p108 element with a target p109 attribute, then the value of the target p109 attribute of the first such base p108 element; or, if there is no such element, the empty string. The novalidate and formnovalidate content attributes are boolean attributes p34 . If present, they indicate that the form is not to be validated during submission. The no-validate state of an element is true if the element is a submit button p297 and the element's formnovalidate p356 attribute is present, or if the element's form owner p353 's novalidate p356 attribute is present, and false otherwise. This attribute is useful to include "save" buttons on forms that have validation constraints, to allow users to save their progress even though they haven't fully entered the data in the form. The following example shows a simple form that has two required fields. There are three buttons: one to submit the form, which requires both fields to be filled in; one to save the form so that the user can come back and fill it in later; and one to cancel the form altogether.

    The action, method, enctype, and target IDL attributes must reflect p57 the respective content attributes of the same name. The noValidate IDL attribute must reflect the novalidate p356 content attribute. The formAction IDL attribute must reflect the formaction p355 content attribute. The formEnctype IDL attribute must reflect the formenctype p356 content attribute. The formMethod IDL attribute must reflect the formmethod p355 content attribute. The formNoValidate IDL attribute must reflect the formnovalidate p356 content attribute. The formTarget IDL attribute must reflect the formtarget p356 content attribute. 4.10.20 Constraints 4.10.20.1 Definitions A listed form-associated element p297 is a candidate for constraint validation except when a condition has barred the element from constraint validation. (For example, an element is barred from constraint validation p356 if it is an output p346 or fieldset p300 element.) An element can have a custom validity error message defined. Initially, an element must have its custom validity error message p356 set to the empty string. When its value is not the empty string, the element is suffering from a custom error p357 . It can be set using the setCustomValidity() p358 method. The user agent should use the custom validity error message p356 when alerting the user to the problem with the control. An element can be constrained in various ways. The following is the list of validity states that a form control can be in, making the control invalid for the purposes of constraint validation. (The definitions below are nonnormative; other parts of this specification define more precisely when each state applies or does not.) 356 Suffering from being missing When a control has no value p354 but has a required attribute (input p303 required p326 , textarea p341 required p343 ). Suffering from a type mismatch When a control that allows arbitrary user input has a value p354 that is not in the correct syntax (E-mail p309 , URL p308 ). Suffering from a pattern mismatch When a control has a value p354 that doesn't satisfy the pattern p328 attribute. Suffering from being too long When a control has a value p354 that is too long for the form control maxlength attribute p355 (input p303 maxlength p327 , textarea p341 maxlength p343 ). Suffering from an underflow When a control has a value p354 that is too low for the min p328 attribute. Suffering from an overflow When a control has a value p354 that is too high for the max p328 attribute. Suffering from a step mismatch When a control has a value p354 that doesn't fit the rules given by the step p329 attribute. Suffering from a custom error When a control's custom validity error message p356 (as set by the element's setCustomValidity() p358 method) is not the empty string. Note: An element can still suffer from these states even when the element is disabled p354 ; thus these states can be represented in the DOM even if validating the form during submission wouldn't indicate a problem to the user. An element satisfies its constraints if it is not suffering from any of the above validity states p356 . 4.10.20.2 Constraint validation When the user agent is required to statically validate the constraints of form p297 element form, it must run the following steps, which return either a positive result (all the controls in the form are valid) or a negative result (there are invalid controls) along with a (possibly empty) list of elements that are invalid and for which no script has claimed responsibility: 1. Let controls be a list of all the submittable elements p297 whose form owner p353 is form, in tree order p27 . 2. Let invalid controls be an initially empty list of elements. 3. For each element field in controls, in tree order p27 , run the following substeps: 1. If field is not a candidate for constraint validation p356 , then move on to the next element. 2. Otherwise, if field satisfies its constraints p357 , then move on to the next element. 3. Otherwise, add field to invalid controls. 4. If invalid controls is empty, then return a positive result and abort these steps. 5. Let unhandled invalid controls be an initially empty list of elements. 6. For each element field in invalid controls, if any, in tree order p27 , run the following substeps: 7. 1. Fire a simple event p496 named invalid that is cancelable at field. 2. If the event was not canceled, then add field to unhandled invalid controls. Return a negative result with the list of elements in the unhandled invalid controls list. If a user agent is to interactively validate the constraints of form p297 element form, then the user agent must run the following steps: 1. Statically validate the constraints p357 of form, and let unhandled invalid controls be the list of elements returned if the result was negative. 2. If the result was positive, then return that result and abort these steps. 357 3. Report the problems with the constraints of at least one of the elements given in unhandled invalid controls to the user. User agents may focus one of those elements in the process, by running the focusing steps p511 for that element, and may change the scrolling position of the document, or perform some other action that brings the element to the user's attention. User agents may report more than one constraint violation. User agents may coalesce related constraint violation reports if appropriate (e.g. if multiple radio buttons in a group p319 are marked as required, only one error need be reported). If one of the controls is not being rendered p638 (e.g. it has the hidden p508 attribute set) then user agents may report a script error. 4. Return a negative result. 4.10.20.3 The constraint validation API This box is non-normative. Implementation requirements are given below this box. element . willValidate p358 Returns true if the element will be validated when the form is submitted; false otherwise. element . setCustomValidity p358 (message) Sets a custom error, so that the element would fail to validate. The given message is the message to be shown to the user when reporting the problem to the user. If the argument is the empty string, clears the custom error. element . validity p359 . valueMissing p359 Returns true if the element has no value but is a required field; false otherwise. element . validity p359 . typeMismatch p359 Returns true if the element's value is not in the correct syntax; false otherwise. element . validity p359 . patternMismatch p359 Returns true if the element's value doesn't match the provided pattern; false otherwise. element . validity p359 . tooLong p359 Returns true if the element's value is longer than the provided maximum length; false otherwise. element . validity p359 . rangeUnderflow p359 Returns true if the element's value is lower than the provided minimum; false otherwise. element . validity p359 . rangeOverflow p359 Returns true if the element's value is higher than the provided maximum; false otherwise. element . validity p359 . stepMismatch p359 Returns true if the element's value doesn't fit the rules given by the step p329 attribute; false otherwise. element . validity p359 . customError p359 Returns true if the element has a custom error; false otherwise. element . validity p359 . valid p359 Returns true if the element's value has no validity problems; false otherwise. valid = element . checkValidity p359 () Returns true if the element's value has no validity problems; false otherwise. Fires an invalid event at the element in the latter case. element . validationMessage p359 Returns the error message that would be shown to the user if the element was to be checked for validity. The willValidate attribute must return true if an element is a candidate for constraint validation p356 , and false otherwise (i.e. false if any conditions are barring it from constraint validation p356 ). The setCustomValidity(message), when invoked, must set the custom validity error message p356 to the value of the given message argument. In the following example, a script checks the value of a form control each time it is edited, and whenever it is not a valid value, uses the setCustomValidity() p358 method to set an appropriate message. 358 The validity attribute must return a ValidityState p359 object that represents the validity states p356 of the element. This object is live p27 , and the same object must be returned each time the element's validity p359 attribute is retrieved. interface ValidityState { readonly attribute boolean readonly attribute boolean readonly attribute boolean readonly attribute boolean readonly attribute boolean readonly attribute boolean readonly attribute boolean readonly attribute boolean readonly attribute boolean }; valueMissing; typeMismatch; patternMismatch; tooLong; rangeUnderflow; rangeOverflow; stepMismatch; customError; valid; A ValidityState p359 object has the following attributes. On getting, they must return true if the corresponding condition given in the following list is true, and false otherwise. valueMissing The control is suffering from being missing p357 . typeMismatch The control is suffering from a type mismatch p357 . patternMismatch The control is suffering from a pattern mismatch p357 . tooLong The control is suffering from being too long p357 . rangeUnderflow The control is suffering from an underflow p357 . rangeOverflow The control is suffering from an overflow p357 . stepMismatch The control is suffering from a step mismatch p357 . customError The control is suffering from a custom error p357 . valid None of the other conditions are true. When the checkValidity() method is invoked, if the element is a candidate for constraint validation p356 and does not satisfy its constraints p357 , the user agent must fire a simple event p496 named invalid that is cancelable (but in this case has no default action) at the element and return false. Otherwise, it must only return true without doing anything else. The validationMessage attribute must return the empty string if the element is not a candidate for constraint validation p356 or if it is one but it satisfies its constraints p357 ; otherwise, it must return a suitably localized message that the user agent would show the user if this were the only form control with a validity constraint problem. If the user agent would not actually show a textual message in such a situation (e.g. it would show a graphical cue instead), then the attribute must return a suitably localized message that expresses (one or more of) the validity 359 constraint(s) that the control does not satisfy. If the element is a candidate for constraint validation p356 and is suffering from a custom error p357 , then the custom validity error message p356 should be present in the return value. 4.10.20.4 Security Servers should not rely on client-side validation. Client-side validation can be intentionally bypassed by hostile users, and unintentionally bypassed by users of older user agents or automated tools that do not implement these features. The constraint validation features are only intended to improve the user experience, not to provide any kind of security mechanism. 4.10.21 Form submission 4.10.21.1 Introduction This section is non-normative. When forms are submitted, the data in the form is converted into the form specified by the enctype p356 , and then sent to the destination specified by the action p355 using the given method p355 . For example, take the following form:
    If the user types in "cats" in the first field and "fur" in the second, and then hits the submit button, then the user agent will load /find.cgi?t=cats&q=fur. On the other hand, consider this form:
    Given the same user input, the result on submission is quite different: the user agent instead does an HTTP POST to the given URL, with as the entity body something like the following text: ------kYFrd4jNJEgCervE Content-Disposition: form-data; name="t" cats ------kYFrd4jNJEgCervE Content-Disposition: form-data; name="q" fur ------kYFrd4jNJEgCervE-- 4.10.21.2 Implicit submission User agents may establish a button p297 in each form as being the form's default button. This should be the first submit button p297 in tree order p27 whose form owner p353 is that form p297 element, but user agents may pick another button if another would be more appropriate for the platform. If the platform supports letting the user submit a form implicitly (for example, on some platforms hitting the "enter" key while a text field is focused implicitly submits the form), then doing so must cause the form's default button p360 's activation behavior p93 , if any, to be run. Note: Consequently, if the default button p360 is disabled p354 , the form is not submitted when such an implicit submission mechanism is used. (A button has no activation behavior p93 when disabled.) If the form has no submit button p297 , then the implicit submission mechanism must just submit p361 the form p297 element from the form p297 element itself. 360 4.10.21.3 Form submission algorithm When a form form is submitted from an element submitter (typically a button), optionally with a scripted-submit flag set, the user agent must run the following steps: 1. If form is in a Document p31 that has no associated browsing context p439 or whose browsing context p439 had its sandboxed forms browsing context flag p203 set when the Document p31 was created, then abort these steps without doing anything. 2. If form is already being submitted (i.e. the form was submitted p361 again while processing the events fired from the next two steps, probably from a script redundantly calling the submit() p299 method on form), then abort these steps. This doesn't affect the earlier instance of this algorithm. 3. If the scripted-submit flag is not set, and the submitter element's no-validate state p356 is false, then interactively validate the constraints p357 of form and examine the result: if the result is negative (the constraint validation concluded that there were invalid fields and probably informed the user of this) then abort these steps. 4. If the scripted-submit flag is not set, then fire a simple event p496 that is cancelable named submit, at form. If the event's default action is prevented (i.e. if the event is canceled) then abort these steps. Otherwise, continue (effectively the default action is to perform the submission). 5. Let controls be a list of all the submittable elements p297 whose form owner p353 is form, in tree order p27 . 6. Let the form data set be a list of name-value-type tuples, initially empty. 7. Constructing the form data set. For each element field in controls, in tree order p27 , run the following substeps: 1. If any of the following conditions are met, then skip these substeps for this element: • The field element has a datalist p338 element ancestor. • The field element is disabled p354 . • The field element is a button p297 but it is not submitter. • The field element is an input p303 element whose type p304 attribute is in the Checkbox p318 state and whose checkedness p354 is false. • The field element is an input p303 element whose type p304 attribute is in the Radio Button p319 state and whose checkedness p354 is false. • The field element is not an input p303 element whose type p304 attribute is in the Image Button p321 state, and either the field element does not have a name p354 attribute specified, or its name p354 attribute's value is the empty string. • The field element is an object p208 element that is not using a plugin p27 . Otherwise, process field as follows: 2. Let type be the value of the type IDL attribute of field. 3. If the field element is an input p303 element whose type p304 attribute is in the Image Button p321 state, then run these further nested substeps: 1. If the field element has an name p354 attribute specified and value is not the empty string, let name be that value followed by a single U+002E FULL STOP character (.). Otherwise, let name be the empty string. 2. Let namex be the string consisting of the concatenation of name and a single U+0078 LATIN SMALL LETTER X character (x). 3. Let namey be the string consisting of the concatenation of name and a single U+0079 LATIN SMALL LETTER Y character (y). 4. The field element is submitter, and before this algorithm was invoked the user indicated a coordinate p322 . Let x be the x-component of the coordinate selected by the user, and let y be the y-component of the coordinate selected by the user. 5. Append an entry in the form data set with the name namex, the value x, and the type type. 6. Append an entry in the form data set with the name namey and the value y, and the type type. 361 7. Skip the remaining substeps for this element: if there are any more elements in controls, return to the top of the constructing the form data set p361 step, otherwise, jump to the next step in the overall form submission algorithm. 4. Let name be the value of the field element's name p354 attribute. 5. If the field element is a select p334 element, then for each option p339 element in the select p334 element whose selectedness p340 is true, append an entry in the form data set with the name as the name, the value p340 of the option p339 element as the value, and type as the type. 6. Otherwise, if the field element is an input p303 element whose type p304 attribute is in the Checkbox p318 state or the Radio Button p319 state, then run these further nested substeps: 1. If the field element has a value p306 attribute specified, then let value be the value of that attribute; otherwise, let value be the string "on". 2. Append an entry in the form data set with name as the name, value as the value, and type as the type. 7. Otherwise, if the field element is an input p303 element whose type p304 attribute is in the File Upload p320 state, then for each file selected p320 in the input p303 element, append an entry in the form data set with the name as the name, the file (consisting of the name, the type, and the body) as the value, and type as the type. If there are no selected files p320 , then append an entry in the form data set with the name as the name, the empty string as the value, and application/octet-stream as the type. 8. Otherwise, if the field element is an object p208 element: try to obtain a form submission value from the plugin p27 , and if that is successful, append an entry in the form data set with name as the name, the returned form submission value as the value, and the string "object" as the type. 9. Otherwise, append an entry in the form data set with name as the name, the value p354 of the field element as the value, and type as the type. 8. Let action be the submitter element's action p355 . 9. If action is the empty string, let action be the document's address p71 . Note: This step is a willful violation p17 of RFC 3986, which would require base URL processing here. This violation is motivated by a desire for compatibility with legacy content. [RFC3986] p703 10. Resolve p51 the URL p51 action, relative to the submitter element. If this fails, abort these steps. Otherwise, let action be the resulting absolute URL p52 . 11. Let scheme be the p51 of the resulting absolute URL p52 . 12. Let enctype be the submitter element's enctype p356 . 13. Let method be the submitter element's method p355 . 14. Let target be the submitter element's target p356 . 15. Select the appropriate row in the table below based on the value of scheme as given by the first cell of each row. Then, select the appropriate cell on that row based on the value of method as given in the first cell of each column. Then, jump to the steps named in that cell and defined below the table. GET p355 POST p355 p363 PUT p355 p363 DELETE p355 p363 Delete action p363 http Mutate action https Mutate action p363 Submit as entity body p363 Submit as entity body p363 Delete action p363 ftp Get action p363 Get action p363 Get action p363 Get action p363 javascript Get action p363 p363 p363 Get action p363 data p363 mailto Get action Mail with headers Submit as entity body Get action p364 Post to data: p363 Mail as body p364 Submit as entity body Get action Put to data: p364 Mail with headers Get action p363 p364 Mail with headers p364 If scheme is not one of those listed in this table, then the behavior is not defined by this specification. User agents should, in the absence of another specification defining this, act in a manner analogous to that defined in this specification for similar schemes. The behaviors are as follows: 362 Mutate action Let query be the result of encoding the form data set using the application/x-www-formurlencoded encoding algorithm p365 , interpreted as a US-ASCII string. Let destination be a new URL p51 that is equal to the action except that its p51 component is replaced by query (adding a U+003F QUESTION MARK character (?) if appropriate). Let target browsing context be the form submission target browsing context p364 . Navigate p459 target browsing context to destination. If target browsing context was newly created for this purpose by the steps above, then it must be navigated with replacement enabled p466 . Submit as entity body Let entity body be the result of encoding the form data set using the appropriate form encoding algorithm p364 . Let target browsing context be the form submission target browsing context p364 . Let MIME type be determined as follows: If enctype is application/x-www-form-urlencoded p356 Let MIME type be "application/x-www-form-urlencoded". If enctype is multipart/form-data p356 Let MIME type be "multipart/form-data". If enctype is text/plain p356 Let MIME type be "text/plain". If method is anything but GET or POST, and the origin p449 of action is not the same origin p451 as that of the form p297 element's Document p31 , then abort these steps. Otherwise, navigate p459 target browsing context to action using the HTTP method given by method and with entity body as the entity body, of type MIME type. If target browsing context was newly created for this purpose by the steps above, then it must be navigated with replacement enabled p466 . Delete action Let target browsing context be the form submission target browsing context p364 . If the origin p449 of action is not the same origin p451 as that of the form p297 element's Document p31 , then abort these steps. Otherwise, navigate p459 target browsing context to action using the DELETE method. If target browsing context was newly created for this purpose by the steps above, then it must be navigated with replacement enabled p466 . Get action Let target browsing context be the form submission target browsing context p364 . Navigate p459 target browsing context to action. If target browsing context was newly created for this purpose by the steps above, then it must be navigated with replacement enabled p466 . Post to data: Let data be the result of encoding the form data set using the appropriate form encoding algorithm p364 . If action contains the string "%%%%" (four U+0025 PERCENT SIGN characters), then %-escape all bytes in data that, if interpreted as US-ASCII, do not match the unreserved production in the URI Generic Syntax, and then, treating the result as a US-ASCII string, further %-escape all the U+0025 PERCENT SIGN characters in the resulting string and replace the first occurrence of "%%%%" in action with the resulting double-escaped string. [RFC3986] p703 Otherwise, if action contains the string "%%" (two U+0025 PERCENT SIGN characters in a row, but not four), then %-escape all characters in data that, if interpreted as US-ASCII, do not match the unreserved production in the URI Generic Syntax, and then, treating the result as a US-ASCII string, replace the first occurrence of "%%" in action with the resulting escaped string. [RFC3986] p703 Let target browsing context be the form submission target browsing context p364 . Navigate p459 target browsing context to the potentially modified action. If target browsing context was newly created for this purpose by the steps above, then it must be navigated with replacement enabled p466 . 363 Put to data: Let data be the result of encoding the form data set using the appropriate form encoding algorithm p364 . Let MIME type be determined as follows: If enctype is application/x-www-form-urlencoded p356 Let MIME type be "application/x-www-form-urlencoded". If enctype is multipart/form-data p356 Let MIME type be "multipart/form-data". If enctype is text/plain p356 Let MIME type be "text/plain". Let destination be the result of concatenating the following: 1. 2. 3. 4. The string "data:". The value of MIME type. The string ";base64,". A base-64 encoded representation of data. [RFC2045] p702 Let target browsing context be the form submission target browsing context p364 . Navigate p459 target browsing context to destination. If target browsing context was newly created for this purpose by the steps above, then it must be navigated with replacement enabled p466 . Mail with headers Let headers be the resulting encoding the form data set using the application/x-www-formurlencoded encoding algorithm p365 , interpreted as a US-ASCII string. Replace occurrences of U+002B PLUS SIGN characters (+) in headers with the string "%20". Let destination consist of all the characters from the first character in action to the character immediately before the first U+003F QUESTION MARK character (?), if any, or the end of the string if there are none. Append a single U+003F QUESTION MARK character (?) to destination. Append headers to destination. Let target browsing context be the form submission target browsing context p364 . Navigate p459 target browsing context to destination. If target browsing context was newly created for this purpose by the steps above, then it must be navigated with replacement enabled p466 . Mail as body Let body be the resulting encoding the form data set using the appropriate form encoding algorithm p364 and then %-escaping all the bytes in the resulting byte string that, when interpreted as US-ASCII, do not match the unreserved production in the URI Generic Syntax. [RFC3986] p703 Let destination have the same value as action. If destination does not contain a U+003F QUESTION MARK character (?), append a single U+003F QUESTION MARK character (?) to destination. Otherwise, append a single U+0026 AMPERSAND character (&). Append the string "body=" to destination. Append body, interpreted as a US-ASCII string, to destination. Let target browsing context be the form submission target browsing context p364 . Navigate p459 target browsing context to destination. If target browsing context was newly created for this purpose by the steps above, then it must be navigated with replacement enabled p466 . The form submission target browsing context is obtained, when needed by the behaviors described above, as follows: If the user indicated a specific browsing context p439 to use when submitting the form, then that is the target browsing context. Otherwise, apply the rules for choosing a browsing context given a browsing context name p442 using target as the name and the browsing context p439 of form as the context in which the algorithm is executed; the resulting browsing context p439 is the target browsing context. The appropriate form encoding algorithm is determined as follows: If enctype is application/x-www-form-urlencoded p356 Use the application/x-www-form-urlencoded encoding algorithm p365 . 364 If enctype is multipart/form-data p356 Use the multipart/form-data encoding algorithm p366 . If enctype is text/plain p356 Use the text/plain encoding algorithm p366 . 4.10.21.4 URL-encoded form data The application/x-www-form-urlencoded encoding algorithm is as follows: 1. Let result be the empty string. 2. If the form p297 element has an accept-charset p298 attribute, then, taking into account the characters found in the form data set's names and values, and the character encodings supported by the user agent, select a character encoding from the list given in the form p297 's accept-charset p298 attribute that is an ASCII-compatible character encoding p28 . If none of the encodings are supported, then let the selected character encoding be UTF-8. Otherwise, if the document's character encoding p75 is an ASCII-compatible character encoding p28 , then that is the selected character encoding. Otherwise, let the selected character encoding be UTF-8. 3. Let charset be the preferred MIME name p28 of the selected character encoding. 4. For each entry in the form data set, perform these substeps: 1. If the entry's name is "_charset_" and its type is "hidden", replace its value with charset. 2. If the entry's type is "file", replace its value with the file's filename only. 3. For each character in the entry's name and value that cannot be expressed using the selected character encoding, replace the character by a string consisting of a U+0026 AMPERSAND character (&), a U+0023 NUMBER SIGN character (#), one or more characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9) representing the Unicode code point of the character in base ten, and finally a U+003B SEMICOLON character (;). 4. For each character in the entry's name and value, apply the appropriate subsubsteps from the following list: ↪ The character is a U+0020 SPACE character Replace the character with a single U+002B PLUS SIGN character (+). ↪ If the character isn't in the range U+0020, U+002A, U+002D, U+002E, U+0030 to U+0039, U+0041 to U+005A, U+005F, U+0061 to U+007A Replace the character with a string formed as follows: 1. Let s be an empty string. 2. For each byte b of the character when expressed in the selected character encoding in turn, run the appropriate subsubsubstep from the list below: ↪ If the byte is in the range 0x20, 0x2A, 0x2D, 0x2E, 0x30 to 0x39, 0x41 to 0x5A, 0x5F, 0x61 to 0x7A Append to s the Unicode character with the codepoint equal to the byte. ↪ Otherwise Append to the string a U+0025 PERCENT SIGN character (%) followed by two characters in the ranges U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9) and U+0041 LATIN CAPITAL LETTER A to U+0046 LATIN CAPITAL LETTER F representing the hexadecimal value of the byte (zero-padded if necessary). ↪ Otherwise Leave the character as is. 5. If the entry's name is "isindex", its type is "text", and this is the first entry in the form data set, then append the value to result and skip the rest of the substeps for this entry, moving on to the next entry, if any, or the next step in the overall algorithm otherwise. 6. If this is not the first entry, append a single U+0026 AMPERSAND character (&) to result. 7. Append the entry's name to result. 365 5. 8. Append a single U+003D EQUALS SIGN character (=) to result. 9. Append the entry's value to result. Encode result as US-ASCII and return the resulting byte stream. 4.10.21.5 Multipart form data The multipart/form-data encoding algorithm is to encode the form data set using the rules described by RFC2388, Returning Values from Forms: multipart/form-data, and return the resulting byte stream. [RFC2388] p703 Each entry in the form data set is a field, the name of the entry is the field name and the value of the entry is the field value, unless the entry's name is "_charset_" and its type is "hidden", in which case the field value is the character encoding used by the aforementioned algorithm to encode the value of the field. The order of parts must be the same as the order of fields in the form data set. Multiple entries with the same name must be treated as distinct fields. 4.10.21.6 Plain text form data The text/plain encoding algorithm is as follows: 1. Let result be the empty string. 2. If the form p297 element has an accept-charset p298 attribute, then, taking into account the characters found in the form data set's names and values, and the character encodings supported by the user agent, select a character encoding from the list given in the form p297 's accept-charset p298 attribute. If none of the encodings are supported, then let the selected character encoding be UTF-8. Otherwise, the selected character encoding is the document's character encoding p75 . 3. Let charset be the preferred MIME name p28 of the selected character encoding. 4. If the entry's name is "_charset_" and its type is "hidden", replace its value with charset. 5. If the entry's type is "file", replace its value with the file's filename only. 6. For each entry in the form data set, perform these substeps: 7. 1. Append the entry's name to result. 2. Append a single U+003D EQUALS SIGN character (=) to result. 3. Append the entry's value to result. 4. Append a U+000D CARRIAGE RETURN (CR) U+000A LINE FEED (LF) character pair to result. Encode result using the selected character encoding and return the resulting byte stream. 4.10.22 Resetting a form When a form form is reset, the user agent must fire a simple event p496 named reset, that is cancelable, at form, and then, if that event is not canceled, must invoke the reset algorithm p366 of each resettable elements p297 whose form owner p353 is form, and broadcast formchange events p366 from form. Each resettable element p297 defines its own reset algorithm. Changes made to form controls as part of these algorithms do not count as changes caused by the user (and thus, e.g., do not cause input events to fire). 4.10.23 Event dispatch When the user agent is to broadcast forminput events or broadcast formchange events from a form p297 element form, it must run the following steps: 366 1. Let controls be a list of all the resettable elements p297 whose form owner p353 is form. 2. If the user agent was to broadcast forminput events p366 , let event name be forminput. Otherwise the user agent was to broadcast formchange events p366 ; let event name be formchange. 3. For each element in controls, in tree order p27 , fire a simple event p496 named event name at the element. 4.11 Interactive elements 4.11.1 The details element Categories Flow content p91 . Sectioning root p144 . Interactive content p92 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: One summary p370 element followed by flow content p91 . Content attributes: Global attributes p82 open p367 DOM interface: interface HTMLDetailsElement : HTMLElement { attribute boolean open; }; The details p367 element represents p638 a disclosure widget from which the user can obtain additional information or controls. Note: The details p367 element is not appropriate for footnotes. Please see the section on footnotes p395 for details on how to mark up footnotes. The first summary p370 element child of the element, if any, represents p638 the summary or legend of the details. If there is no child summary p370 element, the user agent should provide its own legend (e.g. "Details"). The open content attribute is a boolean attribute p34 . If present, it indicates that the details are to be shown to the user. If the attribute is absent, the details are not to be shown. If the attribute is removed, then the details should be hidden. If the attribute is added, the details should be shown. The user agent should allow the user to request that the details be shown or hidden. To honor a request for the details to be shown, the user agent must set the open p367 attribute on the element to the value open. To honor a request for the details to be hidden, the user agent must remove the open p367 attribute from the element. The open attribute must reflect p57 the open p367 content attribute. The following example shows the details p367 element being used to hide technical details in a progress report.

    Copying "Really Achieving Your Childhood Dreams"

    Copying... 25%
    Transfer rate:
    452KB/s
    Local filename:
    /home/rpausch/raycd.m4v
    Remote filename:
    /var/www/lectures/raycd.m4v
    Duration:
    01:16:27
    Color profile:
    SD (6-1-6)
    Dimensions:
    320×240
    The following shows how a details p367 element can be used to hide some controls by default:
    Name & Extension:

    367 One could use this in conjuction with other details p367 in a list to allow the user to collapse a set of fields down to a small set of headings, with the ability to open each one. 368 369 In these examples, the summary really just summarises what the controls can change, and not the actual values, which is less than ideal. 4.11.2 The summary element Categories None. Contexts in which this element may be used: As the first child of a details p367 element. Content model: Phrasing content p91 . Content attributes: Global attributes p82 DOM interface: Uses HTMLElement p81 . The summary p370 element represents p638 a summary, caption, or legend for the rest of the contents of the summary p370 element's parent details p367 element, if any. 370 4.11.3 The command element Categories Metadata content p90 . Flow content p91 . Phrasing content p91 . Contexts in which this element may be used: Where metadata content p90 is expected. Where phrasing content p91 is expected. Content model: Empty. Content attributes: Global attributes p82 type p371 label p371 icon p371 disabled p371 checked p372 radiogroup p372 Also, the title p371 attribute has special semantics on this element. DOM interface: interface HTMLCommandElement : HTMLElement { attribute DOMString type; attribute DOMString label; attribute DOMString icon; attribute boolean disabled; attribute boolean checked; attribute DOMString radiogroup; }; The command p371 element represents a command that the user can invoke. The type attribute indicates the kind of command: either a normal command with an associated action, or a state or option that can be toggled, or a selection of one item from a list of items. The attribute is an enumerated attribute p34 with three keywords and states. The "command" keyword maps to the Command p371 state, the "checkbox" keyword maps to the Checkbox p371 state, and the "radio" keyword maps to the Radio p371 state. The missing value default is the Command p371 state. The Command state The element represents p638 a normal command with an associated action. The Checkbox state The element represents p638 a state or option that can be toggled. The Radio state The element represents p638 a selection of one item from a list of items. The label attribute gives the name of the command, as shown to the user. The label p371 attribute must be specified and must have a value that is not the empty string. The title attribute gives a hint describing the command, which might be shown to the user to help him. The icon attribute gives a picture that represents the command. If the attribute is specified, the attribute's value must contain a valid non-empty URL p51 . To obtain the absolute URL p52 of the icon when the attribute's value is not the empty string, the attribute's value must be resolved p51 relative to the element. When the attribute is absent, or its value is the empty string, or resolving p51 its value fails, there is no icon. The disabled attribute is a boolean attribute p34 that, if present, indicates that the command is not available in the current state. Note: The distinction between disabled p371 and hidden p508 is subtle. A command would be disabled if, in the same context, it could be enabled if only certain aspects of the situation were changed. A command would be marked as hidden if, in that situation, the command will never be enabled. For example, in the context menu for a water faucet, the command "open" 371 might be disabled if the faucet is already open, but the command "eat" would be marked hidden since the faucet could never be eaten. The checked attribute is a boolean attribute p34 that, if present, indicates that the command is selected. The attribute must be omitted unless the type p371 attribute is in either the Checkbox p371 state or the Radio p371 state. The radiogroup attribute gives the name of the group of commands that will be toggled when the command itself is toggled, for commands whose type p371 attribute has the value "radio". The scope of the name is the child list of the parent element. The attribute must be omitted unless the type p371 attribute is in the Radio p371 state. The type, label, icon, disabled, checked, and radiogroup IDL attributes must reflect p57 the respective content attributes of the same name. The element's activation behavior p93 depends on the value of the type p371 attribute of the element, as follows: p371 attribute is in the Checkbox p371 state ↪ If the type If the element has a checked p372 attribute, the UA must remove that attribute. Otherwise, the UA must add a checked p372 attribute, with the literal value checked. The UA must then fire a click event p496 at the element. p371 attribute is in the Radio p371 state ↪ If the type If the element has a parent, then the UA must walk the list of child nodes of that parent element, and for each node that is a command p371 element, if that element has a radiogroup p372 attribute whose value exactly matches the current element's (treating missing radiogroup p372 attributes as if they were the empty string), and has a checked p372 attribute, must remove that attribute. Then, the element's checked p372 attribute attribute must be set to the literal value checked and the user agent must fire a click event p496 at the element. ↪ Otherwise The element has no activation behavior p93 . Note: Firing a synthetic click p31 event at the element does not cause any of the actions described above to happen. Note: command p371 elements are not rendered unless they form part of a menu p372 . Here is an example of a toolbar with three buttons that let the user toggle between left, center, and right alignment. One could imagine such a toolbar as part of a text editor. The toolbar also has a separator followed by another button labeled "Publish", though that button is disabled.
    4.11.4 The menu element Categories Flow content p91 . If the element's type p373 attribute is in the toolbar p373 state: Interactive content p92 . Contexts in which this element may be used: Where flow content p91 is expected. Content model: Either: Zero or more li p154 elements. Or: Flow content p91 . Content attributes: Global attributes p82 type p373 372 label p373 DOM interface: interface HTMLMenuElement : HTMLElement { attribute DOMString type; attribute DOMString label; }; The menu p372 element represents a list of commands. The type attribute is an enumerated attribute p34 indicating the kind of menu being declared. The attribute has three states. The context keyword maps to the context menu state, in which the element is declaring a context menu. The toolbar keyword maps to the toolbar state, in which the element is declaring a toolbar. The attribute may also be omitted. The missing value default is the list state, which indicates that the element is merely a list of commands that is neither declaring a context menu nor defining a toolbar. If a menu p372 element's type p373 attribute is in the context menu p373 state, then the element represents p638 the commands of a context menu, and the user can only interact with the commands if that context menu is activated. If a menu p372 element's type p373 attribute is in the toolbar p373 state, then the element represents p638 a list of active commands that the user can immediately interact with. If a menu p372 element's type p373 attribute is in the list p373 state, then the element either represents p638 an unordered list of items (each represented by an li p154 element), each of which represents a command that the user can perform or activate, or, if the element has no li p154 element children, flow content p91 describing available commands. The label attribute gives the label of the menu. It is used by user agents to display nested menus in the UI. For example, a context menu containing another menu would use the nested menu's label p373 attribute for the submenu's menu label. The type and label IDL attributes must reflect p57 the respective content attributes of the same name. 4.11.4.1 Introduction This section is non-normative. The menu p372 element is used to define context menus and toolbars. For example, the following represents a toolbar with three menu buttons on it, each of which has a dropdown menu with a series of options:
  • Help
  • About
  • In a supporting user agent, this might look like this: 373 In a legacy user agent, the above would look like a bulleted list with three items, the first of which has four buttons, the second of which has three, and the third of which has two nested bullet points with two items consisting of links. The following implements a similar toolbar, with a single button whose values, when selected, redirect the user to Web sites.
    The behavior in supporting user agents is similar to the example above, but here the legacy behavior consists of a single select p334 element with a submit button. The submit button doesn't appear in the toolbar, because it is not a direct child of the menu p372 element or of its li p154 children. 4.11.4.2 Building menus and toolbars A menu (or toolbar) consists of a list of zero or more of the following components: • • • Commands p376 , which can be marked as default commands Separators Other menus (which allows the list to be nested) The list corresponding to a particular menu p372 element is built by iterating over its child nodes. For each child node in tree order p27 , the required behavior depends on what the node is, as follows: p376 ↪ An element that defines a command Append the command to the menu, respecting its facets p376 . p149 element ↪ An hr p339 element that has a value p340 attribute set to the empty string, and has a disabled p340 ↪ An option attribute, and whose textContent p31 consists of a string of one or more hyphens (U+002D HYPHENMINUS) Append a separator to the menu. p154 element ↪ An li p301 element ↪ A label Iterate over the children of the element. p372 element with no label p373 attribute ↪ A menu p334 element ↪ A select Append a separator to the menu, then iterate over the children of the menu p372 or select p334 element, then append another separator. p372 element with a label p373 attribute ↪ A menu p338 element with a label p373 attribute ↪ An optgroup Append a submenu to the menu, using the value of the element's label attribute as the label of the menu. The submenu must be constructed by taking the element and creating a new menu for it using the complete process described in this section. ↪ Any other node Ignore p27 the node. 374 Once all the nodes have been processed as described above, the user agent must the post-process the menu as follows: 1. Except for separators, any menu item with no label, or whose label is the empty string, must be removed. 2. Any sequence of two or more separators in a row must be collapsed to a single separator. 3. Any separator at the start or end of the menu must be removed. 4.11.4.3 Context menus The contextmenu attribute gives the element's context menu p375 . The value must be the ID of a menu p372 element in the DOM. If the node that would be obtained by the invoking the getElementById() p31 method using the attribute's value as the only argument is null or not a menu p372 element, then the element has no assigned context menu. Otherwise, the element's assigned context menu is the element so identified. When an element's context menu is requested (e.g. by the user right-clicking the element, or pressing a context menu key), the UA must fire a simple event p496 named contextmenu that bubbles and is cancelable at the element for which the menu was requested. Note: Typically, therefore, the firing of the contextmenu event will be the default action of a mouseup or keyup event. The exact sequence of events is UA-dependent, as it will vary based on platform conventions. The default action of the contextmenu event depends on whether the element or one of its ancestors has a context menu assigned (using the contextmenu p375 attribute) or not. If there is no context menu assigned, the default action must be for the user agent to show its default context menu, if it has one. If the element or one of its ancestors does have a context menu assigned, then the user agent must fire a simple event p496 named show at the menu p372 element of the context menu of the nearest ancestor (including the element itself) with one assigned. The default action of this event is that the user agent must show a context menu built p374 from the menu p372 element. The user agent may also provide access to its default context menu, if any, with the context menu shown. For example, it could merge the menu items from the two menus together, or provide the page's context menu as a submenu of the default menu. If the user dismisses the menu without making a selection, nothing in particular happens. If the user selects a menu item that represents a command p376 , then the UA must invoke that command's Action p376 . Context menus must not, while being shown, reflect changes in the DOM; they are constructed as the default action of the show event and must remain as constructed until dismissed. User agents may provide means for bypassing the context menu processing model, ensuring that the user can always access the UA's default context menus. For example, the user agent could handle right-clicks that have the Shift key depressed in such a way that it does not fire the contextmenu event and instead always shows the default context menu. The contextMenu attribute must reflect p57 the contextmenu p375 content attribute. Here is an example of a context menu for an input control:
    This adds to items to the control's context menu, one called "Pick random name", and one called "Prefill other fields based on name". They invoke scripts that are not shown in the example above. 375 4.11.4.4 Toolbars When a menu p372 element has a type p373 attribute in the toolbar p373 state, then the user agent must build p374 the menu for that menu p372 element, and use the result in the rendering. The user agent must reflect changes made to the menu p372 's DOM, by immediately rebuilding p374 the menu. 4.11.5 Commands A command is the abstraction behind menu items, buttons, and links. Commands are defined to have the following facets: Type The kind of command: "command", meaning it is a normal command; "radio", meaning that triggering the command will, amongst other things, set the Checked State p376 to true (and probably uncheck some other commands); or "checkbox", meaning that triggering the command will, amongst other things, toggle the value of the Checked State p376 . ID The name of the command, for referring to the command from the markup or from script. If a command has no ID, it is an anonymous command. Label The name of the command as seen by the user. Hint A helpful or descriptive string that can be shown to the user. Icon An absolute URL p52 identifying a graphical image that represents the action. A command might not have an Icon. Access Key A key combination selected by the user agent that triggers the command. A command might not have an Access Key. Hidden State Whether the command is hidden or not (basically, whether it should be shown in menus). Disabled State Whether the command is relevant and can be triggered or not. Checked State Whether the command is checked or not. Action The actual effect that triggering the command will have. This could be a scripted event handler, a URL p51 to which to navigate p459 , or a form submission. These facets are exposed on elements using the command API: This box is non-normative. Implementation requirements are given below this box. element . commandType p377 Exposes the Type p376 facet of the command. element . id p84 Exposes the ID p376 facet of the command. element . label p377 Exposes the Label p376 facet of the command. element . title p84 Exposes the Hint p376 facet of the command. element . icon p377 Exposes the Icon p376 facet of the command. 376 element . accessKeyLabel p513 Exposes the Access Key p376 facet of the command. element . hidden p508 Exposes the Hidden State p376 facet of the command. element . disabled p377 Exposes the Disabled State p376 facet of the command. element . checked p377 Exposes the Checked State p376 facet of the command. element . click p508 () Triggers the Action p376 of the command. The commandType attribute must return a string whose value is either "command", "radio", or "checkbox", depending on whether the Type p376 of the command defined by the element is "command", "radio", or "checkbox" respectively. If the element does not define a command, it must return null. The label attribute must return the command's Label p376 , or null if the element does not define a command or does not specify a Label p376 . This attribute will be shadowed by the label IDL attribute on various elements. The icon attribute must return the absolute URL p52 of the command's Icon p376 . If the element does not specify an icon, or if the element does not define a command, then the attribute must return null. This attribute will be shadowed by the icon p372 IDL attribute on command p371 elements. The disabled attribute must return true if the command's Disabled State p376 is that the command is disabled, and false if the command is not disabled. This attribute is not affected by the command's Hidden State p376 . If the element does not define a command, the attribute must return false. This attribute will be shadowed by the disabled IDL attribute on various elements. The checked attribute must return true if the command's Checked State p376 is that the command is checked, and false if it is that the command is not checked. If the element does not define a command, the attribute must return false. This attribute will be shadowed by the checked IDL attribute on input p303 and command p371 elements. Note: The ID p376 facet is exposed by the id p84 IDL attribute, the Hint p376 facet is exposed by the title p84 IDL attribute, the AccessKey p376 facet is exposed by the accessKeyLabel p513 IDL attribute, and the Hidden State p376 facet is exposed by the hidden p508 IDL attribute. This box is non-normative. Implementation requirements are given below this box. document . commands p377 Returns an HTMLCollection p59 of the elements in the Document p31 that define commands and have IDs. The commands attribute of the document's HTMLDocument p71 interface must return an HTMLCollection p59 rooted at the Document p31 node, whose filter matches only elements that define commands p376 and have IDs p376 . User agents may expose the commands p376 whose Hidden State p376 facet is false (visible), e.g. in the user agent's menu bar. User agents are encouraged to do this especially for commands that have Access Keys p376 , as a way to advertise those keys to the user. 4.11.5.1 Using the a element to define a command An a p160 element with an href p383 attribute defines a command p376 . The Type p376 of the command is "command". The ID p376 of the command is the value of the id p84 attribute of the element, if the attribute is present and not empty. Otherwise the command is an anonymous command p376 . The Label p376 of the command is the string given by the element's textContent p31 IDL attribute. 377 The Hint p376 of the command is the value of the title p84 attribute of the element. If the attribute is not present, the Hint p376 is the empty string. The Icon p376 of the command is the absolute URL p52 obtained from resolving p51 the value of the src p186 attribute of the first img p186 element descendant of the element, relative to that element, if there is such an element and resolving its attribute is successful. Otherwise, there is no Icon p376 for the command. The AccessKey p376 of the command is the element's assigned access key p512 , if any. The Hidden State p376 of the command is true (hidden) if the element has a hidden p508 attribute, and false otherwise. The Disabled State p376 facet of the command is always false. (The command is always enabled.) The Checked State p376 of the command is always false. (The command is never checked.) The Action p376 of the command is to fire a click event p496 at the element. 4.11.5.2 Using the button element to define a command A button p332 element always defines a command p376 . The Type p376 , ID p376 , Label p376 , Hint p376 , Icon p376 , Access Key p376 , Hidden State p376 , Checked State p376 , and Action p376 facets of the command are determined as for a elements p377 (see the previous section). The Disabled State p376 of the command mirrors the disabled p354 state of the button. 4.11.5.3 Using the input element to define a command An input p303 element whose type p304 attribute is in one of the Submit Button p321 , Reset Button p323 , Image Button p321 , Button p323 , Radio Button p319 , or Checkbox p318 states defines a command p376 . The Type p376 of the command is "radio" if the type p304 attribute is in the Radio Button p319 state, "checkbox" if the type p304 attribute is in the Checkbox p318 state, and "command" otherwise. The ID p376 of the command is the value of the id p84 attribute of the element, if the attribute is present and not empty. Otherwise the command is an anonymous command p376 . The Label p376 of the command depends on the Type of the command: If the Type p376 is "command", then it is the string given by the value p306 attribute, if any, and a UA-dependent, locale-dependent value that the UA uses to label the button itself if the attribute is absent. Otherwise, the Type p376 is "radio" or "checkbox". If the element is a labeled control p302 , the textContent p31 of the first label p301 element in tree order p27 whose labeled control p302 is the element in question is the Label p376 (in DOM terms, this is the string given by element.labels[0].textContent). Otherwise, the value of the value p306 attribute, if present, is the Label p376 . Otherwise, the Label p376 is the empty string. The Hint p376 of the command is the value of the title p84 attribute of the input p303 element. If the attribute is not present, the Hint p376 is the empty string. If the element's type p304 attribute is in the Image Button p321 state, and the element has a src p186 attribute, and that attribute's value can be successfully resolved p51 relative to the element, then the Icon p376 of the command is the absolute URL p52 obtained from resolving that attribute that way. Otherwise, there is no Icon p376 for the command. The AccessKey p376 of the command is the element's assigned access key p512 , if any. The Hidden State p376 of the command is true (hidden) if the element has a hidden p508 attribute, and false otherwise. The Disabled State p376 of the command mirrors the disabled p354 state of the control. The Checked State p376 of the command is true if the command is of Type p376 "radio" or "checkbox" and the element is checked p354 attribute, and false otherwise. The Action p376 of the command, if the element has a defined activation behavior p93 , is to run synthetic click activation steps p92 on the element. Otherwise, it is just to fire a click event p496 at the element. 378 4.11.5.4 Using the option element to define a command An option p339 element with an ancestor select p334 element and either no value p340 attribute or a value p340 attribute that is not the empty string defines a command p376 . The Type p376 of the command is "radio" if the option p339 's nearest ancestor select p334 element has no multiple p335 attribute, and "checkbox" if it does. The ID p376 of the command is the value of the id p84 attribute of the element, if the attribute is present and not empty. Otherwise the command is an anonymous command p376 . The Label p376 of the command is the value of the option p339 element's label p340 attribute, if there is one, or the value of the option p339 element's textContent p31 IDL attribute if there isn't. The Hint p376 of the command is the string given by the element's title p84 attribute, if any, and the empty string if the attribute is absent. There is no Icon p376 for the command. The AccessKey p376 of the command is the element's assigned access key p512 , if any. The Hidden State p376 of the command is true (hidden) if the element has a hidden p508 attribute, and false otherwise. The Disabled State p376 of the command is true (disabled) if the element is disabled p340 or if its nearest ancestor select p334 element is disabled p340 , and false otherwise. The Checked State p376 of the command is true (checked) if the element's selectedness p340 is true, and false otherwise. The Action p376 of the command depends on its Type p376 . If the command is of Type p376 "radio" then it must pick p335 the option p339 element. Otherwise, it must toggle p335 the option p339 element. 4.11.5.5 Using the command element to define a command A command p371 element defines a command p376 . The Type p376 of the command is "radio" if the command p371 's type p371 attribute is "radio", "checkbox" if the attribute's value is "checkbox", and "command" otherwise. The ID p376 of the command is the value of the id p84 attribute of the element, if the attribute is present and not empty. Otherwise the command is an anonymous command p376 . The Label p376 of the command is the value of the element's label p371 attribute, if there is one, or the empty string if it doesn't. The Hint p376 of the command is the string given by the element's title p371 attribute, if any, and the empty string if the attribute is absent. The Icon p376 for the command is the absolute URL p52 obtained from resolving p51 the value of the element's icon p371 attribute, relative to the element, if it has such an attribute and resolving it is successful. Otherwise, there is no Icon p376 for the command. The AccessKey p376 of the command is the element's assigned access key p512 , if any. The Hidden State p376 of the command is true (hidden) if the element has a hidden p508 attribute, and false otherwise. The Disabled State p376 of the command is true (disabled) if the element has a disabled p371 attribute, and false otherwise. The Checked State p376 of the command is true (checked) if the element has a checked p372 attribute, and false otherwise. The Action p376 of the command, if the element has a defined activation behavior p93 , is to run synthetic click activation steps p92 on the element. Otherwise, it is just to fire a click event p496 at the element. 4.11.5.6 Using the accesskey attribute on a label element to define a command A label p301 element that has an assigned access key p512 and a labeled control p302 and whose labeled control p302 defines a command p376 , itself defines a command p376 . The Type p376 of the command is "command". 379 The ID p376 of the command is the value of the id p84 attribute of the element, if the attribute is present and not empty. Otherwise the command is an anonymous command p376 . The Label p376 of the command is the string given by the element's textContent p31 IDL attribute. The Hint p376 of the command is the value of the title p84 attribute of the element. There is no Icon p376 for the command. The AccessKey p376 of the command is the element's assigned access key p512 . The Hidden State p376 , Disabled State p376 , and Action p376 facets of the command are the same as the respective facets of the element's labeled control p302 . The Checked State p376 of the command is always false. (The command is never checked.) 4.11.5.7 Using the accesskey attribute on a legend element to define a command A legend p301 element that has an assigned access key p512 and is a child of a fieldset p300 element that has a descendant that is not a descendant of the legend p301 element and is neither a label p301 element nor a legend p301 element but that defines a command p376 , itself defines a command p376 . The Type p376 of the command is "command". The ID p376 of the command is the value of the id p84 attribute of the element, if the attribute is present and not empty. Otherwise the command is an anonymous command p376 . The Label p376 of the command is the string given by the element's textContent p31 IDL attribute. The Hint p376 of the command is the value of the title p84 attribute of the element. There is no Icon p376 for the command. The AccessKey p376 of the command is the element's assigned access key p512 . The Hidden State p376 , Disabled State p376 , and Action p376 facets of the command are the same as the respective facets of the first element in tree order p27 that is a descendant of the parent of the legend p301 element that defines a command p376 but is not a descendant of the legend p301 element and is neither a label p301 nor a legend p301 element. The Checked State p376 of the command is always false. (The command is never checked.) 4.11.5.8 Using the accesskey attribute to define a command on other elements An element that has an assigned access key p512 defines a command p376 . If one of the other sections that define elements that define commands p376 define that this element defines a command p376 , then that section applies to this element, and this section does not. Otherwise, this section applies to that element. The Type p376 of the command is "command". The ID p376 of the command is the value of the id p84 attribute of the element, if the attribute is present and not empty. Otherwise the command is an anonymous command p376 . The Label p376 of the command depends on the element. If the element is a labeled control p302 , the textContent p31 of the first label p301 element in tree order p27 whose labeled control p302 is the element in question is the Label p376 (in DOM terms, this is the string given by element.labels[0].textContent). Otherwise, the Label p376 is the textContent p31 of the element itself. The Hint p376 of the command is the value of the title p84 attribute of the element. If the attribute is not present, the Hint p376 is the empty string. There is no Icon p376 for the command. The AccessKey p376 of the command is the element's assigned access key p512 . The Hidden State p376 of the command is true (hidden) if the element has a hidden p508 attribute, and false otherwise. The Disabled State p376 facet of the command is always false. (The command is always enabled.) The Checked State p376 of the command is always false. (The command is never checked.) 380 The Action p376 of the command is to run the following steps: 1. If the element is focusable p510 , run the focusing steps p511 for the element. 2. If the element has a defined activation behavior p93 , run synthetic click activation steps p92 on the element. 3. Otherwise, if the element does not have a defined activation behavior p93 , fire a click event p496 at the element. 4.11.6 The device element Categories Flow content p91 . Phrasing content p91 . Interactive content p92 . Contexts in which this element may be used: Where phrasing content p91 is expected. Content model: Empty. Content attributes: Global attributes p82 type p381 DOM interface: interface HTMLDeviceElement : HTMLElement { attribute DOMString type; readonly attribute any data; }; The device p381 element represents a device selector, to allow the user to give the page access to a device, for example a video camera. The type attribute allows the author to specify which kind of device the page would like access to. The attribute is an enumerated attribute p34 with the keywords given in the first column of the following table, and their corresponding states given in the cell in second column of the same row. ** ** RS232 is only included below to give an idea of where we could go with this. Should we instead just make this only useful for audiovisual streams? Unless there are compelling reasons, we probably should not be this generic. So far, the reasons aren't that compelling. Keyword ** ** State Device description Examples media Media Stream of audio and/or video data. A webcam. fs File system File system. A USB-connected media player. rs232 RS232 A serial port. RS232 device. processing model: 'change' event fires once user selects a new device; .data is set to new Stream, LocalFS, or RS232 object as appropriate.

    To start chatting, select a video camera:

    4.11.6.1 Stream API The Stream p381 interface is used to represent streams. interface Stream { readonly attribute DOMString URL; 381 StreamRecorder record(); }; The URL attribute must return a File URN representing the stream. [FILEAPI] p701 For audio and video streams, the stream must be in a format supported by the user agent for use in audio p216 and video p213 elements. ** This will be pinned down to a specific codec. When the record() method is invoked, the user agent must return a new StreamRecorder p382 object associated with the stream. interface StreamRecorder { File stop(); }; The stop() method must return a new File object representing the data that was streamed between the creation of the StreamRecorder p382 object and the invocation of the stop() p382 method. [FILEAPI] p701 For audio and video streams, the file must be in a format supported by the user agent for use in audio p216 and video p213 elements. ** This again will be pinned down to a specific codec. 4.11.6.2 Peer-to-peer connections ** ** This section will be moved to a more appropriate location in due course; it is here currently to keep it near the device p381 element to allow reviewers to look at it. [NoInterfaceObject] interface AbstractPeer { void sendText(in DOMString text); attribute Function ontext; // receiving void sendBitmap(in HTMLImageElement image); attribute Function onbitmap; // receiving void sendFile(in File file); attribute Function onfile; // receiving attribute Stream localStream; // video/audio to send readonly attribute Stream remoteStream; // video/audio from remote peer attribute Function onstreamchange; // when the remote peer changes whether the video is being sent or not attribute Function onconnect; attribute Function onerror; attribute Function ondisconnect; }; [Constructor(in DOMString serverConfiguration)] interface PeerToPeerServer : AbstractPeer { void getClientConfiguration(in PeerToPeerConfigurationCallback callback); void close(); // disconnects and stops listening }; [Constructor] interface PeerToPeerClient : AbstractPeer { void addConfiguration(in DOMString configuration); void close(); // disconnects }; [Callback=FunctionOnly, NoInterfaceObject] interface PeerToPeerConfigurationCallback { 382 void handleEvent(in PeerToPeerServer server, in DOMString configuration); }; ** ... ** This relies on some currently hypothetical other standard to define: • The format of server configuration strings. • The format of client configuration strings. • The protocols that servers and clients use to talk to third-party servers mentioned in the server configuration strings. • The protocols that servers and clients use to talk to each other. ** Server: var serverConfig = ...; // configuration string obtained from server // contains details such as the IP address of a server that can speak some // protocol to help the client determine its public IP address, route packets // if necessary, etc. var local = new PeerToPeerServer(serverConfig); local.getClientConfiguration(function (configuration) { if (configuration != '') { ...; // send configuration to other peer using out-of-band mechanism } else { // we've exhausted our options; wait for connection } }); Client: var local = new PeerToPeerClient(); function ... (configuration) { // called whenever we get configuration information out-of-band local.addConfiguration(configuration); } Both client and server: local.onconnect = function (event) { // we are connected! local.sendText('Hello'); local.localStream = ...; // send video local.onstreamchange = function (event) { // receive video // (videoElement is some