Introducing HTML 5
Second Edition
Bruce Lawson
Remy Sharp
Introducing HTML5, Second Edition
Bruce Lawson and Remy Sharp
New Riders
1249 Eighth Street
Berkeley, CA 94710
510/524-2178
510/524-2221 (fax)
Find us on the Web at: www.newriders.com
To report errors, please send a note to
New Riders is an imprint of Peachpit, a division of Pearson Education
Copyright 2012 by Remy Sharp and Bruce Lawson
Project Editor: Michael J. Nolan
Development Editor: Margaret S. Anderson/Stellarvisions
Technical Editors: Patrick H. Lauke (www.splintered.co.uk),
Robert Nyman (www.robertnyman.com)
Production Editor: Cory Borman
Copyeditor: Gretchen Dykstra
Proofreader: Jan Seymour
Indexer: Joy Dean Lee
Compositor: Danielle Foster
Cover Designer: Aren Howell Straiger
Cover photo: Patrick H. Lauke (splintered.co.uk)
Notice of Rights
All rights reserved. No part of this book may be reproduced or transmitted in any form by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. For information on getting permission for reprints and excerpts, contact .
Notice of Liability
The information in this book is distributed on an As Is basis without warranty. While every precaution has been taken in the preparation of the book, neither the authors nor Peachpit shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the instructions contained in this book or by the computer software and hardware products described in it.
Trademarks
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 Peachpit was aware of a trademark claim, the designations appear as requested by the owner of the trademark. All other product names and services identified throughout this book are used in editorial fashion only and for the benefit of such companies with no intention of infringement of the trademark. No such use, or the use of any trade name, is intended to convey endorsement or other affiliation with this book.
ISBN 13: 978-0-321-78442-1
ISBN 10: 0-321-78442-1
9 8 7 6 5 4 3 2 1
Printed and bound in the United States of America
Acknowledgements
Huge thanks to coauthor-turned-friend Remy Sharp, and friend-turned-ruthless-tech-editor Patrick Lauke: il miglior fabbro. At New Riders, Michael Nolan, Margaret Anderson, Gretchen Dykstra, and Jan Seymour deserve medals for their hard work and their patience.
Thanks to the Opera Developer Relations Team, particularly the editor of dev.opera.com, Chris Mills, for allowing me to reuse some materials I wrote for him, Daniel Davis for his description of , Shwetank Dixit for checking some drafts, and David Storey for being so knowledgeable about Web Standards and generously sharing that knowledge. Big shout to former team member Henny Swan for her support and lemon cake. Elsewhere in Opera, the specification team of James Graham, Lachlan Hunt, Philip Jgenstedt, Anne van Kesteren, and Simon Pieters checked chapters and answered 45,763 daft questions with good humour. Nothing in this book is the opinion of Opera Software ASA.
Ian Hickson has also answered many a question, and my fellow HTML5 doctors (www.html5doctor.com) have provided much insight and support.
Many thanks to Richard Ishida for explaining
to me and allowing me to reproduce his explanation. Also to Aharon Lanin. Smoochies to Robin Berjon and the Mozilla Developer Center who allowed me to quote them.
Thanks to Gez Lemon and mighty Steve Faulkner for advice on WAI-ARIA. Thanks to Denis Boudreau, Adrian Higginbotham, Pratik Patel, Gregory J. Rosmaita, and Lonie Watson for screen reader advice.
Thanks to Stuart Langridge for drinkage, immoral support, and suggesting the working title HTML5 Utopia. Mr. Last Weeks creative vituperation provided loadsalaffs. Thanks, whoever you are.
Thanks to John Allsopp, Tantek elik, Christian Heilmann, John Foliot, Jeremy Keith, Matt May, and Eric Meyer for conversations about the future of markup. Silvia Pfeiffers blog posts on multimedia were invaluable to my understanding.
, and Jake Smith provided valuable feedback on early drafts of my chapters. Lastly, but most importantly, thanks to the thousands of students, conference attendees, and Twitter followers for their questions and feedback.
This book is in memory of my grandmothers, Marjorie Whitehead, 8 March 191728 April 2010, and Elsie Lawson 6 June 192020 August 2010.
This book is dedicated to Nongyaw, Marina, and James, without whom life would be monochrome.
Bruce Lawson
ber thanks to Bruce who invited me to coauthor this book and without whom I would have spent the early part of 2010 complaining about the weather instead of writing this book. On that note, Id also like to thank Chris Mills for even recommending me to Bruce.
To Robert Nyman, my technical editor: when I was in need of someone to challenge my JavaScript, I knew there would always be a Swede at hand. Thank you for making sure my code was as sound as it could be. Equally to Patrick Lauke, who also whipped some of my code, and certainly parts of my English, into shape.
Thanks to the local Brighton cafs, Coffee@33 and Caf Dlice, for letting me spend so many hours writing this book and drinking your coffee.
To my local Brighton digital community and new friends who have managed to keep me both sane and insane over the last few years of working alone. Thank you to Danny Hope, Josh Russell, and Anna Debenham for being my extended colleagues.
Thank you to Jeremy Keith for letting me rant and rail over HTML5 and bounce ideas, and for encouraging me to publish my thoughts. Equal thanks to Jessica for letting us talk tech over beers!
To the HTML5 Doctors and Rich Clark in particular for inviting me to contributeand also to the team for publishing such great material.
To the whole #jquery-ot channel for their help when I needed to debug, or voice my frustration over a problem, and for being someplace I could go rather than having to turn to my cats for JavaScript support.
To the #whatwg channel for their help when I had misinterpreted the specification and needed to be put back on the right path. In particular to Anne Van Kesteren, who seemed to always have the answers I was looking for, perhaps hidden under some secret rock Im yet to discover.
To all the conference organisers that invited me to speak, to the conference goers that came to hear me ramble, to my Twitter followers that have helped answer my questions and helped spur me on to completing this book with Bruce: thank you. Ive tried my best with the book, and if theres anything incorrect or out of date: blame Bruce buy the next edition. ;-)
To my wife, Julie: thank you for supporting me for all these many years. Youre more than I ever deserved and without you, I honestly would not be the man I am today.
Finally, this book is dedicated to Tia. My girl. I wrote the majority of my part of this book whilst you were on our way to us. I always imagined that youd see this book and be proud and equally embarrassed. That wont happen now, and even though youre gone, youll always be with us and never forgotten.
Remy Sharp
Introduction
Welcome to the second edition of the Remy & Bruce show. Since the first edition of this book came out in July 2010, much has changed: support for HTML5 is much more widespread; Internet Explorer 9 finally came out; Google Chrome announced it would drop support for H.264 video; Opera experimented with video streaming from the users webcam via the browser, and HTML5 fever became HTML5 hysteria with any new technique or technology being called HTML5 by clients, bosses, and journalists.