Full Stack Learning Hub

Comprehensive guides, cheat sheets, and code examples for full stack development.

View on GitHub

HTML5 Cheat Sheet

HTML (HyperText Markup Language) is the standard markup language for creating web pages. It describes the structure of a Web page.


1. Basic Structure (Boilerplate)

Every HTML document should follow this boilerplate structure, which includes essential metadata for responsiveness and character encoding.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Page Title</title>
    <!-- Link to external CSS stylesheets -->
    <link rel="stylesheet" href="styles/main.css">
    <!-- Link to external JavaScript files -->
    <script src="scripts/main.js" defer></script>
</head>
<body>
    <!-- Content goes here -->
</body>
</html>

2. Document Head (<head>) Elements

These elements provide metadata about the document and link to external resources.

3. Common Tags & Semantic Elements

HTML5 introduced several semantic elements that clearly describe their meaning to both the browser and the developer, improving accessibility and SEO.

Text Formatting

Semantic Sectioning Elements

These elements help define the structure and hierarchy of your web page.

Lists

Unordered List (<ul> - Bullet points)

<ul>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
</ul>

Ordered List (<ol> - Numbered list)

<ol>
    <li>First Item</li>
    <li>Second Item</li>
    <li>Third Item</li>
</ol>

Description List (<dl> - Key-value pairs)

<dl>
    <dt>Coffee</dt>
    <dd>Black hot drink</dd>
    <dt>Milk</dt>
    <dd>White cold drink</dd>
</dl>

Anchor Tag (<a> - Hyperlinks)

<a href="https://www.google.com" target="_blank" title="Go to Google">Go to Google</a>
<!-- `target="_blank"` opens the link in a new tab -->
<!-- `title` provides a tooltip on hover -->

Image Tag (<img>)

<img src="images/profile.jpg" alt="Description of image" width="300" height="200">
<!-- `alt` is crucial for accessibility and SEO -->
<!-- `width` and `height` provide intrinsic sizing, reducing layout shifts -->

4. Tables

Tables are used to display tabular data.

<table>
    <caption>Monthly Sales Report</caption>
    <thead>
        <tr>
            <th>Month</th>
            <th>Sales</th>
            <th>Profit</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>January</td>
            <td>$1000</td>
            <td>$300</td>
        </tr>
        <tr>
            <td>February</td>
            <td>$1200</td>
            <td>$350</td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td>Total</td>
            <td>$2200</td>
            <td>$650</td>
        </tr>
    </tfoot>
</table>

5. Forms (<form>)

Forms are used to collect user input.

<form action="/submit-data" method="POST">
    <fieldset>
        <legend>Personal Information</legend>

        <!-- Text Input -->
        <label for="firstName">First Name:</label>
        <input type="text" id="firstName" name="first_name" required placeholder="Enter your first name">

        <!-- Email Input -->
        <label for="userEmail">Email:</label>
        <input type="email" id="userEmail" name="email" required>

        <!-- Password Input -->
        <label for="userPwd">Password:</label>
        <input type="password" id="userPwd" name="password" minlength="8">
    </fieldset>

    <fieldset>
        <legend>Preferences</legend>

        <!-- Radio Buttons -->
        <p>Preferred Contact Method:</p>
        <input type="radio" id="contactEmail" name="contact_method" value="email" checked>
        <label for="contactEmail">Email</label><br>
        <input type="radio" id="contactPhone" name="contact_method" value="phone">
        <label for="contactPhone">Phone</label>

        <!-- Checkbox -->
        <input type="checkbox" id="newsletter" name="subscribe_newsletter" checked>
        <label for="newsletter">Subscribe to newsletter</label>

        <!-- Dropdown (Select) -->
        <label for="country">Country:</label>
        <select id="country" name="country">
            <option value="">--Please choose an option--</option>
            <option value="usa">United States</option>
            <option value="can">Canada</option>
            <option value="mex">Mexico</option>
        </select>

        <!-- Textarea -->
        <label for="comments">Comments:</label>
        <textarea id="comments" name="comments" rows="4" cols="50" placeholder="Your comments here..."></textarea>
    </fieldset>

    <!-- Buttons -->
    <button type="submit">Submit Information</button>
    <button type="reset">Reset Form</button>
</form>

6. Attributes

Attributes provide additional information about HTML elements.


6. Advanced HTML5 & Semantics

Semantic HTML conveys meaning to both the browser and the developer, improving accessibility and SEO.

Semantic Structure Elements

Tag Description
<header> Introductory content, typically containing navigation or logos.
<nav> A section of navigation links.
<main> The dominant content of the <body>. Unique to the page.
<section> A thematic grouping of content, usually with a heading.
<article> Independent, self-contained content (e.g., blog post, news item).
<aside> Content tangentially related to the main content (sidebar).
<footer> Footer for a section or page (copyright, contacts).
<body>
  <header>
    <nav>
      <a href="#home">Home</a>
      <a href="#about">About</a>
    </nav>
  </header>
  
  <main>
    <article>
      <h2>Blog Post Title</h2>
      <p>Content goes here...</p>
    </article>
    
    <aside>
      <h3>Related Links</h3>
      <ul>...</ul>
    </aside>
  </main>
  
  <footer>
    <p>&copy; 2025 Company Name</p>
  </footer>
</body>

Advanced Forms

Grouping related form data makes complex forms easier to manage and understand.

<form>
  <fieldset>
    <legend>Personal Information</legend>
    
    <label for="browser">Choose a browser:</label>
    <input list="browsers" name="browser" id="browser">
    
    <datalist id="browsers">
      <option value="Chrome">
      <option value="Firefox">
      <option value="Safari">
      <option value="Edge">
    </datalist>
  </fieldset>
</form>

See Also