




























































































Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Prepare-se para as provas
Estude fácil! Tem muito documento disponível na Docsity
Prepare-se para as provas com trabalhos de outros alunos como você, aqui na Docsity
Encontra documentos específicos para os exames da tua universidade
Prepare-se com as videoaulas e exercícios resolvidos criados a partir da grade da sua Universidade
Responda perguntas de provas passadas e avalie sua preparação.
Ganhe pontos para baixar
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
HTML5 Cookbook
Tipologia: Notas de estudo
1 / 284
Esta página não é visível na pré-visualização
Não perca as partes importantes!





























































































“The HTML5 Cookbook is brimming with recipes to show you what you can really do with HTML5, plus a soupçon of JavaScript. Fill your studio with the aroma of drawings, animations, geolocation, audio/video, form fields, and semantic elements.” — Helen Oliver, Research Assistant, Design Engineering Group at Imperial College London
“Great overview of the most important HTML5 technologies, with tons of code to match it! An everyday companion for your developing needs.” — Robert Nyman, Technical Evangelist, Mozilla
“The HTML5 Cookbook is not only a fantastic resource for creative problem solving with HTML5, it is also a great learning tool. There’s no easier way to get familiar with a new (or updated) language than by combing through useful examples---something this book is just chock full of.” — Aaron Gustafson, author of Adaptive Web Design: Crafting Rich Experiences with Progressive Enhancement
Christopher Schmitt and Kyle Simpson
Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo
v
vi | Table of Contents
viii | Table of Contents
Preface
We know you want to learn about all the wonderful and exciting developments that come with HTML5, like web forms, canvas, and local storage. But we also know the importance of establishing a good foundation for advanced development. Let’s first put HTML5 into a bit of context.
What Is HTML5?
HTML5 is a specification (see http://dev.w3.org/html5/spec/ ) under development by the World Wide Web Consortium (W3C). As we write this book, the HTML5 specification is officially a Working Draft , which means it may go through additional revisions before becoming a recommendation. The recommendation will then go through a formal approval process, resulting in a specific version of the markup language.
Meanwhile, independent from the W3C, the Web Hypertext Application Technology Working Group (WHATWG) also pursues development of the HTML specification (see http://whatwg.org/html ).
Notice I didn’t mention a version number. That’s because the WHATWG recently decided to change tack and drop versioning entirely. A “living standard” is now how WHATWG defines HTML (see http://blog.whatwg.org/html-is-the-new-html5 ). This new development model means that HTML is defined according to how it’s evolving, not as a version tied to features in a “snapshot” of time.
Feature Support, Not Browser Versions
What does this mean for us designers and developers? It could lead to a greater focus on implementing individual features, rather than a full specification: no more “this is an HTML5 site,” but instead “this site features web sockets and geolocation.”
Then again, some in the industry argue that designers and developers need stable spec- ifications to refer to in order to validate and maintain their sites effectively. Plus, having a stable “what is true now” version makes authoring and teaching more manageable.
ix
What’s in This Book
While we may not provide a full list of all the features of HTML5 and browser support for them—depending on the recipe—we do discuss the support for each of the indi- vidual elements and implementations covered throughout this book (for tips on finding out what browsers currently support what parts of the specification, see Recipe 2.3, “Understanding Browser Support for HTML5”).
We also cover workarounds to implement when browser support is patchy, and why you may or may not need them. This way, you can decide for yourself if a particular feature works for you, your client, or your employer.
And that’s our value to you, dear reader. Using HTML5 isn’t an absolute proposition. You don’t have to use embedded content or web sockets to use the new structural elements, and vice versa. You don’t even have to use the new structural elements to have a valid HTML5 document; you just need the Document Type Definition.
If you find yourself asking “what’s a Document Type Definition?,” start your adventure into HTML5 by checking out Recipe 1.1, “Specifying the DOCTYPE”!
Pick what works for you and leave the rest. Or, rather, experiment with the rest to see if you may find a practical implementation for yourself or your projects.
Our industry is like HTML in a lot of ways, and probably always will be: it’s constantly changing.
And we, as the good web designers and developers that we are, have to continue staying on top of those latest changes and developments. We have to continue to educate our clients and employers about the benefits and compromises. We have to experiment with moving targets and constantly grow our skills.
Honestly, though, that all sounds pretty good to us. So, let’s start coding some HTML5, shall we?
Audience
While it would probably suffice to say that this book is for any person interested in learning about HTML5, it was particularly designed and developed for web developers who want to transition from XHTML or HTML4 into new technologies.
The chapters toward the end of the book are geared more for developers who want to utilize some of the JavaScript APIs found in HTML5.
Preface | xi
Assumptions This Book Makes
You don’t want a rundown of the HTML5 specification. Rather, you want to make things work as they relate to your job. In each of this book’s recipes, the Solution gives you the quick and dirty answer to the problem presented. Check out the Discussion for greater coverage.
You could start from the beginning of the book and make your way through it in a linear fashion without feeling lost. With one or two exceptions, the chapters’ recipes are set up so that they build off of each other. One of the great things about the books in the Cookbook series, though, is that they’re here to help you out when you find yourself with a specific problem—in this case, an HTML5-related problem. Simply crack open the book or the ebook on your tablet and find the right recipe for a practical, usable solution.
And one more thing: we assume that geolocation will forever be linked to HTML5. Even though we know, yes, that W3C Geolocation API Working Draft is separate from the HTML5 specification. That hasn’t stopped people from writing blog posts, tutorials, and even books about putting geolocation into the same conversation as HTML5. And since it’s such a great, serviceable API right now, we felt we had to include it in a book about HTML5 (see Chapter 8). If it troubles you, think of Geolocation and other technologies as “HTML5 and friends.” However, this book probably isn’t for you if you require hyper-technical hierarchies to be adhered to in order to obtain practical knowledge.
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic Indicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.
Constant width bold Shows commands or other text that should be typed literally by the user.
Constant width italic Shows text that should be replaced with user-supplied values or by values deter- mined by context.
xii | Preface
How to Contact Us
Please address comments and questions concerning this book to the publisher:
O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax)
We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:
http://shop.oreilly.com/product/0636920016038.do
To comment or ask technical questions about this book, send email to:
For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia
Acknowledgments
We can’t see it, but time is an invisible dimension that surrounds us all.
Yet time is so very interesting in that it can be marked so well.
For instance, it can be marked by the due dates and deadlines of which a book of this sort is composed. So many, many deadlines.
When writing a book, for example, there is a deadline for the original manuscript.
Then there are the changes to the manuscript provided by many talented people like editors, technical editors, copyeditors, artists, designers, and so on.
They each give writers their deadlines, marking time.
Editorial deadline, technical edits deadline, copyedits deadline, art deadline, and so on.
Deadlines upon deadlines as time is.
Then there is another way time is marked.
The time away from loved ones.
xiv | Preface
After writing several books, I now know that writing a book is a Herculean task in that it keeps time away from other activities, like fun and family—something I wouldn’t wish on anyone.
But then friends aren’t just anyone, right?
Along with my co-lead author, Kyle Simpson, I congratulate and thank the contributors to the HTML5 Cookbook : Emily Lewis, Kimberly Blessing, Christina Huggins Ramey, Anitra Pavka, Marc Grabanski, and Christopher Deustch.
Thanks to our technical editors, Shelley Powers, Ben Henick, Dusty Jewett, Molly Holzschlag, and Helen Oliver, who diligently kept us on our toes.
Our copyeditor, Rachel Head, is a miracle worker, making our respective families proud by making them think we all are better writers than we probably are.
Many, many thanks to editors Simon St. Laurent and Courtney Nash from O’Reilly, who helped me stay sane during our time on this book.
Every once in a while I tried to count up how many total years of web development experience were brought to this project by all the talented writers and editors who contributed, but I got a bit too exhausted just thinking about it.
I’m not sure if all these talented, beautiful people knew what they signed up for when I first talked to them about the HTML5 Cookbook , but I’m happy with what we were able to make together. And I thank them for that.
Finally, thanks to my family and loved ones who have been there for me throughout my obsession with web design and development. Let’s continue to share good times together.
Christopher Schmitt http://christopherschmitt.com http://twitter.com/@teleject
I would like to thank my wonderful and patient wife, Christen, for letting me be part of this project. I also want to thank my parents for their support and encouragement in all my various endeavors. Lastly, to my new son, Ethan, I hope someday you are happily coding along in HTML12 and you get to look back on this old HTML5 book with nostalgia. Just remember, I had to walk to school in the snow, uphill, both ways...
Kyle Simpson http://blog.getify.com http://twitter.com/@getify
Preface | xv
I’d also like to thank all of the other wonderful people I’ve met at web conferences and networking events over the years. You are too many to name. Y’all inspire me to learn and laugh.
Thank you, Mom and Dad, for… well, everything.
I also want to thank our readers— you —for caring enough about your art to hone your skills. Your curiosity, knowledge, and empathy will advance the Web.
Anitra Pavka http://anitrapavka.com http://twitter.com/@apavka
A hearty thanks to Christopher Schmitt for continually providing me with opportuni- ties for expanding my knowledge of web design. You’ve pushed me to develop my writing and coding skills far beyond my modest ambitions.
Thank you, my sweet husband, Paul Ramey, for providing support and patience while I research, code, and write. And thank you for providing welcome distractions when I’ve worked too long!
Christina Huggins Ramey http://www.christinaramey.me http://twitter.com/@fidlet
Thanks to Christopher Deutsch for taking the geolocation chapter content ideas and running with them.
Marc Grabanski http://marcgrabanski.com http://twitter.com/@1Marc
Preface | xvii