HTML HThe TML Covers The HTML5 elements in depth Pocket Guide T h e H Here is your essential companion to HTML. The HTML Pocket Guide is a T Pocket valuable companion to creating standards-compliant markup that will help M Guide Web designers and developers quickly defi ne content and meaning. The HTML Pocket Guide: L ■ Covers all elements in HTML 4, XHTML 1, and HTML5. P ■ Teaches you when—and explains why and how—to use each element o and attribute. c k ■ Provides code examples that demonstrate common uses and best practices. e ■ Shows how to build lean, semantic, accessible markup. t G ■ Details the changes in HTML5 to X/HTML elements it inherits. u ■ Notes deprecated or obsolete elements and attributes and what to i d use instead. e ■ Tells you how to start using HTML5 today. Plus, visit the support site at www.htmlfi ver.com/html-pocket-guide/ for additional coverage, code examples, HTML templates you may use, and more. BOOK LEVEL Computer Book Shelf Category: HTML beginning Covers: Elements and attributes in HTML 4, XHTML 1, and HTML5 intermediate advanced US $14.99 CAN $17.99 ISBN-13: 978-0-321-69974-9 ISBN-10: 0-321-69974-2 Hyslop 5 1 4 9 9 Bruce Hyslop Peachpit Press 9 780321 699749 Ginormous knowledge, pocket-sized. www.peachpit.com Cover Design: Peachpit Press WHERE ARE THE LESSON FILES? Thank you for purchasing this digital version of: The print version of this title comes with a disc of lesson fi les. As an eBook reader, you have access to these fi les by following the steps below: 1. On your PC or Mac, open a web browser and go to this URL: 2. Download the ZIP fi le (or fi les) from the web site to your hard drive. 3. Unzip the fi les and follow the directions for use in the Read Me included in the download. Please note that many of our lesson materials can be very large, especially image and video fi les. You will be able to see the size of any fi le for download once you reach the URL listed above. If you are unable to locate the fi les for this title by following the steps above, please email [email protected] and supply the URL from step one. Our customer service representatives will assist you as soon as possible. Legal Notice: Peachpit Press makes no warranty or representation, either express or implied, with respect to this software, its quality, performance, merchantability, or fi tness for a particular purpose. In no event will Peachpit Press, its distributors, or dealers be liable for direct, indirect, special, incidental or consequential dam- ages arising out of the use or inability to use the software. The exclusion of implied warranties is not permitted in some states. Therefore, the above exclusion may not apply to you. This warranty provides you with specifi c legal rights. There may be other rights that you may have that vary from state to state. The software and media fi les are copyrighted by the authors and Peachpit Press. You have the non-exclusive right to use these programs and fi les. You may use them on one computer at a time. You may not distribute the URL to third parties or redistribute the fi les over a network. You may transfer the fi les onto a single hard disk so long as you can prove ownership of this eBook. You may not reverse engineer, decompile, or disassemble the software or media fi les. You may not modify or translate the software or media, or distribute copies of the software or media without the written consent of Peachpit Press. The HTML PocketGuide BruceHyslop Ginormous knowledge, pocket-sized. The HTML Pocket Guide Bruce Hyslop Peachpit Press 1249 Eighth Street Berkeley, CA 94710 510/524-2178 510/524-2221 (fax) Find us on the Web at: www.peachpit.com To report errors, please send a note to: [email protected] Peachpit Press is a division of Pearson Education. Copyright © 2010 by Bruce Hyslop Executive Editor: Clifford Colby Editor: Kim Wimpsett Technical Editor: Michael Bester Production Editor: Tracey Croom Compositor: David Van Ness Indexer: James Minkin Cover Design: Peachpit Press Interior Design: Peachpit Press 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 [email protected]. 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 author 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 con- tained 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 prod- ucts 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-69974-9 ISBN-10: 0-321-69974-2 9 8 7 6 5 4 3 2 1 Printed and bound in the United States of America To Mom and Dad, and your nearly 45 years of marriage. To Merri, my birthday mate; you are greatly missed. About the Author Bruce Hyslop has 13 years of experience in Web development, with a focus on interface technical architecture and development. He is the senior director of the Interface Engineering Group (IEG) at Schematic, an interactive agency based in the United States. In this role, Bruce oversees companywide efforts to define and implement best practices regarding HTML, CSS, JavaScript, and accessibility wherever they may be applied: the browser, desktop, mobile devices, and emerging platforms. An early adopter of Web standards, Bruce has helmed IEG for more than 120 projects, including clients such as ABC, BBC, Dell, Logitech, Microsoft, NBC Universal, Nokia, and Target, among others. In addition to his develop- ment and writing efforts, Bruce teaches a CSS course at UCLA Extension. Acknowledgments First I’d like to say a very grateful thank you to Nancy Davis and Cliff Colby for the opportunity and for your continued patience and support, of which I’m very appreciative. A most sincere thank-you goes out to Nicole Neopolitan and Patrick Ty. I could not possibly have done this without your support. Thank you, Kim and Michael, for all your editing suggestions and improvements and for catching my errors. It was always very comforting to know you’d be reviewing my words with care and experienced eyes. Thank you, Charlene Will, Tracey Croom, Cory Borman, and David Van Ness, for taking great care in the design and being such a pleasure with which to work. Thank you, James Minkin, (from me and on behalf of our readers!) for indexing the content . Thank you, everyone at Peachpit with whom I didn’t have an opportunity to work with directly but who contributed to the book’s efforts and will continue to do so. Thank you to my fellow IEGers at Schematic for their continued inspira- tion, and to Michael Roldan, Tommy Ly, Karen Lauritsen, Scott Hutchinson, and Robert Reinhardt. Last, but certainly not least, a special acknowledgment to those of you who were particularly neglected while I wrote this. You often inspired me in quiet but profound ways. I have a lot of catching up to do! Contents Introduction........................................................vii Part 1: HTML Basics.............................................1 Chapter 1: HTML Basics .............................................3 Part 2: HTML Elements and Guidance .................25 Chapter 2: Primary Structure and Sections ....................27 Chapter 3: Document Head . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43 Chapter 4: Lists....................................................69 Chapter 5: Text ....................................................93 Chapter 6: Embedded Content (Images and Objects) ....... 141 Chapter 7: Forms .................................................157 Chapter 8: Tabular Data.........................................185 Chapter 9: Scripting .............................................203 Chapter 10: Frames...............................................213 vi The HTML Pocket Guide Part 3: HTML5 Elements and Guidance.............. 221 Chapter 11: Primary Structure and Sections...................223 Chapter 12: Text ..................................................245 Chapter 13: E mbedded Content (Images, Media, and More)........................263 Chapter 14: Forms................................................277 Chapter 15: Interactive Elements...............................285 Appendix: Alphabetical HTML Elements Page Listing.......294 Index ..............................................................296 The HTML Pocket Guide Introduction Welcome to the HTML Pocket Guide! I’m excited you’re here. HTML—the humble markup language that helped spur a new era of information sharing two decades ago—is hotter than ever today with the emergence of HTML5. So, now is a great time to either learn about HTML for the first time or be sure you’re on top of the latest developments. In this introduction, I summarize what you can expect to learn, whom the book targets, how information is presented, and where you can learn more. viii The HTML Pocket Guide What You Will Learn The focus of this book is to help you learn about n Elements and attributes in HTML 4, XHTML 1, and HTML5 n Differences between these HTML versions n Current Web standards–based best practices regarding HTML usage n What to use instead of deprecated attributes Who This Book Is For This book is suitable for developers and designers of all skill levels who want to learn about HTML and for those who want a handy, informative HTML reference at the ready. Those of you who have X/HTML down pat will be interested in its detailed coverage of all the HTML5 elements. How to Read This Book This book is structured to allow you to read it either sequentially (espe- cially Parts 2 and 3) or jump to a particular topic for quick access to specific answers. The book has three parts: n Part 1 covers an HTML5 overview, HTML fundamentals, and common attributes and data types referred to by Parts 2 and 3. n Part 2 provides in-depth coverage of all HTML elements and their attri- butes except those unique to HTML5. It also explains differences for some of these elements when used in HTML5. All of this information is in a reference-style format that includes code examples and explana- tions concerning how and when to use the elements and attributes. n Part 3 has the same format, except it focuses on elements unique to HTML5. In that sense, it’s like a book within the book, which is espe- cially convenient if your main goal is to get up to speed on the new elements in HTML5.