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.
  • </code></strong>: Specifies the title of the document.</li></ul> <h2>Text Elements</h2> <p>HTML provides various tags for structuring text content:</p> <ul><li><strong><code><h1></code> to <code><h6></code></strong>: Headings, with <code><h1></code> as the most important.</li><li><strong><code><p></code></strong>: Paragraph.</li><li><strong><code><br></code></strong>: Line break.</li><li><strong><code><hr></code></strong>: Thematic break (horizontal rule).</li><li><strong><code><strong></code></strong>: Important text (bold).</li><li><strong><code><em></code></strong>: Emphasized text (italic).</li><li><strong><code><small></code></strong>: Smaller text.</li><li><strong><code><mark></code></strong>: Highlighted text.</li><li><strong><code><blockquote></code></strong>: Long quotations.</li><li><strong><code><code></code></strong>: Inline code.</li><li><strong><code><pre></code></strong>: Preformatted text (preserves whitespace).</li></ul> <h2>Lists</h2> <p>HTML supports ordered, unordered, and description lists:</p> <ul><li><strong><code><ul></code></strong>: Unordered list.</li></ul> <pre><code class="language-html"> <ul> <li>Item 1</li> <li>Item 2</li> </ul> </code></pre> <ul><li><strong><code><ol></code></strong>: Ordered list.</li></ul> <pre><code class="language-html"> <ol> <li>First Item</li> <li>Second Item</li> </ol> </code></pre> <ul><li><strong><code><dl></code></strong>: Description list.</li></ul> <pre><code class="language-html"> <dl> <dt>Term 1</dt> <dd>Description for Term 1</dd> </dl> </code></pre> <h2>Links and Images</h2> <ul><li><strong><code><a href="URL"></code></strong>: Anchor tag for hyperlinks.</li></ul> <pre><code class="language-html"> <a href="https://www.example.com" target="_blank" rel="noopener noreferrer">Visit Example</a> </code></pre> <ul><li><strong><code><img src="image.jpg" alt="Description"></code></strong>: Embeds an image.</li></ul> <pre><code class="language-html"> <img src="image.jpg" alt="Description" width="200" height="150"> </code></pre> <h2>Tables</h2> <p>HTML tables consist of rows and columns:</p> <pre><code class="language-html"> <table> <thead> <tr> <th>Header 1</th> <th>Header 2</th> </tr> </thead> <tbody> <tr> <td>Data 1</td> <td>Data 2</td> </tr> </tbody> </table> </code></pre> <h2>Forms</h2> <p>HTML5 introduces new input types and attributes:</p> <pre><code class="language-html"> <form action="/submit" method="post"> <label for="name">Name:</label> <input type="text" id="name" name="name" required> <label for="email">Email:</label> <input type="email" id="email" name="email" required> <label for="dob">Date of Birth:</label> <input type="date" id="dob" name="dob"> <label for="message">Message:</label> <textarea id="message" name="message" rows="4" cols="50"></textarea> <button type="submit">Submit</button> </form> </code></pre> <h3>Common Input Types</h3> <ul><li><strong><code>text</code></strong>: Single-line text input.</li><li><strong><code>email</code></strong>: Validated email address.</li><li><strong><code>password</code></strong>: Password input (masked).</li><li><strong><code>number</code></strong>: Numeric input.</li><li><strong><code>date</code></strong>: Date picker.</li><li><strong><code>radio</code></strong>: Single-choice options.</li><li><strong><code>checkbox</code></strong>: Multiple-choice options.</li><li><strong><code>file</code></strong>: File upload.</li></ul> <h2>Semantic Elements</h2> <p>HTML5 introduces semantic elements to improve document structure and accessibility:</p> <ul><li><strong><code><header></code></strong>: Introductory content or navigation links.</li><li><strong><code><nav></code></strong>: Navigation links.</li><li><strong><code><main></code></strong>: Main content of the document.</li><li><strong><code><section></code></strong>: Thematic grouping of content.</li><li><strong><code><article></code></strong>: Independent content (e.g., blog post).</li><li><strong><code><aside></code></strong>: Sidebar content.</li><li><strong><code><footer></code></strong>: Footer content.</li><li><strong><code><figure></code></strong>: Self-contained content, like images with captions.</li><li><strong><code><figcaption></code></strong>: Caption for a <code><figure></code>.</li></ul> <h2>Multimedia</h2> <p>HTML5 supports native multimedia embedding:</p> <ul><li><strong><code><video></code></strong>: Embeds a video.</li></ul> <pre><code class="language-html"> <video width="320" height="240" controls> <source src="movie.mp4" type="video/mp4"> Your browser does not support the video tag. </video> </code></pre> <ul><li><strong><code><audio></code></strong>: Embeds an audio file.</li></ul> <pre><code class="language-html"> <audio controls> <source src="audio.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio> </code></pre> <h2>Inline vs. Block Elements</h2> <ul><li><strong>Inline Elements</strong>: Do not start on a new line and only take up as much width as necessary. Examples include <code><span></code>, <code><a></code>, <code><em></code>, <code><strong></code>.</li><li><strong>Block Elements</strong>: Start on a new line and take up the full width available. Examples include <code><div></code>, <code><p></code>, <code><h1></code>, <code><ul></code>, <code><table></code>.</li></ul> <h2>Accessibility Best Practices</h2> <ul><li>Use semantic elements for better structure and SEO.</li><li>Ensure all images have descriptive alt attributes.</li><li>Use <code>aria-*</code> attributes to improve accessibility where necessary.</li><li>Ensure proper use of heading levels for a clear document outline.</li><li>Use <code><label></code> elements with form controls for better usability.</li></ul> <h2>Additional HTML5 Features</h2> <ul><li><strong>Data Attributes</strong>: Custom attributes prefixed with <code>data-</code>, e.g., <code><div data-info="123"></code>.</li><li><strong>Local Storage</strong>: Use the <code>localStorage</code> API for client-side data storage.</li><li><strong>Geolocation API</strong>: Retrieve geographic location data of the user.</li><li><strong>Drag and Drop</strong>: Built-in drag and drop functionality for elements.</li></ul> <p>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.</p> </div> </article> </main> </div> </div> </body> </html>