Basic Document Structure
Every HTML5 document begins with a declaration to ensure standards-compliant rendering. Here's the basic skeleton of an HTML5 document:
Document Title
Key Elements
: Declares the document as HTML5.: The root element with the language attribute.: Contains metadata, links to stylesheets, and the document title.: Sets the character encoding to UTF-8.: Ensures proper scaling on mobile devices.: Specifies the title of the document.
Text Elements
HTML provides various tags for structuring text content:
to: Headings, withas the most important.: Paragraph.: Line break.: Thematic break (horizontal rule).: Important text (bold).: Emphasized text (italic).: Smaller text.: Highlighted text.: Long quotations.: Inline code.: Preformatted text (preserves whitespace).
Lists
HTML supports ordered, unordered, and description lists:
: Unordered list.
- Item 1
- Item 2
: Ordered list.
- First Item
- Second Item
: Description list.
- Term 1
- Description for Term 1
Links and Images
Visit Example
: Embeds an image.
Tables
HTML tables consist of rows and columns:
Header 1
Header 2
Data 1
Data 2
Forms
HTML5 introduces new input types and attributes:
Common Input Types
text: Single-line text input.email: Validated email address.password: Password input (masked).number: Numeric input.date: Date picker.radio: Single-choice options.checkbox: Multiple-choice options.file: File upload.
Semantic Elements
HTML5 introduces semantic elements to improve document structure and accessibility:
: Introductory content or navigation links.: Navigation links.: Main content of the document.: Thematic grouping of content.: Independent content (e.g., blog post).: Sidebar content.: Footer content.: Self-contained content, like images with captions.: Caption for a.
Multimedia
HTML5 supports native multimedia embedding:
: Embeds a video.
: Embeds an audio file.
Inline vs. Block Elements
- Inline Elements: Do not start on a new line and only take up as much width as necessary. Examples include
,,,. - Block Elements: Start on a new line and take up the full width available. Examples include ,
,,,.
Accessibility Best Practices
- Use semantic elements for better structure and SEO.
- Ensure all images have descriptive alt attributes.
- Use
aria-*attributes to improve accessibility where necessary. - Ensure proper use of heading levels for a clear document outline.
- Use
elements with form controls for better usability.
Additional HTML5 Features
- Data Attributes: Custom attributes prefixed with
data-, e.g.,.- Local Storage: Use the
localStorageAPI for client-side data storage.- Geolocation API: Retrieve geographic location data of the user.
- Drag and Drop: Built-in drag and drop functionality for elements.
This cheat sheet provides a quick overview of the essential components and best practices in HTML5. For further learning, you can refer to detailed documentation on each feature and tag to master HTML5 in-depth.
- Local Storage: Use the