HTML5 Developers Cookbook
Chuck Hudson
Tom Leadbetter
Upper Saddle River, NJ Boston Indianapolis San Francisco
New York Toronto Montreal London Munich Paris Madrid
Capetown Sydney Tokyo Singapore Mexico City
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.
The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact:
U.S. Corporate and Government Sales
(800) 382-3419
For sales outside the United States, please contact:
International Sales
Visit us on the Web: informit.com/aw
Editor-in-Chief
Mark Taub
Senior Acquisitions Editor
Trina MacDonald
Development Editor
Michael Thurston
Managing Editor
John Fuller
Project Editor
Anna Popick
Copy Editor
Kim Wimpsett
Indexer
Jack Lewis
Proofreader
Lori Newhouse
Technical Reviewers
Evan Burchard
Siddharth Ram
Tim Wright
Publishing Coordinator
Olivia Basegio
Cover Designer
Gary Adair
Compositor
Rob Mauhar
Library of Congress Cataloging-in-Publication Data
Hudson, Chuck, 1969
HTML5 developers cookbook / Chuck Hudson, Tom Leadbetter.
p. cm.
Includes index.
ISBN 978-0-321-76938-1 (pbk. : alk. paper)
1. HTML (Document markup language) 2. Internet programming. 3. Web
site development. I. Leadbetter, Tom, 1983 II. Title.
QA76.76.H94H836 2012
006.74dc23
2011040007
Copyright 2012 Pearson Education, Inc.
All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458, or you may fax your request to (201) 236-3290.
ISBN-13: 978-0-321-76938-1
ISBN-10: 0-321-76938-4
Text printed in the United States on recycled paper at RR Donnelley in Crawfordsville, Indiana.
First printing, December 2011
To Alex, my grandfather, thank you for sharing your love of life and books.
Chuck
To Lucy, thanks for being you.
Tom
Contents
Introduction
Hypertext Markup Language (HTML) is a core language for creating and structuring web pages. For more than 20 years developers have been writing HTML, and for the first few years the language underwent radical changes, but in the late 1990s things slowed down a bit. Until now.
A Brief History of HTML
In 1991 Sir Tim Berners-Lee wrote a document called HTML Tags, which described 20 elements that would be used for writing web documents. By mid-1993 the Internet Engineering Task Force (IETF) had published a proposal for the first HTML specification. The proposal draft expired, and it was not until November 1995 that the first specification was published: not HTML 1.0, but HTML 2.0.
HTML 3.2 was released in 1997, and this was followed up by HTML 4, published in 1998. HTML 4 had three variations: Strict, Transitional, and Frameset. During this period, browser vendors, such as Microsoft and Netscape, started implementing HTML in slightly different ways, and we had our first round of browser wars (http://en.wikipedia.org/wiki/Browser_wars).
XHTML
After the release of HTML 4, the World Wide Web Consortium (W3C) decided to stop the evolution and development of HTML and work on Extensible Hypertext Markup Language (XHTML) 1.0, an XML-based language that was considered the future of the Internet. There were no new elements in XHTMLin fact, the specification was the same as HTML 4but developers had to conform to new syntax rules: Tags had to be closed, or self-closed, and attributes had to be quoted. This required stricter, tighter coding standards and ensured that developers would be using a single style of writing. Around this time in 2001, Cascading Style Sheets (CSS) started becoming more prominent and popular, and with the rise of blogging, the increased awareness of web standards was significant.
Beginning in 2002, the W3C released drafts of XHTML 1.1. While XHTML 1 was essentially HTML with a splash of XML, XHTML 1.1 was essentially XML. Although it was supposed to be more forward-thinking, it was not backward compatible, so if it was used in website development, the website would not work in current and older browsers.
This caused concern among the web community, with browser vendors, and even within the W3C itself. Not everyone was convinced that XML was the future markup of the web.
Web Forms, Web Apps, and the WHATWG
In 2004, individuals from Apple, Mozilla, and Opera began working on their own specification, aiming at creating backward-compatible code that could be used to create web applications. W3C rejected this proposal, and this led to a group being formed calling itself the Web Hypertext Application Technology Working Group (WHATWG).
The WHATWG began working on Web Forms 2.0 and Web Applications 1.0. The editor for the specifications is Ian Hixie Hickson, and issues and ideas are raised via a public mailing list. Although initially there was work on two specifications, Web Forms 2.0 and Web Applications 1.0, they have now been merged into one specification, called HTML5.
XHTML 2 versus HTML5
So, while WHATWG was developing HTML5, over at the W3C, the XHTML 2 specification was languishing. In 2006, the W3C decided that it had made the wrong decision in abandoning HTML in the previous years, and although it would still develop XHTML 2, it would once again look at the development of HTML. The W3C decided to use the work done so far by WHATWG as the starting point for a new version of HTML.
Although this was positive news, it also led to a confusing state because there were now currently three different types of markup being worked on: two by the W3C, HTML 5 and XHTML 2; and one at the WHATWG, HTML5 (notice there is no space compared to the W3C HTML 5). So, with HTML5/HTML 5, the specification was being developed at the same time but by two groups.
WHATWG operates in a very different manner than the W3C, and it is able to move at a much faster pace. Because of the public mailing list at WHATWG, ideas were put forward regularly, and web developers were able to question some of the decisions made. The specification team was, and still is, able to implement good ideas, reject bad ideas, and change or remove items of the specification based on community feedback quickly. HTML5 was developing much quicker at WHATWG than at the W3C.