Home > Store

HTML5 Developer's Cookbook

Register your product to gain access to bonus material or receive a coupon.

HTML5 Developer's Cookbook


  • Sorry, this book is no longer in print.
Not for Sale

eBook (Watermarked)

  • Your Price: $21.75
  • List Price: $27.19
  • Includes EPUB and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    Adobe Reader PDF The popular standard, used most often with the free Acrobat® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.


  • Copyright 2012
  • Dimensions: 7" x 9"
  • Pages: 480
  • Edition: 1st
  • Book
  • ISBN-10: 0-321-76938-4
  • ISBN-13: 978-0-321-76938-1

2012 Jolt Productivity Award winner!

Using HTML5, web developers can create standards-based browser applications with extraordinary richness and power, incorporating everything from drag-and-drop to native audio and video–all without any third-party plug-ins. Simply put, every web developer needs to master HTML5–and the sooner you do so, the greater advantage you’ll have. HTML5 Developer’s Cookbook provides all the expert advice and proven code you need to start building production-quality HTML5 applications right now.

Authors Chuck Hudson and Tom Leadbetter present tested, modular recipes at beginner, intermediate, and advanced levels. You’ll learn exactly how to deliver state-of-the-art user experiences by integrating HTML5’s new and enhanced elements with CSS3, multimedia, and JavaScript APIs. Reflecting current standards, this book prioritizes HTML5 features with substantial browser support and identifies the level of browser support for each feature discussed. Coverage includes

  • Understanding and using HTML5’s new structural elements
  • Using grouping, text-level, and redefined semantics
  • Managing browser-handling in HTML5
  • Leveraging new CSS3 layout and style techniques
  • Maximizing interactivity with HTML5 Web Forms
  • Embedding audio and video with HTML5
  • Drawing with the canvas
  • Controlling browser histories
  • Integrating location awareness with the Geolocation API
  • Implementing client side storage
  • Working with local files
  • Managing communication and threading
  • Optimizing the HTML5 browser experience
  • Integrating device data

Turn to HTML5 Developer’s Cookbook for expert answers, real solutions, and the code required to implement them. It’s all you need to jumpstart any HTML5 project and create rich, high-value web applications your users will love.

Sample Content

Online Sample Chapter

New Structural Elements in HTML5

Table of Contents

Introduction xix

Acknowledgments xxvii

About the Authors xxix

Chapter 1: New Structural Elements in HTML5 1

BEGINNER RECIPE: Building an HTML5 Starter Document 2

Where Do All the New Elements Come From? 4

BEGINNER RECIPE: Using the header Element to Create a Site Header 5

BEGINNER RECIPE: Using the hgroup Element to Group Headings 7

BEGINNER RECIPE: Creating Navigation with the nav Element 8

INTERMEDIATE RECIPE: Using the New article Element 11

INTERMEDIATE RECIPE: Grouping Content with the section Element 12

BEGINNER RECIPE: Creating a Sidebar with the aside Element 15

BEGINNER RECIPE: Using the footer Element 17

INTERMEDIATE RECIPE: Using the HTML5 Outliner to Ensure the Correct Structure 19

ADVANCED RECIPE: Using All the New Elements to Build a News Page 21

ADVANCED RECIPE: Using All the New Elements to Build a Search Results Page 25

Summary 30

Chapter 2: Grouping, Text-Level, and Redefined Semantics 31

BEGINNER RECIPE: Marking Up Figures and Captions with the figure and figcaption Elements 31

BEGINNER RECIPE: Marking Up the Date and Time with the time Element 34

BEGINNER RECIPE: Making a Native Toggle Widget with the details Element 35

BEGINNER RECIPE: Using the address Element for Contact Information 37

BEGINNER RECIPE: Highlighting Text with the mark Element 38

BEGINNER RECIPE: Using the s Element to Show Inaccurate or Irrelevant Content 39

Changes to Existing Elements 39

BEGINNER RECIPE: Wrapping Links Around Elements 47

INTERMEDIATE RECIPE: Adding Semantic Information with Microdata 47


ADVANCED RECIPE: Marking Up an Article Page with Comments 51

Summary 54

Chapter 3: Browser Handling in HTML5 55

BEGINNER RECIPE: Dealing with Internet Explorer 55

Boilerplates 57

BEGINNER RECIPE: Testing for HTML5 Features 57

INTERMEDIATE RECIPE: Leveraging jQuery to Replace a Calendar 59

INTERMEDIATE RECIPE: Using Modernizr to Detect Features 62

Polyfilling 66

Useful HTML5 Verification Sites 67

Summary 67

Chapter 4: New Layout and Style Techniques with CSS3 69

INTERMEDIATE RECIPE: Creating a Responsive Design with CSS3 Media Queries 69

BEGINNER RECIPE: Using Custom Fonts with @font-face 77

INTERMEDIATE RECIPE: Making Buttons with CSS Gradients and Multiple Backgrounds 80

INTERMEDIATE RECIPE: Enhancing a Site with Transformations and Transitions 84

ADVANCED RECIPE: Creating Animations with CSS 89

Summary 94

Chapter 5: HTML5 Web Forms 95

Validation 95

HTML 4 Input Types 95

BEGINNER RECIPE: Creating a Form to Collect Contact Information 97

BEGINNER RECIPE: Creating a Search Form with input type="search" 101

BEGINNER RECIPE: Creating Calendar and Time Controls 102

BEGINNER RECIPE: Creating a Number Picker 105

BEGINNER RECIPE: Creating a Slider (Without the Need for JavaScript) 106

BEGINNER RECIPE: Creating a Color Picker 107

BEGINNER RECIPE: Displaying Results with the output Element 108

BEGINNER RECIPE: Using Form Placeholder Text 109

BEGINNER RECIPE: Creating an Autocomplete Feature with list and datalist 110

BEGINNER RECIPE: Tracking the Completion of a Task with the progress Element 111

BEGINNER RECIPE: Measuring with the meter Element 112

BEGINNER RECIPE: Jumping to a form Element When the Page Loads 114

BEGINNER RECIPE: Allowing Multiple Entries 115

BEGINNER RECIPE: Basic Validation with the required Attribute 116

INTERMEDIATE RECIPE: Writing Your Own Validation Rule 117

BEGINNER RECIPE: Limiting User Input 118

INTERMEDIATE RECIPE: Customizing and Styling the Form 119

Error Messages 121

ADVANCED RECIPE: Putting It All Together to Make a Sign-Up Form 121

Summary 125

Chapter 6: Drawing with Canvas 127

Canvas Overview 127

BEGINNER RECIPE: Laying a Grid on the Canvas 130

Canvas Tools 134

BEGINNER RECIPE: Making Simple Shapes and Lines 134

INTERMEDIATE RECIPE: Drawing Polygons with a Path 139

INTERMEDIATE RECIPE: Drawing Arcs and Circles 143

BEGINNER RECIPE: Adding Text 144

BEGINNER RECIPE: Drawing an Image 145

INTERMEDIATE RECIPE: Cropping an Image 146

INTERMEDIATE RECIPE: Animating a Sprite Map 147

Canvas Transformations 150

ADVANCED RECIPE: Animating an Image 151

ADVANCED RECIPE: Animating a Vertical Bar Chart 155

Summary 162

Chapter 7: Embedding Video with HTML5 163

BEGINNER RECIPE: Including Video with the video Element 163

INTERMEDIATE RECIPE: Enabling Video for All Browsers 166

INTERMEDIATE RECIPE: Creating a Video with Subtitles and Captions 173

The Media API 177

ADVANCED RECIPE: Making Your Own Custom Controls 178

Summary 186

Chapter 8: Embedding Audio with HTML5 187

BEGINNER RECIPE: Including Audio with the audio Element 187

INTERMEDIATE RECIPE: Enabling Audio for All Browsers 188

New Audio Attributes 190

The Media API 192

INTERMEDIATE RECIPE: Creating a Beat Mixer 193

ADVANCED RECIPE: Adding Streaming Radio 197

Summary 206

Chapter 9: Changing Browser History 207

History Basics 207

BEGINNER RECIPE: Adding to History with pushState 208

BEGINNER RECIPE: Creating an Image Viewer 211

INTERMEDIATE RECIPE: Popping State in the Image Viewer 214

BEGINNER RECIPE: Changing History with replaceState 216

INTERMEDIATE RECIPE: Changing the Page History 218

ADVANCED RECIPE: Using Advanced State Data Objects to Pass Information Across Pages 221

INTERMEDIATE RECIPE: Testing History Security 225

Helpful Libraries 228

Summary 228

Chapter 10: Location Awareness with the Geolocation API 231

Geolocation Overview 231

BEGINNER RECIPE: Determining Your Location with a Simple getCurrentPosition 233

INTERMEDIATE RECIPE: Mapping a Location with getCurrentPosition 237

INTERMEDIATE RECIPE: Determining Distance with PositionOptions 243

ADVANCED RECIPE: Following a Moving Location with watchPosition 250

Summary 257

Chapter 11: Client-Side Storage 259

Client-Side Storage Overview 259

BEGINNER RECIPE: Getting and Setting Session Storage 263

BEGINNER RECIPE: Styling from Session Storage 266

INTERMEDIATE RECIPE: Storing Forms with Local Storage 271

ADVANCED RECIPE: Catching Events in Local Storage 275

Web SQL Database API 283

ADVANCED RECIPE: Using a Web Database for a Grocery List 286

Summary 295

Chapter 12: Communication and Threading 297

WebSocket API Overview 297

BEGINNER RECIPE: Talking Through Web Sockets 299

Threading Through Web Workers 302

BEGINNER RECIPE: Creating a Web Worker 304

INTERMEDIATE RECIPE: Adding Two-Way Communication 308

ADVANCED RECIPE: Leveraging a Shared Web Worker 311

Summary 318

Chapter 13: Browser Experience in HTML5 319

Drag and Drop API 319

BEGINNER RECIPE: Dragging and Dropping Across divs 321

ADVANCED RECIPE: Leveraging Events and dataTransfer 325

Application Cache and API 334

BEGINNER RECIPE: Creating a Manifest File 335

BEGINNER RECIPE: Using Web Pages Offline 337

Application Cache API 340

Notification API 341

BEGINNER RECIPE: Displaying a Simple Notification 344

ADVANCED RECIPE: Creating a Tweet Notification Page 348

Summary 357

Chapter 14: Working with Local Files 359

File API Overview 359

BEGINNER RECIPE: Getting File Attributes 360

BEGINNER RECIPE: Processing Multiple Files with Drag and Drop 362

The FileReader Interface 367

INTERMEDIATE RECIPE: Previewing Images Through readAsDataURL 368

ADVANCED RECIPE: Parsing a CSV File with readAsText 373

File API Extended Specifications 381

ADVANCED RECIPE: Creating a Local File 382

Summary 388

Chapter 15: Integrating Device Data 389

Brief Device APIs History 389

Contacts API 391

BEGINNER RECIPE: Retrieving All Contacts and Mobile Numbers 393

Messaging API 396

Network Information API 397

Battery Status Events 398

HTML Media Capture 398

INTERMEDIATE RECIPE: Capturing Pictures with File Input 399

Device Orientation and Motion Events 403

INTERMEDIATE RECIPE: Creating a Bubble Level 404

Summary 409

Recipes 411

Index 415


Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020