Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
HTML5
CHAPTER 1
INTRODUCTION
The web is constantly evolving. New and innovative websites are being created every
day, pushing the boundaries of HTML in every direction. HTML 4 has been around
for nearly a decade now, and publishers seeking new techniques to provide enhanced
functionality are being held back by the constraints of the language and browsers.To
give authors more flexibility and interoperability, and enable more interactive and
exciting websites and applications, HTML 5 introduces and enhances a wide range of
features including form controls, APIs, multimedia, structure, and semantics.
Work on HTML 5, which commenced in 2004, is currently being carried out in a joint
effort between the W3C HTML WG and the WHATWG. Many key players are
participating in the W3C effort including representatives from the four major browser
vendors: Apple, Mozilla, Opera, and Microsoft; and a range of other organisations
and individuals with many diverse interests and expertise.
Basically, it’s about extending HTML/XHTML with new more semantically rich
elements, deprecating attributes, introducing new attributes and altering how some
element and attributes are allowed to be used. Hand in hand with that is the possibility
to use attributes for WAI-ARIA to make a web page more accessible, such as with
landmark roles.It also introduces a number of APIs for making it easier to create web
applications:
Other things that initially was in the specification, but broken out into separate
specifications are:
CHAPTER 2
HTML5 HISTORY
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 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.
CHAPTER 3
<!DOCTYPE html>
<html>
<head>
<title>Sample page</title>
</head>
<body>
<h1>Sample page</h1>
</body>
</html>
HTML documents consist of a tree of elements and text. Each element is denoted in
the source by a start tag , such as "<body>", and an end tag , such as "</body>". Tags
have to be nested such that elements are all completely within each other, without
overlapping:
Elements can have attributes, which control how the elements work. In the example
below, there is a hyperlink, formed using the aelement and its href attribute:
<a href="demo.html">simple</a>
Attributes are placed inside the start tag, and consist of a name and a value , separated
by an "=" character. The attribute value can remain unquoted 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 would be turned into the following DOM tree:
The root element of this tree is the html element, which is the element always found at
the root of HTML documents. It contains two elements, head and body , 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 and line breaks
("⏎") that all end up as text nodes in the DOM. The head element contains a title
element, which itself contains a text node with the text "Sample page".Similarly, the
body element contains an h1 element, a p 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 element or using event handler content attributes .
For example, here is a form with a script that sets the value of the form's output
element to say "Hello World":
<form name="main">
<script>
</script>
</form>
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 element in the
tree above) can have its "href " attribute changed in several ways:
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.
CHATER 4
The HTML5 specification includes a series of new semantic elements that is used to
give some meaning to the various sections or parts of a Web page, such as a header,
footer, navigation, and so on. In previous versions of HTML, you would typically use
<div> elements to create these parts, using ID or class attributes to differentiate them
from each other. The problem with this is that this has no semantic meaning, as there
are no strict rules defined that specify what class names or IDs are to be used, making
it extremely difficult for software to determine what the particular area is doing.
HTML5 should help alleviate these issues, making it easier for Web browsers to parse
the semantic structure of a document.The main semantic elements that HTML5
introduces are:
<header>
This element is used to define a header for some part of a Web page, be it the entire
page, an <article> element, or a <section> element.
<footer>
Like the <header> element, this new element defines a footer for some part of a page.
A footer does not have to be included at the end of a page, article, or section, but it
typically does.
<nav>
This is a container for the primary navigation links on a Web page. This element is
not intended for use with all groups of links and should be used for major navigation
blocks only. If you have a <footer> element that contains navigation links, you do not
need to wrap these links in a <nav> element, since the <footer> element will suffice
on its own.
<article>
The <article> element is used to define an independent item on the page that can be
distributed on its own, such as a news item, blog post, or comment.
<section>
<aside>
This new element can be used to mark up a sidebar or some other content that is
considered somewhat separate to the content around it. An example of this might be
advertising blocks.
<hgroup>
In some cases, a page, article, or section may require more than one heading,such as
where you have a title and a subtitle. This tutorial, for example, has the title "Create
modern Web sites using HTML5 and CSS3" and the subtitle"Implementing the
canvas and video elements in HTML5." You could wrapthese in an <hgroup>
element, using an <h1> element for the main title and an <h2> element for the
subtitle.
The <canvas> element was originally developed by Apple® for use in Mac OS X
Dashboard widgets and in Safari, but was later adopted by Mozilla® and Opera® in
their Web browsers. The element has been standardized and included in the HTML5
specification,
along with a series of 2D drawing APIs that can be used to create shapes, text,
transitions, and animations inside the element.Many believe that the <canvas>
element is one of the most important aspects of HTML5 as it facilitates the production
of graphs, interactive games, paint applications, and other graphics on the fly without
requiring external plug-ins such as Adobe Flash. The <canvas> element itself is quite
basic, defining the width, height, and unique ID for the object. The developer must
then use a series of JavaScript APIs to actually draw objects on the canvas, typically
when the Web page has finished rendering. These APIs allow the developer to draw
shapes and lines; apply color, opacity, and gradients; create text; transform canvas
objects; and perform animation. The
APIs also allow the <canvas> to be interactive and respond to user input such as
mouse events and key events, facilitating the production of games and Web
applications onthe canvas.
In recent years, the popularity of video sharing sites such as YouTube and content
delivery platforms like
Hulu has seen a huge explosion in the use of the Web for multimedia streaming.
Unfortunately, the Web was not built with such content in mind, and as a result, the
provision of video and audio has by and large been facilitated by the Flash Video
(.flv) file format and the Adobe Flash platform.HTML5, however, includes support
for two new elements, <audio> and <video>,which allow Web developers to include
multimedia content without relying on the user to have additional browser plug-ins
installed.In addition, a set of standard JavaScript APIs has been provided to allow
developers to create their own playback controls, should they wish to do so. There are
many decisions to be made about HTML5 <video> and <audio> in the near future,
and it will be interesting to see what codecs and formats are facilitated in the final
recommendation.
reasonably confident that they will still be there at a later date. In addition, the
information is accessible at any point (even after the page has rendered) and is not
loaded automatically with each HTTP request. The specification includes same-origin
restrictions, which prevent Web sites from reading or changing data stored by other
Web sites.Most browsers store Web pages in local cache, allowing them to be viewed
even if the user is offline. This works fine for static pages, but it is not available for
dynamic content that is typically database-driven, such as Gmail, Facebook, or
Twitter.HTML5 provides support for offline applications, where the browser
downloads all the files necessary to use the application offline, and when the user uses
the application offline, the browser can allow any changes made in the process to be
uploaded to the server when they reconnect to the Internet.
If you have created Web applications before, you are more than likely familiar with
HTML's set of form controls, some of which are implemented using the
<input>element. In HTML 4, the following input types were supported:
• button
• checkbox
• file
• hidden
• image
• password
• reset
• radio
• submit
• text
In addition, there are some other elements that are used in forms such as <select>and
<textarea>. These form controls provide plenty of function for basic form fields such
as name, phone number, and address—like you might find on a contact form.But, the
Web as a platform has grown far beyond the stage where HTML forms are used to
submit contact forms—now they are used to submit application data for server-side
processing. As a result, Web application developers find themselves continually in
• color
• date
• datetime
• datetime-local
• month
• number
• range
• search
• tel
• time
• url
• week
In addition to these new input types, HTML5 also supports two major new features
for form fields. The first of these is autofocus, which tells a browser to automatically
give focus to a particular form field when the page has rendered. The second
enhancement is the placeholder attribute,which allows the developer to define the text
that will appear in a textbox-based control when its contents are empty. A The
placeholder attribute allows the developer to specify text that will show when the
value of the control is empty and the control does not have focus.
HTML5 includes so many new features; This section provides a brief overview of
some of the other enhancements in the specification.
Web worker
This allows JavaScript code to be set to run in a background process facilitating the
development of multi-threaded applications. The chief benefit that Web workers offer
developers is that intensive calculations can be processed in the background without
adversely affecting the speed of the user interface.
Geolocation
HTML5 includes a geolocation API that allows a Web application to determine your
current geographical location, assuming the device you are targeting provides features
for finding such information (for example, GPS on acellphone). If you do not have a
device that supports this feature (such as an iPhone or an Android 2.0-based
smartphone), you can use Firefox and download a plug-in that allows you to set your
location manually.
Another interesting feature is the inclusion of a drag and drop API. Up until now,
implementation of drag and drop without plug-ins was dependent on
Cross-document messaging
This allows documents in different windows (and iframes, for that matter) to send and
receive messages to one another. This feature could prove very useful for the
development of widgets and applications that are hosted on servers other than the
primary Web page's server (similar to Facebook applications).
And more other new features introduced by HTML5 include MIME types and
protocol handler registration, so Web applications can be registered as the default
application for a particular file type or protocol; browser history management,which
until now needed to be implemented manually or using an external JavaScript
framework; and a host of other new elements and attributes that make Web
developers' lives easier.
CHAPTER 5
HTML 5 introduces a whole set of new elements that make it much easier to structure
pages. Most HTML 4 pages include a variety of common structures, such as headers,
footers and columns and today, it is fairly common to mark them up using div
elements, giving each a descriptive id or class.
The use of div elements is largely because current versions of HTML 4 lack the
necessary semantics for describing these parts more specifically. HTML 5 addresses
this issue by introducing new elements for representing each of these different
sections.
The div elements can be replaced with the new elements: header, nav, section, article,
aside, and footer.
The markup for that document could look like the following:
<body>
<header>...</header>
<nav>...</nav>
<article>
<section>
...
</section>
</article>
<aside>...</aside>
<footer>...</footer>
</body>
There are several advantages to using these elements. When used in conjunction with
the heading elements (h1 to h6), all of these provide a way to mark up nested sections
with heading levels, beyond the six levels possible with previous versions of HTML.
The specification includes a detailed algorithm for generating an outline that takes the
structure of these elements into account and remains backwards compatible with
previous versions. This can be used by both authoring tools and browsers to generate
tables of contents to assist users with navigating the document.
For example, the following markup structure marked up with nested section and h1
elements:
<section>
<h1>Level 1</h1>
<section>
<h1>Level 2</h1>
<section>
<h1>Level 3</h1>
</section>
</section>
</section>
Note that for better compatibility with current browsers, it is also possible to make use
of the other heading elements (h2 to h6) appropriately in place of the h1 elements.
By identifying the purpose of sections in the page using specific sectioning elements,
assistive technology can help the user to more easily navigate the page. For example,
they can easily skip over the navigation section or quickly jump from one article to
the next without the need for authors to provide skip links. Authors also benefit
because replacing many of the divs in the document with one of several distinct
elements can help make the source code clearer and easier to author.
The header element represents the header of a section. Headers may contain more
than just the section’s heading—for example it would be reasonable for the header to
include sub headings, version history information or bylines.
<header>
<h1>A Preview of HTML 5</h1>
<p class="byline">By Lachlan Hunt</p>
</header>
<header>
<h1>Example Blog</h1>
<h2>Insert tag line here.</h2>
</header>
The footer element represents the footer for the section it applies to. A footer
typically contains information about its section such as who wrote it, links to related
documents, copyright data, and the like.
The nav element represents a section of navigation links. It is suitable for either site
navigation or a table of contents.
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/products">Products</a></li>
<li><a href="/services">Services</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
The aside element is for content that is tangentially related to the content around it,
and is typically useful for marking up sidebars.
<aside>
<h1>Archives</h1>
<ul>
<li><a href="/2007/09/">September 2007</a></li>
<li><a href="/2007/08/">August 2007</a></li>
<li><a href="/2007/07/">July 2007</a></li>
</ul>
</aside>
<section>
<h1>Chapter 1: The Period</h1>
<p>It was the best of times, it was the worst of times,
it was the age of wisdom, it was the age of foolishness,
it was the epoch of belief, it was the epoch of incredulity,
it was the season of Light, it was the season of Darkness,
...</p>
</section>
<article id="comment-2">
<header>
<h4><a href="#comment-2" rel="bookmark">Comment #2</a>
by <a href="http://example.com/">Jack O'Niell</a></h4>
<p><time datetime="2007-08-29T13:58Z">August 29th, 2007 at
13:58</time>
</header>
<p>That's another great article!</p>
</article>
CHAPTER 6
The <video> element: inherent difficulties
Now we will add a video to the index.html page along with a set of browser-supplied
playback controls.
Adding a video to the page
<section>
<header>
<h1>This is a video section</h1>
</header>
<p>
<video src="http://www.double.co.nz/video_test/transformers480.ogg"
controls autoplay>
<div class="no-html5-video">
<p>This video will work in Mozilla Firefox or Google
Chrome only.</p>
</div>
</video>
</p>
</section>
we first create a new section where the video will be shown on the page. This has a
header followed by the video itself. The controls attribute tells the browser to display
the browser's standard controls for video playback. And the autoplay attribute, well,
tells the browser to start playing the video automatically. Between the opening and
closing <video> tags we have created a <div> element with the class no-html5-video,
which will display a message to users who try to view the video in a browser that does
not support the <video> element or does not support the Theora video codec.
Now try opening it in a browser like Internet Explorer or Opera. You should see an
error like the one shown below in Figure 4. Note that if you try to view it in Safari it
may show the browser video player, but it will not play the video.
CHAPTER 7
Web form enhancements
One of the more underrated aspects of HTML5 is the introduction of several new
form controls that will make developers' lives much easier when creating forms-based
Web applications. At present, support for these new controls in terms of browser
widgets and functionality is fairly sparse, but they degrade gracefully as regular text
boxes so you can safely use them in your code now, and when browser support
improves, the features will automatically enable.
The first form element does not have any type attribute, and as a result it will default
to a text control. You'll notice that this has the placeholder text "Enter your name" and
is set to autofocus. Supporting browsers will automatically switch focus to this
element when the page has been rendered. The next element is of type "email" and
again contains a placeholder text value. The only browser that recognizes this type of
input element as anything special is Opera, which displays a mail icon in the field to
signify that it's an email field. The next field of interest is the datetime field with the
label "Callback on:". In supporting browsers, this will display a date and time picker.
In Opera, this displays as two controls, a textbox with a datepicker and a spinner for
the time.
CHAPTER8
Let’s get down to some actual code and see what an HTML5-coded web page could
look like. This is the complete source code of a html5 demo web page:
01.<!DOCTYPE html>
02.<html>
03.<head>
04. <meta charset="utf-8">
05. <title>HTML5 example with new elements and WAI-ARIA landmark
roles</title>
06. <link rel="stylesheet" href="css/base.css" type="text/css"
media="screen">
07. <!--[if lte IE 8]>
08. <script src="js/html5.js"></script>
09. <![endif]-->
10.</head>
11.
12.<body id="index-page">
13.
14. <div id="container">
15. <header role="banner">
16. <h1>HTML5 example with new elements and WAI-ARIA
landmark roles</h1>
17. <p>This page has valid simple HTML5 markup
complemented with WAI-ARIA landmark roles for accessibility</p>
18. </header>
19.
20. <nav id="demo-top-nav">
21. <ul>
22. <li><a href="http://W3C.com/html5">HTML5 demos and
samples' start page</a></li>
23. <li><a href="http://W3C.com/specification">html5
specification document</a></li>
24. <li><a href="http://w3c.com/javascript/">JavaScript
compatibility tests</a></li>
25. </ul>
26. </nav>
27.
28. <div id="demo-main" role="main">
29. <section id="demo-main-content">
30. <header>
31. <hgroup>
32. <h2>A title</h2>
33. <h3>Subtitle to the above title</h3>
34. </hgroup>
35. </header>
36.
37. <article>
38. <p>Some content, created <time datetime="2010-
10-14">October 14th 2010</time></p>
39. </article>
40. <article>
41. <p>Some more content - i guess you get the
drift by now</p>
42. </article>
43.
44. <article>
45. <header>
46. <h2>The HTML code for this page</h2>
47. </header>
48.
49. </article>
50. </section>
51.
52. <aside id="demo-aside-content" role="complementary">
53. This is just a demo page to see HTML5 markup and
WAI-ARIA landmark roles in action in a simple context
54. </aside>
55. </div>
56.
57. <footer id="page-footer" role="contentinfo">
58. </footer>
59. </div>
60.
61.</body>
62.</html>
As you can see, it looks more or less than every other HTML web page you have ever
seen, but with just a few new HTML elements being used and the role attribute with
landmark roles for WAI-ARIA to make it more accessible.
CHAPTER 9
Pros
Major players using it
To begin with, a lot of major players have already started implementing it.
Google.com already have the HTML5, the new hyped Google Wave is revolving a lot
around HTML5 and related and there is also a YouTube HTML5 demo page.
Strict rendering
The HTML5 doctype will trigger the strictest rendering in all web browsers. No
Almost Standards Mode, no quirks; strict all the way, which is the way we want, and
the way it should be.
Progressive enhancement
You can start today just by changing the doctype. Then gradually move onto
exchanging some structure elements, sprinkle it with some WAI-ARIA etc and before
you know it, you have a fantastic HTML5 page!
Validation available
Now even the W3C Validator supports HTML5. Just use the Firefox Web
Developer Extension to validate your HTML against it. The HTML Validator
extension unfortunately doesn’t support it yet, but I know there are at least plans to
include this – if you have any ides or input, please help him out.
SEO
It probably doesn’t matter much right now, but in the future, I think that web sites
that are marked up in a much more rich fashion with new HTML5 elements to give
them the multitude they need, will benefit a lot from this.
Cons
Internet Explorer
It probably doesn’t come as a shock to you, but Internet Explorer, all current versions
(yes, including IE8 as well) has a little issue: it won’t apply any CSS to an unknown
element (e.g. nav, section etc).
However it was found out that with an HTML5 Shiv, sort of an electrical shock for IE
to start rendering things at least a little bit more properly, you can address that
problem.
The gist of it is that you need to call document.createElement with the name of each
new HTML5 element you use in the page. You don’t need to use it to append or place
those element, just call it to make IE aware of them. Remy Sharp has written a little
HTML5 enabling script for Internet Explorer, version 6 to 8 which works in all
possible cases.
People eager for HTML5 has argued that we will need script dependency for IE to
render styling for those elements, otherwise it will render unstyled, but with the
content still fully accessible. While I agree in theory, I think it is, at times, an
unnecessary requirement for using HTML5.
Another option is the content negotiation approach, where we on the server exchange
the new elements for old ones just for Internet Explorer. It’s simple: just have a
regular expression to replace all block elements (header, footer, section etc) with div
elements, and the inline ones (time, mark etc) with span elements.
CHAPTER 10
CHAPTER 11
REFERENCES
2 http://www.w3.org/TR/2010/WD-html5-20100624/
CHAPTER 12
APPENDIX