Optimizing Cancer Screening With MCED Technologies: From Science to Practical...i3 Health
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...i3 Health
Ad
Html5 Programmers Reference 1st Edition Jonathan Reid
1. Html5 Programmers Reference 1st Edition Jonathan
Reid download
https://ebookbell.com/product/html5-programmers-reference-1st-
edition-jonathan-reid-36111868
Explore and download more ebooks at ebookbell.com
2. Here are some recommended products that we believe you will be
interested in. You can click the link to download.
Html5 Programmers Reference 1st Edition Jonathan Reid
https://ebookbell.com/product/html5-programmers-reference-1st-edition-
jonathan-reid-5226664
Web Standards Programmers Reference Html Css Javascript Perl Python
And Php Steven M Schafer
https://ebookbell.com/product/web-standards-programmers-reference-
html-css-javascript-perl-python-and-php-steven-m-schafer-1366700
Html5 Quick Markup Reference 1st Edition Wallace Jackson
https://ebookbell.com/product/html5-quick-markup-reference-1st-
edition-wallace-jackson-50195512
Html5 Games Development By Example Beginners Guide Makzan
https://ebookbell.com/product/html5-games-development-by-example-
beginners-guide-makzan-50195522
3. Html5 For Masterminds How To Take Advantage Of Html5 To Create
Responsive Websites And Revolutionary Applications Jd Gauchat
https://ebookbell.com/product/html5-for-masterminds-how-to-take-
advantage-of-html5-to-create-responsive-websites-and-revolutionary-
applications-jd-gauchat-50195532
Html5 For Web Designers 1st Jeremy Keith
https://ebookbell.com/product/html5-for-web-designers-1st-jeremy-
keith-2003876
Html5 Canvas Cookbook Eric Rowell
https://ebookbell.com/product/html5-canvas-cookbook-eric-
rowell-2070242
Html5 Canvas 1st Edition Steve Fulton Jeff Fulton
https://ebookbell.com/product/html5-canvas-1st-edition-steve-fulton-
jeff-fulton-2227062
Html5 Step By Step Step By Step Microsoft 1st Edition Faithe Wempen
https://ebookbell.com/product/html5-step-by-step-step-by-step-
microsoft-1st-edition-faithe-wempen-2245616
6. For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
7. v
Contents at a Glance
About the Author�����������������������������������������������������������������������������������������������������xv
About the Technical Reviewer�������������������������������������������������������������������������������xvii
Acknowledgments��������������������������������������������������������������������������������������������������xix
Introduction������������������������������������������������������������������������������������������������������������xxi
■
■Part I: HTML5 in Depth������������������������������������������������������������������������ 1
■
■Chapter 1: Welcome to HTML5������������������������������������������������������������������������������� 3
■
■Chapter 2: HTML5 Elements�������������������������������������������������������������������������������� 13
■
■Chapter 3: HTML5 APIs���������������������������������������������������������������������������������������� 55
■
■Chapter 4: Canvas��������������������������������������������������������������������������������������������� 105
■
■Chapter 5: Related Standards���������������������������������������������������������������������������� 149
■
■Chapter 6: Practical HTML5������������������������������������������������������������������������������� 185
■
■Part II: HTML5 Reference���������������������������������������������������������������� 239
■
■Chapter 7: HTML5 Element Reference��������������������������������������������������������������� 241
■
■Chapter 8: HTML5 API Reference����������������������������������������������������������������������� 285
■
■Chapter 9: Canvas Reference���������������������������������������������������������������������������� 309
■
■Appendix A: JavaScript Tips and Techniques���������������������������������������������������� 347
Index��������������������������������������������������������������������������������������������������������������������� 361
8. xxi
Introduction
The World Wide Web has existed for almost 25 years now. It started as a simple proposal by Tim Berners-Lee
and Robert Cailliau as a way for the scientists at CERN to publish papers easily, but it rapidly grew into a
platform that captured the imagination of the world.
The Web may have started out as a simple document-publishing platform, but it quickly became
clear that it was destined to become much more than that. As people demanded more interactivity and
richer experiences, the limits of the original HTML standards quickly became obvious. The advent of other
technologies like Cascading Style Sheets and JavaScript helped, but developers were still spending extensive
resources on building the experiences that people wanted.
HTML5 is meant to help solve some of these problems. The fifth incarnation of the HTML standard,
HTML5, is designed to be both feature rich and easier to work with. Prior versions of HTML focused on how
best to standardize document markup, which was a great way to bring standards to the chaos of the early
Web. HTML5, however, is focused on providing a platform for building rich interactions. Much of HTML5
was also specifically designed with mobile technologies in mind, while older versions of HTML were not.
What This Book Covers
This book is designed to be your go-to reference for HTML5 features. It is divided into two sections.
Part I, “HTML5 in Depth,” has chapters that provide detailed examinations of the HTML5 features,
including multiple examples and the current level of support at press time.
• Chapter 1, “Welcome to HTML5,” is a history lesson, explaining how the World Wide
Web and its technologies evolved, and how HTML5 came to be. This will hopefully
help you understand why HTML5 is so much different from previous HTML
standards, and will give you better insight in how HTML5 is structured.
• Chapter 2, “HTML5 Elements,” covers the new semantic tags in HTML5. As with
predecessor standards, HTML5 includes a new set of tags for marking up the content
in your documents. This is where you’ll find out how to use the new audio and video
tags, as well as a host of other HTML5 features.
• Chapter 3, “HTML5 APIs,” dives into the JavaScript APIs that are specified in the
HTML5 standard. You’ll learn about new ways for your HTML5 applications to
communicate and save data.
• Chapter 4, “Canvas,” covers one of the most innovative features of HTML5: the
canvas element. Here you’ll learn how to use this element to draw, modify images,
and create animations.
9. xxii
■ Introduction
• Chapter 5, “Related Standards,” covers several JavaScript APIs that are related to
HTML5 (and frequently used with HTML5) but are not actually a part of the HTML5
standard. These APIs also tend to have a strong mobile focus.
• Chapter 6, “Practical HTML5,” covers actually working with HTML5 in production
projects. It covers detecting features and applying shims, and includes a complete
HTML5 mobile game designed and built from the ground up.
Part II, “HTML5 Reference,” contains reference chapters for all of the HTML5 features covered in
Part 1. Each chapter is designed to provide an at-a-glance reference for each feature and includes a brief
description of the feature, how it is used (including both syntax and examples), and where to find its
standards.
• Chapter 7 is the reference chapter for HTML5 elements.
• Chapter 8 is the reference chapter for the HTML5 JavaScript APIs.
• Chapter 9 is the reference chapter for the canvas element.
What You Need to Know
Though there are lots of detailed examples throughout the book, it is written as a reference and not as a
tutorial. I’m assuming you have an intermediate understanding of how browsers work as well as how to
work with JavaScript, and at least a basic understanding of CSS and the network protocols involved in HTTP.
You should be comfortable creating and editing web pages and writing your own CSS and JavaScript.
Running the Code Samples
There are extensive code samples throughout the book. You can download the samples from www.apress.com,
or you can type them in by hand. Many of the examples can be run by simply loading the file into a web
browser using the browser’s File menu.
Some examples, though, must be run from an actual server, either due to security limitations or
because you will want to view them on a mobile device. To build and test all the examples in the book, I’ve
used Aptana Studio, available for free at http://www.aptana.com. Aptana Studio comes with an internal
debugging server that you can use to run any of these examples. If you prefer a stand-alone solution, I’ve
had very good luck with XAMPP, a stand-alone installation of the Apache web server, along with optional
components like MySQL, PHP, and Perl. And of course both MacOS and Windows come with their own web
server solutions that you can activate and use, as do most standard Linux distributions.
Finally, be sure to check out the “Comment Annotations” section in Appendix A, “JavaScript Tips and
Techniques,” for an explanation of the format of the examples and how to read the annotations.
11. 3
Chapter 1
Welcome to HTML5
In this chapter, I’m going to dive into the history of HTML and how HTML5 came to be. I’ll talk about the
evolution of HTML from a simple proposal all the way to its current version, including reviews of related
technologies. I’ll also cover what HTML5 is, its scope, how it differs from previous versions, and how it fits in
with other technologies.
What Is HTML5?
Hypertext Markup Language, or HTML, has been with us since 1989. Versions of HTML prior to 5 only defined
markup tags for content: lists, paragraphs, headers, tables, and so on. HTML5, though, defines much more.
It has new content tags (such as audio and video) but it also defines complex interactions like dragging
and dropping, new network interfaces like server events, and even has new asynchronous functionality like
web workers. HTML specifications prior to HTML5 also defined the tags in SGML (more on that in a bit), but
the HTML5 specification is careful only to define tags in terms of annotated content and expected behavior.
And because HTML5 is a big part of a new set of advanced web technologies, many times you’ll see articles
on the Web or in popular media that mistakenly include technologies in HTML5 that have nothing to do
with HTML.
So what exactly is HTML5? Why does HTML5 define so much more than tags? How did HTML5
come about? Why is the HTML5 standard such a big departure from previous standards, both in terms of
definition and scope? To answer these questions, I’ll start with a quick review of how HTML came to be in
the first place.
A Brief History of HTML
HTML’s humble beginnings go all the way back to 1989. At that time the most common ways of sharing
information online was via e-mail, Usenet newsgroups, and public FTP sites. E-mail and newsgroups made
it easy for people to communicate directly with one another, and FTP sites provided a way for people to
provide access to sets of files. The main issue is that all of these forms of sharing information required
different software, and a certain level of skill to be able to actually navigate the Internet—though at that time
the Internet was considerably smaller than it is today.
Tim Berners-Lee proposed a better solution in 1989. At the time he was working at the European
Organization for Nuclear Research (known better by its French acronym CERN, for Conseil Européen pour
la Recherche Nucléaire), and he was keenly aware of the need for a better way to share information online.
In particular, Berners-Lee needed to solve the problem of sharing technical documents online. CERN
produced huge amounts of technical documentation, ranging from nuclear physics papers intended for
publication to internal policy documents, and they needed a solution that would work for all of these
different use cases.
12. Chapter 1 ■ Welcome to HTML5
4
Berners-Lee found himself trying to solve two problems at once:
• He needed a solution that provided a way of visually formatting the information that
CERN scientists were producing. This information could take the form of documents
such as published papers as well as data observed during experiments.
• He needed a solution that was capable of handling cross-references and embedding
graphics and other media. Many of the documents and at CERN included diagrams
and graphics and referenced one another, or other internal data sources, or even
external documents and data sources.
Fortunately, Berners-Lee already had some experience with solving these problems. Back in 1980 when
he was a contractor at CERN he had built a prototype system called ENQUIRE that provided some of the
functionality the organization needed, but failed to scale well. It did, however, employ a very important key
concept: hypertext.
Enter Hypertext
Hypertext is text with references to other information that the user can activate to gain immediate access to
that information. This includes information contained within the same document as well as information
in external documents or other data sources. These links are referred to as hyperlinks. In the case of most
modern computers, hypertext is displayed on the screen and hyperlinks are activated by clicking them with
a mouse or (in the case of touchscreens) tapping them with a finger. The term hypermedia is an extension
of the concept of hypertext to include not only hyperlinks but graphics, audio, video, and other sources of
information.
The concept of hypermedia has been around for quite some time. In 1945 American engineer and
inventor Vannevar Bush wrote an essay titled “As We May Think” for the Atlantic Monthly. As part of the
essay Bush proposed a “memory extender” or “memex,” a device that people can use to store all of their
personal information sources: books, records, albums, and so on. The memex would provide a person with
access to all of their information through the use of a set of bookmarks, and could be expanded as needed.
■
■ Tip You can read “As We May Think” on the Atlantic’s web site at www.theatlantic.com/magazine/
archive/1945/07/as-we-may-think/303881/.
In 1960 Ted Nelson founded Project Xanadu in an attempt to build a word processing system capable of
storing multiple versions of many documents that would allow the user to move through those documents
in a nonsequential fashion. He referred to these nonsequential paths as “zippered lists” and posited that by
using these zippered lists, new documents could be formed from pieces of other documents in a process
he called “transclusion.” In 1963 Nelson coined the terms hypertext and hypermedia, which were first
published in his paper “Complex Information Processing: A File Structure for the Complex, the Changing
and the Indeterminate” (available at http://dl.acm.org/citation.cfm?id=806036). At that time Nelson
used hypertext to refer to editable text rather than a text-based cross-reference, so the term has had some
semantic drift since Nelson first coined it.
■
■ Tip Project Xanadu is alive and well today at www.xanadu.com/, and even has a demonstration of a
“xanadoc” that is created on demand via transclusion.
13. Chapter 1 ■ Welcome to HTML5
5
In 1962 American engineer and inventor Douglas Englebart began work on his “oNLine System” or “NLS.”
The NLS was the first system that included most of the modern computer features available today: a
pointing device, windows, separate programs for presenting different kinds of data, information organized
by relevance, hypermedia links, and so forth. Englebart demonstrated the NLS at the Fall Joint Computer
Conference in San Francisco in December 1968. This demonstration was groundbreaking not only because it
was the first to show all of these modern features in use at once, but also because it used state-of-the-art video
conferencing technology to show the user interface for NLS as Englebart used it. Because the demonstration
was so groundbreaking in scope, it is often referred to as “The Mother of All Demos.”
■
■ Tip The demonstration can be seen on Stanford University’s web site at http://web.stanford.edu/dept/
SUL/library/extra4/sloan/MouseSite/1968Demo.html.
Berners-Lee had built ENQUIRE on the concept of hypertext (Figure 1-1). Within ENQUIRE a given
document was represented by a single page of information called a “card,” which was essentially a list of
hyperlinks defining what the document included, how it was used, a description, and who the authors were.
The links could easily be followed by activating them, allowing the user to explore the entire network of
documents.
Figure 1-1. A Screenshot of ENQUIRE
14. Chapter 1 ■ Welcome to HTML5
6
In this respect, ENQUIRE was similar to an online version of a library’s card catalog system, and
unfortunately required a significant amount of effort to keep updated.
ENQUIRE also didn’t address the requirement for visually formatting documents. However, CERN
already made use of a possible solution in the form of a document markup language.
Enter Markup Languages
Document markup languages are programming languages that provide a way to annotate (or “mark up” as an
editor marks up a document under review) a document in such a way that the annotations are syntactically
distinct from the main content document. Markup languages exist in three broad categories based on the
goal of the annotations:
• Presentational markup languages are used to describe how a document should be
presented to the user. Most modern word processors use presentational markup
in the form of binary codes embedded in the document. Presentational markup is
typically designed for a specific program or display method and thus not meant to be
human readable.
• Procedural markup languages provide annotations that specify how the contents of
the document should be processed, often in the context of layout and typesetting
for printing. One of the most common examples of a procedural markup language is
PostScript.
• Descriptive markup languages are used to annotate the document with descriptions
of its content. Descriptive markup does not give any indication of how the contents
should be processed or displayed; that is left up to the processing agent.
Document markup languages have existed for decades. The first widely known document markup
language was presented by computer scientist William Tunnicliffe in 1967, but IBM researcher Charles
Goldfarb is typically called the “father” of modern markup languages because of his invention of the IBM
Generalized Markup Language (GML) in 1969. Goldfarb was responsible for pushing IBM to include GML
in its document management solutions. GML would eventually evolve into Standard Generalized Markup
Language (SGML, which became an ISO standard (ISO 8879:1986 Information processing—Text and office
systems -- Standard Generalized Markup Language) in 1986 with Goldfarb as the chair of the committee.
SGML isn’t a language you use directly; instead it is a “meta-language”—a language that is used to
define other languages. In this case, SGML is used to define markup languages that can then be used to
describe documents. Specifically, SGML requires that markup languages describe a document’s structure
and content attributes (vs. describing how to process the document), and that the markup languages
be rigorously defined so that processing and viewing software can be built that follows the same rules.
Languages defined by SGML are referred to as “SGML applications” (not to be confused with applications
that run on computers and perform tasks). Common SGML applications include XML (the eXtensible
Markup Language) and DocBook (a markup language designed for technical documentation).
CERN had been using an SGML application called SGMLguid) for marking up its documents, and
Berners-Lee recognized that a combination of SGMLguid with hypertext could be the solution he needed for
CERN’s document management problems.
15. Chapter 1 ■ Welcome to HTML5
7
Hypertext Markup Language Is Born
In late 1989, Berners-Lee proposed a pilot project that would employ hypertext and a simple markup
language as its basis. Berners-Lee envisioned that hyperlinks would be the key feature that tied all of the
disparate documents together:
HyperText is a way to link and access information of various kinds as a web of nodes in
which the user can browse at will. Potentially, HyperText provides a single user-interface
to many large classes of stored information such as reports, notes, data-bases, computer
documentation and on-line systems help.
from “WorldWideWeb: Proposal for a HyperText Project,” 12 November 1990
(www.w3.org/Proposal.html)
This proposal outlined a simple client/server network protocol for the new “web” of documents and
how they would function together to transfer information from the server to the viewing client. Berners-
Lee dubbed the new protocol “the Hypertext Transfer Protocol” or HTTP. The project was approved, and
Berners-Lee and his team began working on what would eventually become the World Wide Web.
After creating both client and server software for the new document system, Berners-Lee published
the first document that defined a basic set of tags that could be used to mark up documents that were to be
included in the new online document web. This document, titled “HTML Tags,” defined 18 tags that could be
used to mark up the contents of a document in such a way that the new web clients would be able to parse
and display them. Almost all of the tags came from SGMLguid except one: the anchor tag. The anchor tag
was the implementation of the hypertext linking feature that was so important to the new system.
■
■ Tip You can read the original “HTML Tags” document in the W3C’s historical archive at
www.w3.org/History/19921103-hypertext/hypertext/WWW/MarkUp/Tags.html.
This first document was a simple list of tags with a description of how to use them to describe the
content of a document. Later the tags were formalized as an SGML application in 1993 with the publication of
“Hypertext Markup Language (HTML)”(www.w3.org/MarkUp/draft-ietf-iiir-html-01.txt) as a working
draft submitted to the Internet Engineering Task Force (IETF). This draft expired and was followed by a
competing draft titled “HTML+ (Hypertext Markup Format)” later that same year, authored by Dave Raggett.
OPEN AND COLLABORATIVE
Tim Berners-Lee worked to keep the HTML definition process open and collaborative, leveraging
the knowledge and experience of many participants. These early collaborations paved the way not
only for the creation of the entire web technology ecosystem that would be designed through public
collaboration, but also for the creation of the core groups that would maintain the projects.
16. Chapter 1 ■ Welcome to HTML5
8
The Browser Wars
While working on the definition of HTML, Tim Berners-Lee was also working on the first software that
could make use of the new web of documents. In 1991 Berners-Lee released the first web browser,
“WorldWideWeb,” for the NeXTStep platform. There was significant interest from other programmers in
developing their own web browsers, so in 1993 Berners-Lee released a portable C library called libwww to the
public domain so that anyone could work on building web browsers. (The library was available prior to that
as part of the larger WorldWideWeb software application.)
By this point there were several experimental web browser projects on multiple platforms. Some of
these were simple text-based browsers that could be used from any terminal, such as the Lynx browser.
Others were graphical applications for use in the graphic desktops of the time.
One of the most popular of the graphical applications was Mosaic, developed at the National Center for
Supercomputing Applications (NCSA) at the University of Illinois. Work on Mosaic was begun in late 1992 by
Marc Andreesen and Eric Bina, with the first release in 1993.
In 1994 Andreesen left the NCSA to found a company called Mosaic Communications, where they built
a new browser from entirely new code. The new browser was called Netscape Navigator (and eventually
Mosaic Communications was renamed to Netscape Communications).
The actual Mosaic code base itself was licensed from the NCSA by a company called Spyglass, Inc.
Spyglass never did anything with the code, and in 1995 Microsoft licensed the code from them, modified it,
and renamed it Internet Explorer.
Both Netscape and Microsoft began expanding the capabilities of their browsers, adding new HTML
tags and other features. Netscape added JavaScript (codenamed “mocha” and originally released as
“LiveScript”) in Navigator in 1995. Microsoft quickly followed with their own version of the same language,
called JScript to avoid trademark issues, in 1996.
Netscape Navigator and Internet Explorer both had radically different implementations of the same
features, as well as their own proprietary features. A given HTML document could render one way in
Navigator and look completely different when rendered by Internet Explorer. Even simple HTML markup
produced significantly different visual results in the two browsers, and any attempt to do anything more
advanced was simply not possible.
This set the stage for the so-called Browser Wars. Anyone producing content for the Web had to make a
choice: choose a single browser to support, or spend significant resources to try and support both (in many
cases this meant producing two different versions of the same content, one version for each browser).
It became commonplace to see web sites that were optimized for only one browser, with graphics indicating
the choice, as shown in Figure 1-2.
Figure 1-2. Graphics from the Browser Wars
17. Chapter 1 ■ Welcome to HTML5
9
Microsoft handily won the first round of the Browser Wars by including Internet Explorer as a standard
part of the Windows operating system. This gave Internet Explorer a huge base of installations and little
reason for people to pay for Netscape. By 1999 Internet Explorer made up 96% of the browser usage on the
World Wide Web. Netscape Communications was acquired by AOL, and Netscape Navigator (by then called
Netscape Communicator) was mothballed.
BROWSER WARS: NETSCAPE STRIKES BACK
AOL open-sourced the Netscape Communicator code base and entrusted it to the newly formed
nonprofit organization named the Mozilla Foundation. The Mozilla Foundation continued to build upon
the Navigator code base as an open source project and gained considerable momentum, adding new
features to the browser including e-mail and HTML editing features. In late 2002 a stripped-down
browser-only version of the suite was created, initially called Phoenix, then Firebird, and then later
(due to project naming conflicts) Firefox. Firefox went on to successfully challenge Internet Explorer’s
hold on the browser market in what many people refer to as the second round of the Browser Wars.
Standards to the Rescue
Combating the fragmentation of the Web meant bringing all parties to the table and agreeing upon
technology standards everyone could build upon. Standards provided a common ground for both browser
manufacturers and content creators:
• By adopting standards as part of their manufacturing process, browser
manufacturers would provide a predictable platform for the Web.
• By adapting standards as part of their coding practices, content creators could be
assured that their content would render consistently across all browsers.
In October 1994, that’s exactly what Tim Berners-Lee did, in a move that harkened back to his desire
to keep the Web open and collaborative. He left CERN and formed the World Wide Web Consortium
(W3C), a standards organization devoted to web technologies. The consortium was made up of anyone
who wanted to participate in defining and maintaining the standards for web technologies: companies that
eventually included Microsoft, Apple, Facebook, and Google; government organizations like NASA and
National Institute of Standards and Technologies; universities like Stanford University and the University of
Oxford; research organizations like CERN; and nonprofit organizations like the Mozilla Foundation and the
Electronic Frontier Foundation.
The W3C standards process starts by publishing a working draft for a standard. The consortium
members can then comment on the draft, which can undergo considerable evolution. Once the draft
has solidified, a candidate recommendation is published. Candidate recommendations are reviewed
from an implementation viewpoint—how difficult will it be to implement and use the standard. Once
the implementers have had their say, the draft moves to the proposed recommendation status. Proposed
recommendations go before the W3C advisory council for final approval. Once that final approval is granted,
the standard is given the status of an official W3C recommendation.
Standards didn’t resolve the browser wars overnight. It took a while before browser manufacturers
implemented the standards. Microsoft in particular espoused an “embrace and extend” philosophy in which
they agreed to the standards but also continued to add on their own proprietary technologies in an attempt
to make Internet Explorer a more attractive platform for web development. In the end, though, the demand
for consistent behavior across all browsers won out, and standards provided the blueprint for the victory.
18. Chapter 1 ■ Welcome to HTML5
10
The Continuing Evolution of HTML
The HTML standard was initially maintained by the IETF, which published the HTML 2.0 standard in 1995 as
RFC 1866.
■
■ Note “RFC” stands for “Request for Comments,” which means the document was published and
stakeholders were invited to comment on it as part of an ongoing review process.
The W3C took over the HTML standard in 1996. In 1997 the W3C published the HTML 3.2 standard.
This version officially deprecated several vendor-specific features and further stabilized the standard for
both browser manufacturers and content creators. In less than a year the W3C published HTML 4.0. This
version of HTML moved the standard in the direction of purely semantic markup: many visual tags such as
those that created bold or italic tags were deprecated in favor of using Cascading Style Sheets (CSS). The
W3C published HTML 4.1 in 1999, which was essentially HTML 4.0 with some minor edits and corrections.
In 2000 HTML 4.1 because an ISO standard: ISO/IEC 15445:2000.
All of these HTML versions were defined as SGML applications. Each tag along with its attributes was
defined using SGML rules, as show in in Listing 1-1.
Listing 1-1. SGML Definition of the UL Tag in HTML 4.1
!ELEMENT UL - - (LI)+ -- unordered list --
!ATTLIST UL
%attrs; -- %coreattrs, %i18n, %events --
!ELEMENT OL - - (LI)+ -- ordered list --
!ATTLIST OL
%attrs; -- %coreattrs, %i18n, %events --
As the standards progressed, content creators had to follow them more and more strictly in order to
guarantee consistent behavior across browsers.
THE RISE AND FALL OF XHTML
In 2008 a new SGML application was proposed that would provide a smaller and more manageable
subset of SGML directives. Called the Extensible Markup Language, or XML, it was also meant to be
used to define data markup languages. The HTML 4 standard was quickly translated into XML, resulting
in XHTML. The XHTML 1.0 standard was published in 2000.
XHTML was meant to make the HTML language more modular and extensible. XHTML syntax is stricter
than plain HTML, and errors in XHTML markup will cause the rendering agent to publish an error and
stop rather than revert to a base behavior and continue. XHTML was never widely adopted, however,
because of lack of backward compatibility with older content and lack of browser support.
19. Chapter 1 ■ Welcome to HTML5
11
The Formation of the WHATWG and the Creation of HTML5
By 2004, the W3C was focusing its efforts on XHTML 2.0. However, some members of the consortium felt that
the XML-based direction wasn’t the correct path to follow for web technologies. The Mozilla Foundation and
Opera Software presented a position paper to the W3C in June 2004. This paper focused on web applications
as a whole: how to build them, what technologies they should employ, backward compatibility with existing
web browsers, and so forth. The paper included a draft specification for Web Forms as an example of direction.
You can read the paper on the W3C’s web site at www.w3.org/2004/04/webapps-cdf-ws/papers/opera.html.
The paper asked more questions than it answered, but overall it pointed in a different direction than the
W3C’s current XML-based solutions. In the end the W3C voted down the paper, opting to continue with
XML solutions.
Many stakeholders felt very strongly about looking at web applications in the holistic fashion proposed
by the paper, so a group was formed to focus on the creation of a web applications standard. Called the
Web Hypertext Application Technology Working Group (WHATWG), members included individuals from
Apple Inc., the Mozilla Foundation, and Opera Software. Initially they created a draft proposal for a Web
Applications standard, which covered all of the features that the group felt was important for creating rich,
interactive web applications, including:
• New semantic markup tags for common content patterns such as footers, sidebars,
and pull quotes.
• New state managemen0074 and data storage features.
• Native drag-and-drop interactions.
• New network features such as server-pushed events.
This new standard was eventually merged with the Web Forms standard (also being worked on by the
WHATWG) and the combined standard was renamed HTML5. This is why the HTML5 standard is not an
SGML application, and why it covers so much more than just markup: it was designed to provide better tools
for creating web applications.
In 2007 the W3C’s HTML group adopted the WHATWG’s HTML5 specification and began moving
forward with it. Both groups have continued to maintain their own versions of the same standard. By mutual
agreement the W3C maintains the canonical standard for HTML5. The WHATWG’s standard is considered a
“living standard,” which is therefore never complete and always evolving. In this way the W3C’s standard is
like a snapshot of the WHATWG’s standard.
THE W3C HTML5 STANDARD
The W3C’s HTML5 standard is available at www.w3.org/TR/html5/Overview.html. It is officially a W3C
recommendation.
THE WHATWG LIVING STANDARD
The WHATWG HTML standard is located at https://html.spec.whatwg.org/multipage/index.html.
20. Chapter 1 ■ Welcome to HTML5
12
HTML5 Features
Because it was designed to enable the creation of rich interactive web applications, HTML5 specifies a lot
more than just markup tags—though it covers those as well.
New Tags
The HTML5 standard specifies a host of new tags for marking up documents. New sectioning tags provide
ways of indicating common design patterns such as footers and navigation components and providing
improved semantic information for screen readers. New grouping tags offer ways to indicate groups of
content such as figures. And of course, HTML5 includes the new audio and video tags, for embedding
multimedia into web applications as easily as images. HTML5 also includes a whole set of new interactive
elements for implementing common design patterns such as dialogs and progressive disclosure.
Since it includes the Web Forms specification, HTML5 also includes many new form elements,
including data lists (filterable dropdowns), meters and progress bars, and sliders. HTML5 also specifies
several new form attributes to allow for richer interactions with forms. Now with simple attributes you can
specify placeholder text in a form field, or indicate what form field should have focus (be active) when the
page is loaded.
Canvas
HTML5 specifies the new canvas feature, a way to programmatically draw on a web page. The canvas also
includes features for text, layer blending, and image manipulation.
JavaScript APIs
The HTML5 standard includes a set of new JavaScript APIs to add more features to web applications. There
are new APIs for client/server communication, including the ability for servers to push events to web pages
and new ways of securing communication across documents and domains. There are also features for
storing data locally in the browser, drag-and-drop interactions, and multithreading.
Related Standards
There are a family of related standards that interact with HTML5, and are maintained by the W3C, but aren’t
technically members of the HTML5 standard. These include features like geolocation, device orientation,
and WebGL.
Summary
In this chapter I covered the history of HTML and how HTML5 came about, including:
• the origins of the underlying technologies,
• the browser wars, and
• the birth of the standards.
I also covered the overall composition of the HTML5 standard and its relatives.
Enough history! The next chapter will dive into the new HTML5 elements, including the audio and
video elements.
21. 13
Chapter 2
HTML5 Elements
Though the HTML5 specification is much more complex than previous versions, like those versions it
includes definitions of new elements and deprecations of old elements. In this chapter I’m going to focus on
the Elements section of the HTML5 specification.
I will start by showing how best practices have contributed to the evolution of HTML. Then I will cover
many of the new tags included in the HTML5 specification: tags for creating new sections, grouping content,
semantic markup, embedded content, new interactive content, and forms. I’ll also cover the new features of
web forms: new form properties, field properties, and input types. Finally, I’ll cover the elements that have
been deprecated in HTML5.
Functionality, Semantics, and the Evolution of HTML
HTML5 represents the latest in the language’s evolutionary line. In the beginning of the Web this evolution
was largely driven by the browser manufacturers, who all wanted to create their own proprietary spaces on
the Web to distinguish themselves from their competitors. Unfortunately, this led to the fracturing of the
Web that is now known as the “Browser Wars.”
The first standards were born to combat this fracturing. By providing a common ground for all browser
manufacturers, they made it possible for developers to code HTML that was platform independent.
More important, as the standards evolved further, a set of best practices evolved along with them to
help developers leverage the strengths of complying with the standards. Probably the two most important of
these practices were the concepts of separation of functionality and semantic markup.
Separation of functionality dictates that we should use each of our tools according to their strengths. It is
often summarized as “separation of presentation from content,” but it goes deeper than that: use HTML for
content, CSS for presentation, and JavaScript for functionality.
Decoupling HTML from CSS and JavaScript allows the three languages to evolve independently, and
also makes it possible for developers to upgrade more easily or even completely change technologies later
without having to totally redo the code for all three languages.
The core idea of semantic markup is to use the right tag to mark up a given section or piece of data as
determined by its content. In a way it’s a deeper application of separation of functionality: use the right tag
for the job. Thus paragraphs should be marked up with p tags, unordered (bulleted) lists with ul, list
items with li, and so forth. Today this best practice has become second nature to web developers, but it
wasn’t always that way. It was common to see tags used just for the indentation or margins that their default
styles provided, which made for pretty confusing markup.
The problem with these best practices is they were of little help outside of building simple informational
documents on the Web. If you wanted to do complex layouts, HTML didn’t have the necessary semantics.
And if you wanted to build functionality with web technologies, HTML really started to show its lack of
semantics.
22. Chapter 2 ■ HTML5 Elements
14
A major symptom of this lack was the proliferation of nonsemantic tags like div and span. Because
these tags only denote sections (div denotes a block-level section and span denotes an inline section)
they can safely be used to encompass just about any content. This suffusion of nonsemantic tags caused the
coining of the neologism “div-itis” or, more commonly, “divitis.”
One of the main purposes of HTML5 was to address these shortcomings. HTML5 specifies several
new tags for different sections of documents, new semantic tags, and tags for improving interactivity and
expanding the functionality of forms.
Sections
SUPPORT LEVEL
Good
All major browsers support section elements for at least the last two versions.
WHATWG Living Standard: http://www.whatwg.org/specs/web-apps/current-work/multipage/
sections.html#sections
W3C Candidate Recommendation: http://www.w3.org/TR/html5/sections.html#sections
HTML5 includes a set of new tags that are designed to address the lack of structural tags in previous
versions of HTML. Marking up even moderately complex documents revealed several weaknesses in the
original HTML tag set that resulted in the use of nonsemantic tags for many common purposes, such as
navigation sections, document headers, and document footers.
The new tags are as follows:
• article An article is a complete, self-contained set of content within a page.
Conceptually an article could be distributed or reused by itself. Examples of valid
articles include a single magazine article within a larger magazine, a blog post, a
reusable widget in the user interface, or any other self-contained set of content.
• aside An aside is a way of indicating a sidebar: a set of content that is independent
of, and tangential to, the content that surrounds it. Examples include pull quotes,
sidebars, or even advertising sections within larger documents.
• nav A nav section is the section with the major navigation links to other articles, or
to other documents. It is not generally meant for collections of minor links, such as
the links that are often relegated to a footer (in that specific case, the footer tag is
considered semantically sufficient).
• footer This well-named tag represents the footer of the containing section
element (body, article, etc.). Footers typically contain information about the
containing section element like copyright information, contact information, and
links to supporting documents and site maps.
• header The header tag groups together a set of introductory tags for the
current containing section element (body, article, etc.). Headers can contain
navigation, search forms, or even the document’s table of contents and internal links.
• section The section tag is used to group thematically similar content together,
often with a heading of some sort.
23. Chapter 2 ■ HTML5 Elements
15
Before these tags were introduced, these sections were typically marked up using div tags with
relevant CSS classes, as in Listing 2-1.
Listing 2-1. Old and Busted Markup with Nonsemantic Tag0073
!DOCTYPE HTML
html
head
titleThe HTML5 Programmer's Reference/title
style
body {
margin: 0;
padding: 0;
}
.page {
background-color: #C3DBE8;
}
.header {
background-color: #DDDDDD;
}
.header li {
display: inline-block;
border: 1px solid black;
border-radius: 5px;
padding: 0 5px;
}
.footer {
background-color: #DDDDDD;
}
/style
/head
body
div class=page
div class=header
h1Lorem Ipsum Dolor Sit Amet/h1
div class=navigation
ul
lione/li
litwo/li
lithree/li
/ul
/div
/div
div class=section
h2Section Header/h2
pLorem ipsum dolor sit amet, consectetur adipiscing elit.
Proin congue leo ut nut tincidunt, sed hendrerit justo
tincidunt. Mauris vel dui luctus, blandit felis sit amet,
mollis enim. Nam tristique cursus urna, id vestibulum
tellus condimentum vulputate. Aenean ut lectus adipiscing,
24. Chapter 2 ■ HTML5 Elements
16
molestie nibh vitae, dictum mauris. Donec lacinia odio
sit amet odio luctus, non ultrices dui rutrum. Cras
volutpat tellus at dolor rutrum, non ornare nisi
consectetur. Pellentesque sit amet urna convallis, auctor
tortor pretium, dictum odio. Mauris aliquet odio vel
congue fringilla. Mauris pellentesque egestas lorem./p
/div
div class=aside
h2Aside Header/h2
pVivamus hendrerit nisl nec imperdiet bibendum. Nullam
imperdiet turpis vitae tortor laoreet ultrices. Etiam
vel dignissim orci, a faucibus dui. Pellentesque
tincidunt neque sed sapien consequat dignissim./p
/div
div class=footer
div class=address
Sisko's Creole Kitchen, 127 Main Street,
New Orleans LA 70112
/div
/div
/div
/body
/html
Listing 2-1 divides your content into a single “page,” contained within a div tag with the class page
applied to it. Within this page you have a header with our navigation, a section, an aside, and a footer. You’ve
also applied some basic styling to the markup to better illustrate the header and footer sections, and make
the navigation elements look more like buttons than a simple unordered list.
This is the kind of markup that you’re probably used to seeing, and other than the fact that it relies a great
deal on nonsemantic div tags there’s nothing wrong with it. With the new HTML5 tags, however, you can
do away with all of those div tags and replace them instead with semantic tags, as you do in Listing 2-2.
Listing 2-2. New Hotness Markup with HTML5 Semantic Tags
!DOCTYPE HTML
html
head
titleThe HTML5 Programmer's Reference/title
style
body {
margin: 0;
padding: 0;
}
.page, article {
background-color: #C3DBE8;
}
.header, header {
background-color: #DDDDDD;
}
.header li, header li {
display: inline-block;
border: 1px solid black;
25. Chapter 2 ■ HTML5 Elements
17
border-radius: 5px;
padding: 0 5px;
}
.footer, footer {
background-color: #DDDDDD;
}
/style
/head
body
article
header
h1Lorem Ipsum Dolor Sit Amet/h1
nav
ul
lione/li
litwo/li
lithree/li
/ul
/nav
/header
section
h2Section Header/h2
pLorem ipsum dolor sit amet, consectetur adipiscing elit.
Proin congue leo ut nut tincidunt, sed hendrerit justo
tincidunt. Mauris vel dui luctus, blandit felis sit amet,
mollis enim. Nam tristique cursus urna, id vestibulum
tellus condimentum vulputate. Aenean ut lectus adipiscing,
molestie nibh vitae, dictum mauris. Donec lacinia odio
sit amet odio luctus, non ultrices dui rutrum. Cras
volutpat tellus at dolor rutrum, non ornare nisi
consectetur. Pellentesque sit amet urna convallis, auctor
tortor pretium, dictum odio. Mauris aliquet odio vel
congue fringilla. Mauris pellentesque egestas lorem./p
/section
aside
h2Aside Header/h2
pVivamus hendrerit nisl nec imperdiet bibendum. Nullam
imperdiet turpis vitae tortor laoreet ultrices. Etiam
vel dignissim orci, a faucibus dui. Pellentesque
tincidunt neque sed sapien consequat dignissim./p
/aside
footer
address
Sisko's Creole Kitchen, 127 Main Street,
New Orleans LA 70112
/address
/footer
/article
/body
/html
26. Chapter 2 ■ HTML5 Elements
18
You have replaced all of the nonsemantic divs with their associated semantic HTML5 tags. You’ve also
updated the style sheet so the new tags will share the same styles with the old classes that were applied to
the div tags you removed.
Browsers do render the two examples slightly differently. The differences vary from browser to browser:
Internet Explorer 10 has the least variation, with the only difference being that text contained within an
address tag is automatically rendered in italics. With Chrome and Firefox, the differences are greater, as
seen in Figure 2-1.
As you can see, the font size for h1 tags within header tags is smaller in both browsers, and they
both render text within address tags in italics, as does Internet Explorer. If you are migrating to the new
semantic tags, be sure you take these differences into account.
Figure 2-1. Screenshots of Listing 2-1 rendered in Chrome (left) and Listing 2-2 rendered in Firefox (right)
27. Chapter 2 ■ HTML5 Elements
19
Grouping
SUPPORT LEVEL
Good
All major browsers support figure and figcaption features for at least the last two versions.
Internet Explorer does not support the main tag natively but other browsers do.
WHATWG Living Standard: http://www.whatwg.org/specs/web-apps/current-work/multipage/
grouping-content.html#grouping-content
W3C Candidate Recommendation: http://www.w3.org/TR/html5/grouping-content.
html#grouping-content
HTML5 defines a few new tags for grouping content. These tags differ from the HTML5 Section tags in
that they define a given group of data as a particular kind of data, while the Section tags provide structure for
the document. The new tags are as follows:
• figure This tag is used to group together a set of content that is self-contained
and independent from the main document flow, but is referenced from within the
document flow. Examples of figures include illustrations, screenshots, and code
snippets.
• figcaption This tag is used to provide a caption for a figure tag. Captions
are optional.
• main The definition of the main tag differs between the W3C and the WHATWG
specifications. According to the W3C the main tag should be used to group
together the primary content of the document or application that has to do with
the main subject or functionality. According to the WHATWG, the main tag has
no intrinsic meaning and instead represents its contents. The rationale for this
difference is explained in detail in Bug 21553 over on the W3C’s bugbase:
https://www.w3.org/Bugs/Public/show_bug.cgi?id=21553.
The new grouping tags are simple to use, as demonstrated in Listing 2-3.
Listing 2-3. Using the New HTML5 Grouping Tags
!DOCTYPE HTML
html
head
titleThe HTML5 Programmer's Reference/title
style
figure figcaption {
font-style: italic;
}
figure pre {
line-height: 1.6em;
font-size: 11px;
padding: 1em 0.5em 0.0em 0.9em;
28. Chapter 2 ■ HTML5 Elements
20
border: 1px solid #bebab0;
border-left: 11px solid #ccc;
margin: 0.3 0 1.7em 0.3em;
overflow: auto;
max-height: 500px;
position: relative;
background: #faf8f0;
}
/style
/head
body
main
article
h1Main, Figure and Figcaption/h1
h2Best Things Ever/h2
pVivamus hendrerit nisl nec imperdiet bibendum. Nullam
imperdiet turpis vitae tortor laoreet ultrices. Etiam
vel dignissim orci, a faucibus dui. Pellentesque
tincidunt neque sed sapien consequat dignissim./p
figure
figcaptionUsing Figure and Figcaption for Code Samples/figcaption
pre
[sample code here]
/pre
/figure
pMore content about Main, Figure and Figcaption.../p
/article
/main
/body
/html
This example uses main to indicate the main section of the example document, and figure and
figcaption to define a code sample area. You have also applied some simple CSS styling to the code area
and its caption, to make it stand out more from the rest of the document, as shown in Figure 2-2.
29. Chapter 2 ■ HTML5 Elements
21
In this screenshot you can see that the browser applies some default margins to the figure tag, which
is fairly consistent across browsers.
Semantics
SUPPORT LEVEL
Mixed
There is little support in any browser for bdi, data, ruby, rt, rp, or time.
Support for mark is good (going back at least two versions of the major browsers) and wbr is
excellent (going back to the very earliest versions of the major browsers).
WHATWG Living Standard: http://www.whatwg.org/specs/web-apps/current-work/multipage/
text-level-semantics.html#text-level-semantics
W3C Candidate Recommendation: http://www.w3.org/TR/html5/text-level-semantics.
html#text-level-semantics
Figure 2-2. Screenshot of Listing 2-3 rendered in Firefox
30. Chapter 2 ■ HTML5 Elements
22
HTML5 includes several new semantic tags designed to help clarify content types.
• bdi The Bi-Directional Isolation Element is used to isolate an inline span of text
that might be rendered in a different direction than the surrounding text.
• data The data tag is used to associate machine-readable data with the content it
encloses. It provides a semantic way of annotating content with data002E
• mark This tag is used to mark occurrences within a document, such as search results.
• ruby, rp, and rt These tags are for Ruby annotations, which are used for
showing pronunciation of East Asian characters. For details about Ruby annotations,
see http://www.w3.org/TR/ruby/ and http://en.wikipedia.org/wiki/Ruby_
character.
• time The time tag is similar to data in that it provides a way to associate data
(in this case, specifically date/time data) with the enclosed content.
• wbr The Word Break Opportunity tag is used to indicate a position in the
document flow where the browser may initiate a line break though its internal rules
might not otherwise do so. It has no effect on bidi-ordering, and if the browser does
initiate a break at the tag, a hyphen is not used.
Unfortunately support for these tags is rather poor. The data and time tags, along with the tags for
Ruby annotations, are not widely supported, even in the most modern browsers.
The mark tag, though, is quite well supported, and is as easy to use as any other inline tag. Listing 2-4
shows a very simple use of the mark tag to highlight certain words within a document.
Listing 2-4. Marking Words in a Document
!DOCTYPE HTML
html
head
titleThe HTML5 Programmer's Reference/title
style
mark {
background-color: #E3DA5D;
}
/style
/head
body
article
h1Using the lt;markgt; tag/h1
pVivamus hendrerit nisl nec imperdiet markbibendum/mark. Nullam
imperdiet turpis vitae tortor laoreet ultrices. Etiam
vel dignissim orci, a faucibus dui. Pellentesque
tincidunt markneque/mark sed sapien consequat dignissim./p
/article
/body
/html
This example renders the same in all browsers (Figure 2-3).
31. Chapter 2 ■ HTML5 Elements
23
The wbr tag is probably one of the most broadly supported of all the HTML5 tags. It was a
nonstandard tag available in all browsers that was brought into the standard with HTML5. It’s used to
provide word break suggestions in long words, which can be situationally useful. Listing 2-5 shows a simple
example with long words before inserting wbr tags:
Listing 2-5. Long Words in a Document
!DOCTYPE HTML
html
head
titleThe HTML5 Programmer's Reference/title
style
.larger {
font-size: 2em;
}
/style
/head
Figure 2-3. Screenshot of Listing 2-4 rendered in Firefox
32. Chapter 2 ■ HTML5 Elements
24
body
article
h1Using the lt;wbrgt; tag/h1
pHere are some long words in a slightly larger font size to demonstrate
how useful the lt;wbrgt; tag can be./p
p class=largerSupercalifragilisticexpialidocious and antidisestablishmentarianism,
also pneumonoultramicroscopicsilicovolcanoconiosis./p
/article
/body
/html
As shown in Figure 2-4, Listing 2-5 renders as you would expect in all modern browsers.
You can easily use some wbr tags to help the browser decide where to break those long words, as in
Listing 2-6.
Figure 2-4. Rendering of Listing 2-5 in Firefox
33. Chapter 2 ■ HTML5 Elements
25
Listing 2-6. Suggesting Line Breaks in Large Words
!DOCTYPE HTML
html
head
titleThe HTML5 Programmer's Reference/title
style
.larger {
font-size: 2em;
}
/style
/head
body
article
h1Using the lt;wbrgt; tag/h1
pHere are some long words in a slightly larger font size to demonstrate
how useful the lt;wbrgt; tag can be./p
p class=largerSupercaliwbrfragilisticwbrexpialidocious and
antidiswbrestablishmentwbrarianism./p
/article
/body
/html
The browser can break the words at our suggestions if needed (Figure 2-5).
Figure 2-5. Rendering Listing 2-6 at different browser widths
34. Chapter 2 ■ HTML5 Elements
26
As you can see, the browser can now use our word break suggestions if it needs to. This can be
particularly useful if you are working on cramped layouts where screen real estate is at a premium, such as
on a mobile device.
Audio and Video Content
SUPPORT LEVEL
Good
All modern browsers support audio and video elements for at least the last two versions, but see the
following for information about format support.
WHATWG Living Standard: http://www.whatwg.org/specs/web-apps/current-work/multipage/
edits.html#embedded-content
W3C Candidate Recommendation: www.w3.org/TR/html5/embedded-content-0.html#embedded-
content-0
One of the biggest shortcomings of previous versions of HTML was their inability to easily include
multimedia content on web pages. HTML5 has new tags that specifically address that problem. With these
new tags, including multimedia content on a web page is as easy as including static images. Even better, all
modern browsers support these capabilities very well.
Before HTML5, if you wanted to embed a video into your web page, you needed a third-party plug-in
that had the ability to play the desired content, as well as do things like adjust the volume, fast-forward or
reverse through the content, and so forth. With HTML5, browser manufacturers have built these capabilities
into their software. These capabilities include a user interface for controlling playback and the ability to play
various media formats for audio and video encoding.
An unfortunate complication is that audio and video can both be encoded in many different formats,
and many of these formats have patent encumbrances that made the browser manufacturers unwilling to
support them. So while all modern browsers support multimedia tags, some browsers support different
formats than others. For details on what browser supports which formats, see Chapter 7.
Another complication arises from interacting with multimedia. For example, users will often want
to skip around in content, going forward or back as desired. Supporting interactive functionality like that
requires a server that is capable of reacting to these user interactions and can provide the portions of content
as needed. Simple web servers typically don’t have this capability, though many of them can be configured
to do so. For more information on configuring servers for multimedia, see Chapter 7.
Embedded Audio Content
With the HTML5 audio tag, you can embed audio content into your web pages as easily as including an
image. Like any HTML tag, the audio tag has several properties that you can set:
• autoplay: This is a boolean flag that, when set (to anything, even false), will cause
the browser to immediately begin playing the audio content as soon as it can without
stopping for buffering.
• controls: If this attribute is set, the browser will display its default user interface
controls for the audio player (volume controls, progress meter/scrub bar, etc.).
35. Chapter 2 ■ HTML5 Elements
27
• loop: If this attribute is set, the browser will loop playback of the specified file.
• muted: This attribute specifies that the playback should be muted by default.
• preload: This attribute is used to provide to the browser a hint for how to provide the
best user experience for the specified content. It can take three values: none, metadata,
and auto. The none value specifies that the author wants to minimize the download
of the audio content, possibly because the content is optional, or because the server
resources are limited. The metadata value specifies that the author recommends
downloading the metadata for the audio content (duration, track list, tags, etc.) and
possibly the first few frames of the content. The auto value specifies that the browser
can put the user’s needs first without risk to the server. This means the browser can
begin buffering the content, download all the metadata, and so forth. Note that these
values can be changed after the page has loaded. For example, if you have a page with
many audio tags each with preload set to none to prevent swamping the server,
when the user makes a choice of which of the audio tags they want to hear, you can
dynamically change its preload value to auto to provide a better user experience. This
enables you to balance user experience with available resources.
• src: This attribute specifies the source of the content, just as with an img tag.
If desired, this attribute can be omitted in favor of one or more source tags
contained within the audio tag.
The audio tag is not self-closing and thus requires a closing tag. Note that since older browsers do
not support the audio tag, any content contained within one will be displayed in those browsers, thus
providing a backward-compatible way of providing alternate content in older browsers.
The audio tag is very easy to use, as shown in Listing 2-7.
Listing 2-7. Embedding Audio Content in a Web Page
!DOCTYPE HTML
html
head
titleThe HTML5 Programmer's Reference/title
/head
body
article
h1Using the lt;audiogt; tag/h1
audio controls=controls src=../media/windows-rolled-down.mp3
/audio
/article
/body
/html
■
■ Note The examples in this section use audio files. You should substitute your own files as needed.
Listing 2-7 has opted to show the controls for the native player to demonstrate what they look like by
default. Each browser’s native player looks slightly different and has somewhat different features (Figure 2-6).
36. Chapter 2 ■ HTML5 Elements
28
Chrome’s default audio player has a volume slider, while Firefox’s player has a tooltip indicating current
play time. It is not possible to style the player, so if you want to have a consistent look and feel across all
browsers you will have to build your own player—which is actually quite easy to do because HTML5 also
specifies a JavaScript API for working with audio tags. For details on this API, please see Chapter 7.
■
■ Tip In Chrome, the audio and video players are implemented as web components using the new Shadow
DOM specification. Using the Shadow DOM APIs it is possible to access and style the components of the player
directly. For example, the background of the player is a shadow div, which can be selected with the CSS
selector audio::-webkit-media-controls-panel and whose appearance (such as the background color)
can be altered as desired. Similarly, the volume bar is an input type=range tag with the selector
audio::-webkit-media-controls-volume-slider. Unfortunately, at the time of this writing Chrome and
Opera are the only two browsers to support the Shadow DOM specification. Other browsers may also be
implementing their players using Shadow DOM, and when they fully support the specification, their players may
become accessible as well, allowing web developers to control the appearance of the players without having to
resort to building their own from scratch.
Figure 2-6. Listing 2-7 rendered in Chrome (left) and Firefox (right)
37. Chapter 2 ■ HTML5 Elements
29
Embedded Video Content
The HTML5 video tag enables basic video capabilities in browsers. It functions similarly to the audio
tag and has a similar set of properties that can be set:
• autoplay: This is a boolean flag that, when set (to anything, even false), will cause
the browser to immediately begin playing the video content as soon as it can without
stopping for buffering.
• controls: If this attribute is set, the browser will display its default user interface
controls for the video player (volume controls, progress meter/scrub bar, etc.).
• height: This attribute can be used to specify the height, in pixels, of the video player.
• loop: If this attribute is set, the browser will loop playback of the specified file.
• muted: This attribute specifies that the playback should be muted by default.
• poster: This attribute can be used to specify a URL for a poster to display before the
video is played. If no poster is specified, then the player will show the first frame of
the video by default, once it has loaded.
• preload: This attribute is used to provide the browser a hint for how to provide
the best user experience for the specified content. It can take three values: none,
metadata, and auto. The none value specifies that the author wants to minimize the
download of the video content, possibly because the content is optional, or because
the server resources are limited. The metadata value specifies that the author
recommends downloading the metadata for the video content (duration, track list,
tags, etc.) and possibly the first few frames of the content. The auto value specifies
that the browser can put the user’s needs first without risk to the server. This means
the browser can begin buffering the content, download all the metadata, and so
forth. Note that these values can be changed after the page has loaded. For example,
if you have a page with many video tags, each with preload set to none to prevent
swamping the server, when the user chooses which of the video tags they want to
view, you can dynamically change its preload value to auto to provide a better user
experience. This enables you to balance user experience with available resources.
• src: This attribute specifies the source of the content, just as with an img tag.
If desired, this attribute can be omitted in favor of one or more source tags
contained within the video tag.
• width: This attribute can be used to specify the width of the video player, in pixels.
The video tag is just as easy as the audio tag to use, as shown in Listing 2-8.
Listing 2-8. Embedding Video Content in a Web Page
!DOCTYPE html
html
head
titleThe HTML5 Programmer's Reference/title
/head
body
article
h1Using the lt;videogt; tag/h1
video controls=controls src=../media/podcast.m4v
38. Chapter 2 ■ HTML5 Elements
30
/video
/article
/body
/html
■
■ Note The examples in this section use video files. You should substitute your own files as needed.
And as with the audio tag, each browser provides a slightly different video player, as shown in
Figure 2-7.
As before, the two browsers have slightly different interfaces for their video players. If you want to
change the appearance of the player and its controls, you’ll have to build your own.
Specifying Multiple Sources
Both the audio and video tags have an src attribute, but you can forgo that attribute in favor of
including a list of one or more source tags inside of the audio or video tag. You can even specify
different encodings of the same file, thus working around any limitations that browsers might have with
encoding support. The browser will go down the list of source tags and play the first file that it supports.
The source tag has two attributes:
• src: The URL for the audio file.
• type: The MIME type of the audio file, with an optional codecs parameter, specified
according to RFC 4281.
As an example, imagine you have a video that we want to serve. You have it in two different formats: Ogg
Vorbis and MP4. Use two source tags as shown in Listing 2-9.
Figure 2-7. Listing 2-8 rendered in Chrome (left) and Firefox (right)
39. Chapter 2 ■ HTML5 Elements
31
Listing 2-9. Specifying Multiple Sources for Multimedia
video controls
source src=../media/video-1.mp4 type=video/mp4
source src=../media/video-1.ogv type=video/ogg
/video
You can get very precise about the encoding of your audio and video by using the optional codecs
parameter in the type attribute. For example, if you have an H.264 video (profile 3) with low-complexity AAC
audio all contained in an MP4 container, you could specify the codecs as shown in Listing 2-10:
Listing 2-10. Specifying Audio and Video Codecs for a Video Source
source src=../media/video-1.mp4 type=video/mp4, codecs=' avc1.4D401E, mp4a.40.2'
This can be particularly useful for providing the best possible quality encoding for your video while
allowing the most browsers to access it regardless of encoding support limitations.
Interactive Elements
SUPPORT LEVEL
Unsupported
Interactive elements are not supported by modern browsers except for experimental versions.
WHATWG Living Standard: http://www.whatwg.org/specs/web-apps/current-work/multipage/
interactive-elements.html#interactive-elements
W3C Candidate Recommendation: http://www.w3.org/TR/html5/interactive-elements.html
HTML5 includes a new set of interactive elements that are intended to provide some prebuilt user
interface elements that can be used in web pages and applications. Unfortunately, these features are not yet
supported in most browsers, but support probably will improve with time.
Dialogs
One of the most exciting new features is the dialog tag, which provides the ability to easily create pop-up
dialogs. Any content enclosed in a dialog tag is not rendered in the document until you call one of its
display methods:
• show: Calling this method will open the dialog as a standard pop-up.
• showModal: Calling this method will open the dialog as modal dialog, with the rest of
the page grayed out behind the dialog.
In addition, each dialog will dispatch a close event when it is closed.
Listing 2-11 is a simple example that demonstrates how to use the dialog tag. As of this writing, the
only browser that supports the dialog tag is Chrome, and even then you have to activate the Experimental
Web Platform Features in chrome://flags. If you enable the features, the example will work great.
40. Chapter 2 ■ HTML5 Elements
32
Listing 2-11. Web Dialogs
!DOCTYPE HTML
html
head
titleThe HTML5 Programmer's Reference/title
style
li {
display: inline-block;
background-color: #A9DCF5;
border-radius: 4px;
padding: 2px 10px;
cursor: pointer;
}
/style
/head
body
article
h1Using the lt;dialoggt; tag/h1
ul
li id=open-dialogOpen Dialog/li
li id=open-modalOpen Modal/li
/ul
dialog id=dialog
pHello World!/p
button id=close-dialogOkay/button
/dialog
/article
script
var myDialog = document.getElementById('dialog'),
openDialog = document.getElementById('open-dialog'),
openModal = document.getElementById('open-modal'),
closeDialog = document.getElementById('close-dialog'),
status = document.getElementById('status');
closeDialog.addEventListener('click', function(event) {
myDialog.close();
}, false);
openDialog.addEventListener('click', function(event) {
myDialog.show();
}, false);
openModal.addEventListener('click', function(event) {
myDialog.showModal();
}, false);
myDialog.addEventListener('close', function(event) {
alert('A close event was dispatched.');
}, false);
/script
/body
/html
41. Chapter 2 ■ HTML5 Elements
33
This will render a very simple dialog shown in Figure 2-8.
Each time you close one of the dialogs, the close event will fire, producing an alert that reads, “A close
event was dispatched.”
This is the default appearance of the dialogs. They can easily be styled with CSS to make them more
attractive, and of course they can contain any content, including images, form fields, and so forth. You can
also style the backdrop for the modal instance; it is a pseudo-element that can be accessed using ::backdrop
on your dialog selector.
For example, in Listing 2-12, if you add a couple of simple CSS directives to your style sheet, you’ll have
a much more attractive dialog.
Listing 2-12. CSS Styles for Web Dialogs
dialog {
text-align: center;
padding: 1.5em;
margin: 1em auto;
border: 0;
border-radius: 8px;
box-shadow: 0 2px 10px #111;
}
dialog::backdrop {
background-color: rgba(187, 217, 242, 0.8);
}
Figure 2-8. The dialogs that Listing 2-11 produces
42. Chapter 2 ■ HTML5 Elements
34
These styles will change the appearance of both the dialog and the modal backdrop (Figure 2-9).
Though the dialog tag is currently only supported in Chrome, there is a polyfill that provides most of
the functionality in other browsers available at https://github.com/GoogleChrome/dialog-polyfill.
■
■ Tip Polyfill is a term for a library that enables or duplicates unsupported features in browsers. Another
term for polyfill is shim.
Progressive Disclosure
One common UI feature is progressive disclosure: you provide a simple list of items, and when the user
clicks on one, the space beneath expands, revealing more information. These widgets go by different names
depending on the framework used (jQuery UI, for example, refers to them as accordions). HTML5 includes
a definition for this feature using the summary and details tags. The details tag encloses all of the
desired content, including a summary tag, which should enclose just a brief summary of the content. The
default rendering of a details tag is to show just the contents of the summary tag preceded by a small
triangle. The user can then click anywhere on the summary and the rest of the content will be revealed. You
can specify that a given details tag is to be rendered in the open state by giving it the open attribute.
At the moment, Chrome, Opera, and Safari are the only browsers that support the details and
summary tags. Firefox will be supporting the tags and you can check the status of their support in bug
591737 at https://bugzilla.mozilla.org/show_bug.cgi?id=591737. The status of support in Internet
Explorer is unknown.
Figure 2-9. Web dialog (modal state) with CSS styles applied
43. Chapter 2 ■ HTML5 Elements
35
The tags are simple to use, as shown in Listing 2-13.
Listing 2-13. Progressive Disclosure
!DOCTYPE HTML
html
head
titleThe HTML5 Programmer's Reference/title
/head
body
article
h1Using the lt;summarygt; and lt;detailsgt; tags/h1
details
summaryItem 1/summary
pLorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus
accumsan orci nec justo rhoncus facilisis. Integer pellentesque
ipsum vitae semper lacinia. Quisque non nisl rutrum, porta est at,
ultrices neque. Aenean consequat, lacus vulputate vestibulum
faucibus, turpis magna mollis quam, a congue neque lorem at
justo./p
/details
details
summaryItem 2/summary
pLorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus
accumsan orci nec justo rhoncus facilisis. Integer pellentesque
ipsum vitae semper lacinia. Quisque non nisl rutrum, porta est at,
ultrices neque. Aenean consequat, lacus vulputate vestibulum
faucibus, turpis magna mollis quam, a congue neque lorem at
justo./p
/details
details open
summaryItem 3--this one will be open by default/summary
pLorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus
accumsan orci nec justo rhoncus facilisis. Integer pellentesque
ipsum vitae semper lacinia. Quisque non nisl rutrum, porta est at,
ultrices neque. Aenean consequat, lacus vulputate vestibulum
faucibus, turpis magna mollis quam, a congue neque lorem at
justo./p
/details
details
summaryItem 3/summary
pLorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus
accumsan orci nec justo rhoncus facilisis. Integer pellentesque
ipsum vitae semper lacinia. Quisque non nisl rutrum, porta est at,
ultrices neque. Aenean consequat, lacus vulputate vestibulum
faucibus, turpis magna mollis quam, a congue neque lorem at
justo./p
/details
/article
/body
/html
44. Chapter 2 ■ HTML5 Elements
36
In Chrome, this example renders nicely, as shown in Figure 2-10.
Clicking on a closed item reveals its hidden content, and clicking on an open item hides its content.
Forms
Forms have been significantly improved in HTML5. The specification includes both new tags for forms
(such as data lists, progress meters, and date pickers) as well as new attributes for existing form tags. These
new features are designed to make forms more interactive for users and easier to build and maintain.
New Form Elements
SUPPORT LEVEL
Mixed
Most of these features are well supported in the major browsers for the last two versions. Internet
Explorer does not support the meter tag, however.
WHATWG Living Standard: http://www.whatwg.org/specs/web-apps/current-work/multipage/
forms.html#forms
W3C Candidate Recommendation: http://www.w3.org/TR/html5/forms.html#forms
Figure 2-10. Listing 2-13 rendered in Chrome
45. Chapter 2 ■ HTML5 Elements
37
HTML5 has a few new form elements that are specifically designed to implement common user
interface patterns that have evolved over the last few years. Specifically these new tags implement
autocomplete features and progress bars.
Data Lists
The first of the new tags implements a common autocomplete feature: when you begin typing into a form
field, a drop-down appears that has a list of options that match what has already been typed. As you continue
to type, the list becomes more specific, and at any time you can use the arrow keys to select one of the options.
These sort of autocomplete fields are often referred to as data lists (and sometimes combo boxes) and HTML5
has a new datalist tag that implements this exact user interface element.
In practice, a datalist tags contain option tags, one for each item in the data list. By themselves
datalist elements are not rendered in page, and can go anywhere in the document structure. Once
created, a data list must be associated with an input field in order to use it. Give the datalist tag a unique
id attribute. To associate it with an input element, set that element’s list attribute to the unique id. That
tells the browser to render the specified data list with the input element, as demonstrated in Listing 2-14.
Listing 2-14. A Data List
!DOCTYPE html
html
head
titleThe HTML5 Programmer's Reference/title
/head
body
!-- Note the datalist can be anywhere --
datalist id=browsers
option value=Chrome
option value=Firefox
option value=Internet Explorer
option value=Opera
option value=Safari
/datalist
article
h1Using the lt;datalistgt; tag/h1
input list=browsers /
/article
/body
/html
As with other HTML5 user interface elements, each browser renders the data list slightly differently
(Figure 2-11).
46. Chapter 2 ■ HTML5 Elements
38
As you can see, Chrome provides a drop-down arrow hint on the right side of the input field to indicate
that the input field is a data list, and Firefox has a slight drop shadow on the dropdown. The functionality of
the list remains the same between browsers.
Meter
The new meter tag provides a simple meter bar or gauge visual element. This bar is meant to model a
measurement within a known range, or a fractional value of a whole (e.g., volume, disk usage, etc.). It should
not be used to show progress (e.g., in a download); use the new progress tag for this.
The meter tag has the following properties:
• value: The current value to be displayed. This value must be within the min and max
values, if specified. If no value is set, or if it is malformed, the browser will default to 0.
If specified but the value is greater than the max attribute, the value will be set to the
value of the max attribute. If the value is less than the min attribute, the value will be
set to the value of the min attribute.
• min: The minimum value of the range. Defaults to 0 if not specified.
• max: The maximum value of the range. Must be greater than the value of the min
attribute (if specified). Defaults to 1.
It is also possible to specify subranges within the measured range. There can be a low range, a high
range, and an optimum range. The low range goes from the min value to a specified value, while the high
range goes from the high value to the max value. Either the low range or the high range can be specified as an
optimum range by specifying a number within them using the optimum attribute.
• low: The highest value of the low range. When the value attribute is within the low
range, the bar will render yellow by default.
• high: The lowest value of the high range, which ranges from this value to the value
of the max attribute. When the value attribute is within the high range, the bar will
render yellow by default.
Figure 2-11. Listing 2-14 rendered in Chrome (left) and Firefox (right)
47. Chapter 2 ■ HTML5 Elements
39
• optimum: Indicates an optimum value for the range. The value must be between the
min and max values of the range. If the low and high ranges are used, specifying an
optimum value within one of them will indicate which of those ranges is preferred.
When the value is within the preferred range, the bar will render green. When it is in
the other range, it will render red.
Creating these meters is as simple as adding a meter tag to your document, as demonstrated in
Listing 2-15.
Listing 2-15. Meter Bars
!DOCTYPE html
html
head
titleThe HTML5 Programmer's Reference/title
/head
body
article
h1Using the lt;metergt; tag/h1
pSimple meter from 1 to 100, value set to 25:br
meter min=1 max=100 value=25/meter
/p
pSimple meter from 1 to 100, low range from 1 to 25, high range from
75 to 100, value set to 90:br
meter min=1 max=100 low=25 high=75 value=90/meter
/p
pSimple meter from 1 to 100, low range from 1 to 25, high range from
75 to 100, value set to 10:br
meter min=1 max=100 low=25 high=75 value=10/meter
/p
pSimple meter from 1 to 100, low range from 1 to 25, high range from
75 to 100, optimum set to 10, value set to 10:br
meter min=1 max=100 low=25 high=75 optimum=10 value=10/meter
/p
pSimple meter from 1 to 100, low range from 1 to 25, high range from
75 to 100, optimum set to 10, value set to 10:br
meter min=1 max=100 low=25 high=75 optimum=10 value=90/meter
/p
/article
/body
/html
The meters render pretty consistently across browsers (Figure 2-12).
48. Chapter 2 ■ HTML5 Elements
40
Output
The new output tag provides a way of specifying the output of a calculation or other user action within
a form. It doesn’t have any special features; instead it provides a semantic tag for marking up this kind of
content.
A simple example is shown in Listing 2-16.
Listing 2-16. Calculation Output in a Form
!DOCTYPE html
html
head
titleThe HTML5 Programmer's Reference/title
/head
body
article
h1Using the lt;outputgt; tag/h1
form id=mainform onsubmit=return false
label for=input-numberTemperature/label
Figure 2-12. Listing 2-15 rendered in Chrome (left) and Firefox (right)
49. Chapter 2 ■ HTML5 Elements
41
input name=input-number id=input-number type=number step=anybr
input type=radio name=convert-choice id=radio-ftoc checked value=ftoc
label for=radio-ftocConvert Fahrenheit to Celcius/labelbr
input type=radio name=convert-choice id=radio-ctof value=ctof
label for=radio-ctofConvert Celcius to Fahrenheit/labelbr
Result:
output name=output-target for=input-number id=output-target/output
/form
/article
script
var myForm = document.getElementById('mainform');
var converter = {
ctof: function(degreesC) {
return (((degreesC * 9) / 5) + 32);
},
ftoc: function(degreesF) {
return (((degreesF - 32) * 5) / 9);
}
};
myForm.addEventListener('input', function() {
var inputNumber = document.getElementById('input-number'),
outputTarget = document.getElementById('output-target');
var sel = document.querySelector('input[name=convert-choice]:checked').value;
outputTarget.value = converter[sel](parseInt(inputNumber.value));
}, false);
/script
/body
/html.
This is a simple example, but you’ve used a couple of nifty tricks.
• You created a converter object, which has two methods, ctof (for converting Celsius
to Fahrenheit) and ftoc (for converting Fahrenheit to Celsius).
• You set one of the radio button’s value properties to ctof, and the other to ftoc.
• You used the selector input[name=convert-choice]:checked to get whichever radio
button is checked and then fetch its value (either “ctof” or “ftoc”).
• Then you can directly access the correct method on the converter object just by
using the result of your query.
■
■ Tip JavaScript is also governed by a standard—ECMA-262—which specifically defines two ways to
access object members: dot notation or bracket notation. So objectName.identifierName is functionally
equivalent to objectName[identifierName string] even if the object in question is not an array. For
details, see Section 11.2.1, “Property Accessors,” in ECMA-262 at http://www.ecma-international.org/
ecma-262/5.1/.
50. Chapter 2 ■ HTML5 Elements
42
Figure 2-13 shows Listing 2-16 as rendered in Chrome.
Progress
HTML5 defines a new progress tag, which renders as a progress meter in the document. It is used to
indicate progression or completion of a task, and provides the user with an idea of how much has been done
and what still remains. It should not be used for visualizing a measurement within a known range—for that,
use the meter tag.
The progress tag takes the following attributes:
• max: The maximum value of the activity. This value must be a valid positive
floating-point number. If max is not specified, the maximum value defaults to 1.
• value: The current value of the progress. This value must be a valid floating-point
number between 0 and max (if specified) or 1 (if max is not specified). If value is not
specified, then the progress bar is considered indeterminate, meaning the activity
it is modeling is ongoing but gives no indication of how much longer it will take to
complete.
Listing 2-17 provides a simple demonstration of progress bars.
Figure 2-13. Listing 2-16 rendered in Chrome
51. Chapter 2 ■ HTML5 Elements
43
Listing 2-17. Progress Bars
!DOCTYPE html
html
head
titleThe HTML5 Programmer's Reference/title
/head
body
article
h1Using the lt;progressgt; tag/h1
pDownloading file1br
progress max=100 value=1010/100/progress 10%/p
pDownloading file2br
progress max=100 value=50 orient=vertical50/100/progress 50%/p
/article
/body
/html
As shown in Figure 2-14, the progress bar renders differently in the various browsers.
The examples would look different when rendered on MacOS as well. Fortunately, the bars are easy
to style. Firefox and Internet Explorer give direct access to the element’s styling, while in Chrome you have
to select the pseudo-elements to change them. By adding a few simple directives to your CSS, as shown in
Listing 2-18, you can make the bar look the same in all browsers.
Listing 2-18. CSS Rules for Progress Bars
progress {
color: #0063a6;
font-size: .6em;
line-height: 1.5em;
text-indent: .5em;
width: 15em;
height: 1.8em;
border: 1px solid #0063a6;
background-color: #fff;
}
Figure 2-14. Listing 2-17 rendered in Chrome (left), Internet Explorer (middle), and Firefox on Windows 8
(right)
52. Chapter 2 ■ HTML5 Elements
44
::-webkit-progress-bar {
background-color: #fff;
}
::-webkit-progress-value {
background-color: #0063a6;
}
As you can see in Figure 2-15 the bars now render the same across browsers.
A slightly more practical example would be a timer. Using the progress tag you can indicate that
some allotted time—ten seconds, for example—is passing, as shown in Listing 2-19.
Listing 2-19. A Ten-Second Timer
!DOCTYPE html
html
head
titleThe HTML5 Programmer's Reference/title
style
progress {
color: #0063a6;
font-size: .6em;
line-height: 1.5em;
text-indent: .5em;
width: 15em;
height: 1.8em;
border: 1px solid #0063a6;
background-color: #fff;
}
::-webkit-progress-bar {
background-color: #fff;
}
::-webkit-progress-value {
background-color: #0063a6;
}
/style
/head
Figure 2-15. Progress bars with CSS rules applied
53. Chapter 2 ■ HTML5 Elements
45
body
article
h1Using the lt;progressgt; tag/h1
h2Ten Second Timer/h2
pprogress max=10 value=0 id=myProgress0/progress/p
/article
script
var progress = 0;
var myProgress = document.getElementById(myProgress);
var myTimer = setInterval(function() {
myProgress.value = ++progress;
if (progress 10) {
clearInterval(myTimer);
}
}, 1000);
/script
/body
/html
This example uses the DOM method setInterval() to run a function every second that updates the
value of the progress bar. When the progress bar is full, it cancels the timer with the clearInterval() method.
New Form Element Attributes
The HTML5 specification includes a few useful new attributes for form elements. Again, these new attributes
were designed specifically to address shortcomings in previous versions of HTML forms and to add
commonly needed functionality that, until now, had to be built using JavaScript.
Autocomplete
All browsers offer the capability of storing form data for later reuse. This is of particular help with mobile
devices because it reduces typing. The autocomplete attribute allows you to specify which input elements
can be autocompleted and which should always be filled in manually. The autocomplete attribute can take
two values: on (autocomplete is allowed; this is the default) or off (autocomplete is not allowed).
Listing 2-20 is a simple example with two form fields, one with autocomplete allowed and the other
with it disallowed.
Listing 2-20. Controlling Autocomplete in Forms
!DOCTYPE html
html
head
titleThe HTML5 Programmer's Reference/title
/head
body
article
h1Using the autocomplete attribute/h1
form id=test-form action=# method=post
plabel for=input-autoThis input allows autocomplete:/labelbr
input autocomplete=on id=input-auto name=input-auto/p
plabel for=input-noautoThis input does not allow autocomplete:/labelbr
54. Chapter 2 ■ HTML5 Elements
46
input autocomplete=off id=input-noauto name=input-noauto/p
pinput type=submit/p
/form
/article
/body
/html
In just about every browser, you should be able to fill out the form fields and click the submit button.
Then, reload the page. Double-click in the first form field, and you should be presented with a drop-down
containing the value you entered earlier (Figure 2-16).
Note that you will have to enable the autofill feature in your browser. Most browsers will enable it by
default, but many people turn it off for security purposes. If the user has disabled the feature in their browser,
the autocomplete attribute will have no effect.
Browsers use a number of cues to determine which form fields should be autocompleted with what
data: the name and ID for the fields, the action and method attributes of the form tag, and so forth.
The process is fairly nonstandard and edges into the realm of “magic.” In 2012, Google proposed an
extension to the autocomplete property to help standardize the process. In this proposal they suggested an
autocompletetype attribute with an extensive set of values ranging from address-line1 to postal-code to
url. You can read their full proposal at http://wiki.whatwg.org/wiki/Autocompletetype. That proposal
was never fully adopted, but sections from it eventually went into the new Autofill specification, which you
can view at https://html.spec.whatwg.org/multipage/forms.html#autofill.
Autofocus
The autofocus attribute allows you to specify what form field should have focus when the page loads.
Because it is exclusive, you can only set autofocus on one form field on a given page, and the focus will go
to that element when the page is done loading. You cannot set autofocus on a form element of type hidden.
Autofocus can be set to any input, button, or textarea field.
If you add an autofocus attribute to the second field in listing 2-20 on page load it will be focused, as in
Listing 2-21.
Figure 2-16. Listing 2-20 rendered in Chrome (left) and Firefox (right)
60. This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Title: Chronicles (1 of 6): The Description of Britaine
Author: Raphael Holinshed
William Harrison
John Hooker
Release date: April 11, 2013 [eBook #42506]
Most recently updated: October 23, 2024
Language: English
Credits: Produced by Jonathan Ingram, Lesley Halamek and the
Online
Distributed Proofreading Team at http://www.pgdp.net
*** START OF THE PROJECT GUTENBERG EBOOK CHRONICLES (1
OF 6): THE DESCRIPTION OF BRITAINE ***
61. HOLINSHED'S
CHRONICLES
ENGLAND, SCOTLAND,
AND
IRELAND.
IN SIX VOLUMES.
VOL. I.
ENGLAND.
LONDON:
PRINTED FOR J. JOHNSON; F. C. AND J. RIVINGTON; T. PAYNE; WILKIE
AND ROBINSON; LONGMAN, HURST, REES, AND ORME;
CADELL AND DAVIES; AND J. MAWMAN.
1807.
AMS PRESS INC.
NEW YORK
62. AMS PRESS INC.
NEW YORK, N.Y. 10003
1965
MANUFACTURED in the U.S.A.
[Original Title.]
THE
FIRST AND SECOND VOLUMES
of
CHRONICLES,
comprising
1 The description and historie of England,
2 The description and historie of Ireland,
3 The description and historie of Scotland:
first collected and published
BY
63. RAPHAELL HOLINSHED,
WILLIAM HARRISON, AND OTHERS:
Now newlie augmented and continued (with manifold
matters of singular note and worthie memorie)
TO THE YEARE 1586,
By JOHN HOOKER aliàs VOWELL Gent.
AND OTHERS.
WITH CONUENIENT TABLES AT THE END OF THESE
VOLUMES.
HISTORIÆ PLACEANT NOSTRATES AC PEREGRINÆ.
64. THE CONTENTS OF VOLUME I
Page
Advertisement. iv
Dedication. v
The Names of the Authors from whom this Historie of
England is collected. ix
An Historicall Description of the Iland of Britaine,
Book I 1
An Historicall Description of the Iland of Britaine,
Book II 221
An Historicall Description of the Iland of Britaine,
Book III 369
Transcriber's Note
ADVERTISEMENT.
The chronicles of holinshed having become exceedingly scarce, and,
from their Rarity and Value, having always brought a high Price
whenever they have appeared for Sale, the Publishers have thought
they should perform an acceptable Service to the Public by reprinting
them in a uniform, handsome, and modern Form.
65. It cannot now be necessary to state the Importance and interesting
Nature of this Work. The high Price for which it has always sold, is a
sufficient Testimony of the Esteem in which it has been held.
Holinshed's Description of Britain is allowed to contain the most
curious and authentic Account of the Manners and Customs of our
Island in the Reign of Henry VIII. and Elizabeth, in which it was
written. His History of the Transactions of the British Isles, during
these Periods, possesses all the Force and Value of contemporary
Evidence, collected by a most skilful Observer; and the peculiar Style
and Orthography in which the Work is written, furnish a very
interesting Document to illustrate the History of the English
Language.
The original Edition of the Chronicles of Holinshed, it is well known,
was published by their Author in a mutilated State. A Number of
Pages, which had obviously been printed with the rest of the Work,
were found to be omitted, except in a few Copies obtained by some
favoured Persons. In the present Edition, these Castrations are
faithfully restored; and in order that the Purchaser may depend upon
finding an exact as well as a perfect Copy, it has been a Law with
the Publishers, not to alter a single Letter, but to print the Work with
the utmost Fidelity from the best preceding Edition, with the
Author's own Orthography, and with his marginal Notes. The only
Liberty taken, has been to use the Types of the present Day, instead
of the old English Letter of the Time of Elizabeth.
The Publishers submit to the Public this Edition of a curious and
valuable Chronicle of our History, with a confident Hope, that it will
gratify both the Historical Student and the General Reader. If it meet
with the Reception which they anticipate, they will be encouraged to
select some others of the rarest and most important of our ancient
Chronicles, and reprint them, in like Manner, for the Convenience
and Gratification of the Public.
66. TO THE
RIGHT HONORABLE, AND HIS SINGULAR GOOD
LORD AND MAISTER,
S. WILLIAM BROOKE KNIGHT,
lord warden of the cinque ports, and baron of cobham,
all increase of the feare and knowledge of god, firme
obedience toward his prince, infallible loue to the
common wealth, and commendable renowme here in this
world, and in the world to come life euerlasting.
Hauing had iust occasion, Right Honorable, to remaine in London,
during the time of Trinitie terme last passed, and being earnestlie
required of diuers my freends, to set downe some breefe discourse
of parcell of those things, which I had obserued in the reading of
such manifold antiquities as I had perused toward the furniture of a
Chronologie, which I haue yet in hand; I was at the first verie loth to
yeeld to their desires: first, for that I thought my selfe vnable for
want of skill and iudgment, so suddenlie with so hastie speed to
take such a charge vpon me: secondlie, bicause the dealing therein
might prooue an hinderance and impechment vnto mine owne
Treatise: and finallie, for that I had giuen ouer all earnest studie of
histories, as iudging the time spent about the same, to be an
hinderance vnto my more necessarie dealings in that vocation
function wherevnto I am called in the ministerie. But when they
were so importunate with me, that no reasonable excuse could
serue to put by this trauell, I condescended at the length vnto their
yrkesome sute, promising that I would spend such void time as I
had to spare, whilest I should be inforced to tarie in the citie, vpon
some thing or other that should satisfie their request; and stand in
67. lieu of a description of my Countrie. For their parts also they assured
me of such helps as they could purchase: and thus with hope of
good, although no gaie successe, I went in hand withall, then almost
as one leaning altogither vnto memorie, sith my books and I were
parted by fourtie miles in sunder. In this order also I spent a part of
Michaelmas and Hilarie termes insuing, being inforced thereto I say
by other businesses which compelled me to keepe in the citie, and
absent my selfe from my charge, though in the meane season I had
some repaire vnto my poore librarie, but not so great as the dignitie
of the matter required, and yet far greater than the Printers hast
would suffer. One helpe, and none of the smallest that I obtained
herein, was by such commentaries as Leland had somtime collected
of the state of Britaine, books vtterlie mangled, defaced with wet
and weather, and finallie vnperfect through want of sundrie volumes:
secondlie, I gat some knowledge of things by letters and pamphlets,
from sundrie places shires of England, but so discordant now and
then amongst themselues, especiallie in the names and courses of
riuers and situation of townes, that I had oft greater trouble to
reconcile them one with an other, than orderlie to pen the whole
discourse of such points as they contained: the third aid did grow by
conference with diuers, either at the table or secretlie alone, wherein
I marked in what things the talkers did agree, and wherin they
impugned ech other, choosing in the end the former, and reiecting
the later, as one desirous to set foorth the truth absolutelie, or such
things in deed as were most likelie to be true. The last comfort arose
by mine owne reading of such writers as haue heretofore made
mention of the condition of our countrie, in speaking wherof, if I
should make account of the successe, extraordinarie cōming by
sundrie treatises not supposed to be extant, I should but seeme to
pronounce more than may well be said with modestie, say farder
of my selfe than this Treatise can beare witnes of. Howbeit, I refer
not this successe wholie vnto my purpose about this Description, but
rather giue notice thereof to come to passe in the penning of my
Chronologie, whose crums as it were fell out verie well in the
framing of this Pamphlet. In the processe therefore of this Booke, if
your Honor regard the substance of that which is here declared, I
68. must needs confesse that it is none of mine owne: but if your
Lordship haue consideration of the barbarous composition shewed
herein, that I may boldlie claime and challenge for mine owne, sith
there is no man of any so slender skill, that will defraud me of that
reproch, which is due vnto me for the meere negligence, disorder,
and euill disposition of matter comprehended in the same. Certes I
protest before God and your Honour, that I neuer made any choise
of stile, or words, neither regarded to handle this Treatise in such
precise order and method as manie other would haue done, thinking
it sufficient, truelie and plainelie to set foorth such things as I
minded to intreat of, rather than with vaine affectation of eloquence
to paint out a rotten sepulchre; a thing neither commendable in a
writer, nor profitable to the reader. How other affaires troubled me in
the writing hereof manie know, and peraduenture the slacknesse
shewed herein can better testifie: but howsoeuer it be done,
whatsoeuer I haue done, I haue had an especiall eye vnto the truth
of things, and for the rest, I hope that this foule frizeled Treatise of
mine will prooue a spur to others better learned, more skilfull in
Chorographie, and of greater iudgement in choise of matter to
handle the selfe same argument, if in my life time I doo not peruse
it againe. It is possible also that your Honour will mislike hereof, for
that I haue not by mine owne trauell and eysight viewed such things
as I doo here intreat of. In deed I must needs confesse, that vntill
now of late, except it were from the parish where I dwell, vnto your
Honour in Kent; or out of London where I was borne, vnto Oxford
Cambridge where I haue bene brought vp, I neuer trauelled 40.
miles foorthright and at one iourney in all my life; neuerthelesse in
my report of these things, I vse their authorities, who either haue
performed in their persons, or left in writing vpon sufficient ground
(as I said before) whatsoeuer is wanting in mine. It may be in like
sort that your Honour will take offense at my rash and retchlesse
behauiour vsed in the composition of this volume, and much more
that being scambled vp after this maner, I dare presume to make
tendour of the protection therof vnto your Lordships hands. But
when I consider the singular affection that your Honour dooth beare
to those that in any wise will trauell to set foorth such profitable
69. things as lie hidden, and therevnto doo weigh [Page viii] on mine owne
behalfe my bounden dutie and gratefull mind to such a one as hath
so manie and sundrie waies benefited me that otherwise can make
no recompense, I can not but cut off all such occasion of doubt, and
therevpon exhibit it, such as it is, and so penned as it is, vnto your
Lordships tuition, vnto whome if it may seeme in anie wise
acceptable, I haue my whole desire. And as I am the first that
(notwithstanding the great repugnancie to be seene among our
writers) hath taken vpon him so particularlie to describe this Ile of
Britaine; so I hope the learned and godlie will beare withall,
reforme with charitie where I doo tread amisse. As for the curious,
and such as can rather euill fauouredlie espie than skilfullie correct
an error, and sooner carpe at another mans dooings than publish
any thing of their owne, (keeping themselues close with an obscure
admiration of learning knowledge among the common sort) I force
not what they saie hereof: for whether it doo please or displease
them, all is one to me, sith I referre my whole trauell in the
gratification of your Honour, and such as are of experience to
consider of my trauell, and the large scope of things purposed in this
Treatise, of whome my seruice in this behalfe may be taken in good
part, that I will repute for my full recompense, and large guerdon of
my labours. The Almightie God preserue your Lordship in continuall
health, wealth, and prosperitie, with my good Ladie your wife, your
Honours children, (whom God hath indued with a singular
towardnesse vnto all vertue and learning) and the rest of your
reformed familie, vnto whom I wish farder increase of his holie spirit,
vnderstanding of his word, augmentation of honor, and continuance
of zeale to follow his commandements.
Your Lordships humble seruant
and houshold Chaplein.
W. H.
70. ¶ THE NAMES OF THE AUTHORS
FROM WHOME THIS
HISTORIE OF ENGLAND
IS COLLECTED.
A.
Aelius Spartianus.
Aelius Lampridius.
Asserius Meneuensis.
Alfridus Beuerlacensis.
Aeneas Syluius Senensis.
Auentinus.
Adam Merimouth with
additions.
Antoninus Archiepiscopus
Florentinus.
Albertus Crantz.
Alexander Neuill.
Arnoldus Ferronius.
Annius Viterbiensis.
Amianus Marcellinus.
Alliances genealogiques des
Roys Princes de France.
Annales D. Aquitaine per
Iean Bouchet.
Annales de Bourgoigne per
Guilamme Paradin.
Annales de France per Nicol
Giles.
71. Annales rerum Flandricarum
per Jacobum Meir.
Antonius Sabellicus.
Antonius Nebricensis.
Aurea Historia.
B.
Biblia Sacra.
Beda venerabilis.
Berosus.
Brian Tuke knight.
Blondus Forliuiensis.
Berdmondsey, a Register
booke belonging to that
house.
C.
Cæsars Commentaries.
Cornelius Tacitus.
Chronica Chronicorum.
Chronica de Dunstable, a
booke of Annales belonging
to the Abbey there.
Chronicon Io. Tilij.
Chronica de Eyton, an
historie belonging to
that colledge, although
compiled by some
Northernman, as some
suppose named
Otherborne.
Chronicles of S. Albon.
Chronica de Abingdon, a
booke of Annales belonging
72. to that house.
Chronica de Teukesburie.
Claudianus.
Chronicon Genebrard.
Chroniques de Normandie.
Chroniques de Britaine.
Chroniques de Flanders
published by Denis Sauage.
Continuation de Historie and
Chroniques de Flanders by
the same Sauage.
Couper.
Cuspinianus.
Chronica Sancti Albani.
Caxtons Chronicles.
Carion with additions.
Crockesden, a Register
booke belonging to an house
of that name in
Staffordshire.
D.
Diodorus Siculus.
Dion Cassius.
Dominicus Marius Niger.
E.
Edmerus.
Eusebius.
Eutropius.
Encomium Emmæ, an old
Pamphlet written to hir,
conteining much good
matter for the
73. vnderstanding of the
state of this realme in
hir time, wherein hir
praise is not
pretermitted, and so
hath obteined by reason
thereof that title.
Enguerant de Monstrellet.
Eulogium.
Edmund Campian.
F.
Fabian.
Froissart.
Franciscus Tarapha.
Franciscus Petrarcha.
Flauius Vopiscus
Siracusanus.
Floriacensis Vigorinensis.
G.
Gviciardini Francisco.
Guiciardini Ludouico.
Gildas Sapiens.
Galfridus Monemutensis,
aliàs Geffrey of Monmouth.
Giraldus Cambrensis.
Guilielmus Malmesburiensis.
Galfridus Vinsauf.
Guilielmus Nouoburgensis.
Guilielmus Thorne.
Gualterus Hemmingford,
aliàs Gisburnensis.
Geruasius Dorobernensis.
74. Geruasius Tilberiensis.
Guilielmus Gemeticensis de
ducibus Normaniæ.
Guilielmus Rishanger.
Guilielmus Lambert.
Georgius Lillie.
Guilamme Paradin.
H.
Higinus.
Henricus Huntingtonensis.
Henricus Leicestrensis.
Hector Boece.
Historie Daniou.
Historia Ecclesiastica
Magdeburgensis.
Henricus Mutius.
Historia quadripartita seu
quadrilogium.
Hardings Chronicle.
Halles Chronicle.
Henricus Bradshaw.
Henricus Marleburgensis.
Herodianus.
Humfrey Luyd.
I.
Iohannes Bale.
Iohannes Leland.
Iacobus Philippus Bergomas.
Iulius Capitolinus.
Iulius Solinus.
Iohannes Pike with
additions.
75. Iohannes Functius.
Iohn Price knight.
Iohannes Textor.
Iohannes Bodinus.
Iohannes Sleidan.
Iohannes Euersden a Monke
of Berry.
Iohannes or rather Giouan
villani a Florentine.
Iohannes Baptista Egnatius.
Iohannes Capgraue.
Iohannes Fourden.
Iohannes Caius.
Iacob de Voragine Bishop of
Nebio.
Iean de Bauge a Frenchman
wrote a pamphlet of the
warres in Scotland,
during the time that
Monsieur de Desse
remained there.
Iohn Fox.
Iohannes Maior.
Iohn Stow, by whose diligent
collected summarie, I
haue beene not onelie
aided, but also by diuers
rare monuments,
ancient writers, and
necessarie register
bookes of his, which he
hath lent me out of his
own Librarie.
Iosephus.
L.
76. Liber constitutionum London.
Lucan.
Lælius Giraldus.
M.
Marianus Scotus.
Matthæus Paris.
Matthæus Westmonaster.
aliàs Flores historiarum.
Martin du Bellay, aliàs Mons.
de Langey.
Mamertinus in Panegyricis.
Memoires de la Marche.
N.
Nicephorus.
Nennius.
Nicholaus Treuet with
additions.
O.
Orosius Dorobernensis.
Osbernus Dorobernensis.
Otho Phrisingensis.
P.
Pausanias.
Paulus Diaconus.
Paulus Aemilius.
Ponticus Virunius.
Pomponius Lætus.
Philip de Cumeins, aliàs M.
de Argenton.
77. Polydor Virgil.
Paulus Iouius.
Platina.
Philippus Melancthon.
Peucerus.
Pomponius Mela.
R.
Rogerus Houeden.
Ranulfus Higeden, aliàs
Cestrensis the author of
Polychronicon.
Radulfus Cogheshall.
Radulfus Niger.
Register of the Garter.
Records of Battell Abbey.
Richardus Southwell.
Robert Greene.
Radulfus de Diceto.
Robert Gaguin.
Rodericus Archiepiscopus
Toletanus.
Records and rolles diuerse.
S.
Strabo.
Suetonius.
Sigebertus Gemblacensis.
Sidon Appollinaris.
Simon Dunelmensis.
Sextus Aurelius Victor.
T.
Trebellius Pollio.
78. Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
ebookbell.com