HTML5
Existing markup
| Structure | h1–h6, div |
|---|---|
| Media | img, object |
| Interaction | form, input, textarea, select, button |
State the problem
I want to publish documents and applications on the web without dependencies.
Solutions
HyperText Markup Language
eXtensible HyperText Markup Language
Web Hypertext Application Technology Working Group
- June 2004: Opera and Mozilla set up the mailing list
- HTML5 — Web Applications 1.0 & Web Forms 2.0
- October 2006: Reinventing HTML — Tim Berners-Lee
- May 2007: W3C HTML Working Group
- January 2008: HTML 5
Timeline
- ?: Last Call Working Draft
- 2012: Candidate Recommendation
- 2022: Proposed Recommendation
Design principles
HTML Design Principles…offer guidance for the design of HTML in the areas of compatibility, utility and interoperability.
- Priority of constituencies
…consider users over authors over implementors over specifiers over theoretical purity.
- Do not reinvent the wheel, pave the cowpaths
- Support existing content, degrade gracefully
Error handling
—Parsing HTML documentsThis specification defines the parsing rules for HTML documents, whether they are syntactically correct or not.
W3C Documents
-
HTML5
…special attention has been given to defining clear conformance criteria for user agents in an effort to improve interoperability.
-
HTML: The Markup Language
…describes the HTML markup language and provides details necessary for producers of HTML content to create documents that conform to the language.
-
HTML5 differences from HTML4
…describes the differences between HTML4 and HTML5 and provides some of the rationale for the changes.
Doctype
Character encoding
Simplification
<linktype="text/css"rel="stylesheet" href="file.css"><scripttype="text/javascript"src="file.js"></script>
Syntax
-
<li class="foo">Hello world</li> <img src="foo" alt="bar" /> -
<li class="foo">Hello world <img src="foo" alt="bar"> -
<LI CLASS="foo">Hello world</LI> <IMG SRC="foo" ALT="bar"> -
<li class=foo>Hello world</li> <img src=foo alt=bar>
Serialisation
-
HTML5
must be served using the
text/htmlMIME type. -
XHTML5
must be served using an XML MIME type, such as
application/xhtml+xmlorapplication/xml.
Removed
- Presentational elements:
<font>,<big>,<center>, etc. - Presentational attributes:
border,bgcolor, etc. <frame>,<frameset>,<noframes><acronym>revlongdesc
Updated
-
rellink types + RelExtensions -
<a>…may be wrapped around entire paragraphs, lists, tables, and so forth, even entire sections, so long as there is no interactive content within.
Redefined
-
<b>…a span of text to be stylistically offset from the normal prose without conveying any extra importance.
-
<i>…a span of text in an alternate voice or mood, or otherwise offset from the normal prose.
-
<hr>…a paragraph-level thematic break.
-
<small>…side comments such as small print …disclaimers, caveats, legal restrictions, or copyrights.
-
<cite>…the title of a work …must not be used to mark up people's names
Kinds of content
-
Document metadata
—
<title>,<meta>… -
Text-level semantics
—
<em>,<strong>… -
Grouping content
—
<p>,<li>,<div>… -
Embedded content
—
<img>,<embed>… -
Interactive elements
—
<input>,<button>… - Sections
New elements
-
Text-level semantics
—
<mark>,<time> -
Grouping content
—
<figure> -
Interactive elements
—
<details> -
Sections
—
<header>,<footer>,<hgroup>,<nav>,<article>,<section>,<aside>
header
…a group of introductory or navigational aids.
<header>
<h1>My awesome site</h1>
<p>Welcome to my site. It has lots of cool stuff:</p>
<ul>
<li>My lovely horse</li>
<li>My interesting rock collection</li>
<li>and more…</li>
</ul>
</header>
aside
…represents a section of a page that consists of content that is tangentially related to the content around it, and which could be considered separate from that content.
<aside>
<h1>Brighton</h1>
<p>Brighton is a town on the south coast of England.</p>
<p>It is built on the site of Brighthelmston.</p>
</aside>
hgroup
…used to group a set of h1–h6 elements when the heading has multiple levels, such as subheadings, alternative titles, or taglines.
<hgroup>
<h1>DOM Scripting</h1>
<h2>Web Design with JavaScript and The Document Object Model</h2>
</hgroup>
footer
…typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like.
<footer>
<p>Copyright 2009 <address>jeremy@adactio.com</address></p>
</footer>
figure
…some flow content, optionally with a caption, that is self-contained and is typically referenced as a single unit from the main flow of the document.
<figure>
<img src="horse.jpg" alt="a horse in a field">
<figcaption>My lovely horse</figcaption>
</figure>
nav
…a section of a page that links to other pages or to parts within the page: a section with navigation links.
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>
time
…a way to encode modern dates and times in a machine-readable way.
<time datetime="2010-09-02T16:30:00">September 2nd, 4:30pm</time>
<time datetime="2010-09-02">September 2nd</time>
section
…a thematic grouping of content, typically with a heading.
<section>
<header>
<h1>DOM Scripting</h1>
</header>
<h2>JavaScript</h2>
<p>JavaScript is a programming language.</p>
<h2>The DOM</h2>
<p>The DOM is an API.</p>
<footer>Written by Jeremy Keith</footer>
</section>
article
…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.
<article>
<header>
<h1>DOM Scripting</h1>
</header>
<h2>JavaScript</h2>
<p>JavaScript is a programming language.</p>
<h2>The DOM</h2>
<p>The DOM is an API.</p>
<footer>Written by Jeremy Keith</footer>
</article>
details
…a disclosure widget from which the user can obtain additional information or controls.
<details>
<summary>Log in</summary>
<form method="post" action="login">
<label for="username">Username</label>
<input type="text" name="username" id="username">
<label for="password">Password</label>
<input type="password" name="password" id="password">
</form>
</details>
mark
…a run of text in one document marked or highlighted for reference purposes, due to its relevance in another context.
<h1>Search results for 'unicorn'</h1>
<ol>
<li>Riding the UX <mark>unicorn</mark> across the rainbow of the web.</li>
</ol>
Sectioning content
Sectioning content is content that defines the scope of headings and footers.
articleasidenavsection
Each sectioning content element potentially has a heading and an outline.
Implicit sections
| Markup | Outline |
|---|---|
|
Foo
Lorem ipsum foolor
Bar
Lorem ipsum barlor
Baz
Lorem ipsum bazlor
Qux
Lorem ipsum quxlor
foobar
|
Explicit sections
| Markup | Outline |
|---|---|
|
Foo
Lorem ipsum foolor
Bar
Lorem ipsum barlor
Baz
Lorem ipsum bazlor
Qux
Lorem ipsum quxlor
foobar
|
Masking
For the purposes of document summaries, outlines, and the like, the text of
hgroupelements is defined to be the text of the highest rankedh1–h6element descendant of thehgroupelement.
| Markup | Outline |
|---|---|
|
Sectioning roots
These elements can have their own outlines, but the sections and headings inside these elements do not contribute to the outlines of their ancestors.
Sectioning roots
| Markup | Outline |
|---|---|
|
Foo Bar Qux |
New elements
New and old elements
ARIA roles
Styles
article, aside, details,
figure, footer, header,
hgroup, nav, section {
display: block;
}
header[role="banner"] { }
nav[role="navigation"] { }
footer[role="contentinfo"] { }
Internet Explorer
document.createElement('article'); document.createElement('aside'); document.createElement('details'); …<!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"> </script> <![endif]-->
Distribution
<h1>My blog homepage</h1>
<article>
<h1>Blog post title</h1>
<p>I ate a cheese sandwich.</p>
<footer>
Published <time pubdate datetime="2010-04-22">two days ago</time>.
</footer>
</article>
Styles
<style>
h1 { color: green; }
</style>
<h1>What colour am I?</h1>
<section>
<style>
h1 { color: red; }
</style>
<h1>What colour am I?</h1>
</section>
Scoped styles
<style>
h1 { color: green; }
</style>
<h1>What colour am I?</h1>
<section>
<style scoped>
h1 { color: red; }
</style>
<h1>What colour am I?</h1>
</section>
Widgets
<article>
<h1>Weather in Brighton</h1>
<p>It's sunny.</p>
<footer>
Updated: <time pubdate datetime="2010-06-05T16:05">4:05pm</time>.
</footer>
<style scoped>
h1 { color: red; }
</style>
</article>
Input types
Testing for support
function inputSupportsType(test) { var input = document.createElement('input'); input.setAttribute('type',test); if (input.type == 'text') { return false; } else { return true; }if (!inputSupportsType('range')) { // JavaScript fallback goes here. }
Attributes
-
<input list="foo"><datalist id="foo">example -
<input placeholder="text">example -
<input autofocus> -
<input required> -
<input multiple> -
<input autocomplete="off"> -
<input pattern="[0-9]{3}" title="a three digit number"> - JavaScript constraint validation API
Testing for support
function elementSupportsAttribute(element,attribute) { var test = document.createElement(element); if (attribute in test) { return true; } else { return false; }if (!elementSupportsAttribute('input','placeholder')) { // JavaScript fallback goes here. }
Example
Survey
Options
- Doctype
- ARIA
roles - Some
inputtypes - Structural
classnames - Structural elements with JavaScript for IE
Resources
Blogs
Get involved
WHATWG
- Spec: whatwg.org/html5
- Mailing lists: whatwg.org/mailing-list
- IRC channel: irc://irc.freenode.org/whatwg
W3C
- Spec: dev.w3.org/html5/spec
- Mailing list: lists.w3.org/Archives/Public/public-html
- Issue tracker: www.w3.org/html/wg/tracker