HTML Cheat Sheet

Use this HTML cheat sheet as a quick reference for common tags, attributes, page structure, forms, tables, media, and semantic elements.

Basic HTML Page Template

<!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>
</head>
<body>
    <h1>Hello, HTML</h1>
    <p>This is a basic HTML page.</p>
</body>
</html>

Core Document Tags

<!DOCTYPE html>

Defines the document as HTML5.

<!DOCTYPE html>

<html>

The root element of the page.

<html lang="en">

<head>

Holds metadata, the page title, CSS links, and other information that does not appear as main page content.

<head>
    <title>My Page</title>
</head>

<body>

Holds the visible content of the page.

<body>
    <h1>Welcome</h1>
</body>

<title>

Sets the browser tab title.

<title>My Page</title>

<meta>

Adds metadata such as character encoding, description, and viewport settings.

<meta charset="UTF-8">

<link>

Links external files, most often CSS files.

<link rel="stylesheet" href="style.css">

<script>

Adds JavaScript to the page.

<script src="app.js"></script>

Head Metadata

<head>
    <meta charset="UTF-8">
    <meta name="description" content="A beginner-friendly HTML page.">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML Cheat Sheet</title>
    <link rel="stylesheet" href="styles.css">
</head>

Useful Metadata

  • charset="UTF-8" supports common characters and symbols.
  • name="description" adds a search-friendly page summary.
  • name="viewport" helps pages display properly on mobile devices.
  • <title> sets the browser tab title and often appears in search results.
  • <link rel="stylesheet"> connects a CSS file.

Headings

Use headings to structure content, not just to make text larger.

<h1>Main page heading</h1>
<h2>Section heading</h2>
<h3>Subsection heading</h3>
<h4>Smaller subsection</h4>
<h5>Minor heading</h5>
<h6>Smallest heading</h6>

Heading Uses

  • <h1> is the main page heading, usually one per page.
  • <h2> marks main sections.
  • <h3> marks subsections inside H2 sections.
  • <h4> to <h6> create deeper content levels.

Text Tags

Paragraph

<p>This is a paragraph.</p>

Important Text

<strong>This text is important.</strong>

Emphasized Text

<em>This text is emphasized.</em>

Small Text

<small>This is small supporting text.</small>

Highlighted Text

<mark>This text is highlighted.</mark>

Line Break

<p>First line<br>Second line</p>

Thematic Break

<hr>

Links

Basic Link

<a href="https://example.com">Visit Example</a>

Open Link in a New Tab

<a href="https://example.com" target="_blank" rel="noopener">
    Open Example
</a>

Link to Another Page

<a href="about.html">About</a>

Email Link

<a href="mailto:hello@example.com">Email us</a>

Phone Link

<a href="tel:+123456789">Call us</a>

Useful Link Attributes

  • href sets the destination.
  • target="_blank" opens the link in a new tab.
  • rel="noopener" improves new-tab security.
  • mailto: opens an email app.
  • tel: starts a phone call on supported devices.

Images

Basic Image

<img src="images/profile.jpg" alt="Profile photo of Alex">

Image with Width and Height

<img
    src="images/product.jpg"
    alt="Blue running shoes"
    width="400"
    height="300"
>

Decorative Image

<img src="images/divider.png" alt="">

Lazy-Loaded Image

<img src="images/course.jpg" alt="Person coding on a laptop" loading="lazy">

Useful Image Attributes

  • src sets the image file path or URL.
  • alt describes the image.
  • width sets the image width.
  • height sets the image height.
  • loading="lazy" delays loading until the image is needed.

Lists

Unordered List

<ul>
    <li>HTML</li>
    <li>CSS</li>
    <li>JavaScript</li>
</ul>

Ordered List

<ol>
    <li>Create a file</li>
    <li>Add HTML</li>
    <li>Open it in a browser</li>
</ol>

Description List

<dl>
    <dt>HTML</dt>
    <dd>The markup language used to structure web pages.</dd>

    <dt>CSS</dt>
    <dd>The language used to style web pages.</dd>
</dl>

List Tags

  • <ul> creates an unordered list.
  • <ol> creates an ordered list.
  • <li> creates a list item.
  • <dl> creates a description list.
  • <dt> marks a term.
  • <dd> marks a description.

Semantic Layout Tags

<header>
    <h1>Website Name</h1>
</header>

<nav>
    <a href="/">Home</a>
    <a href="/about.html">About</a>
    <a href="/contact.html">Contact</a>
</nav>

<main>
    <section>
        <h2>Featured Courses</h2>
        <p>Start learning web development today.</p>
    </section>
</main>

<footer>
    <p>&copy; 2026 Website Name</p>
</footer>

Common Semantic Tags

  • <header> contains introductory page or section content.
  • <nav> contains navigation links.
  • <main> contains the main page content.
  • <section> groups related content.
  • <article> marks standalone content, such as a blog post.
  • <aside> contains related side content.
  • <footer> contains footer content.
  • <div> is a generic container with no semantic meaning.

Articles, Sections, and Divs

Article

Use <article> for content that can stand alone.

<article>
    <h2>What Is HTML?</h2>
    <p>HTML structures content on the web.</p>
</article>

Section

Use <section> for grouped content inside a page.

<section>
    <h2>Course Benefits</h2>
    <p>Learn by building practical projects.</p>
</section>

Div

Use <div> when no meaningful semantic tag fits.

<div class="card">
    <h2>HTML Basics</h2>
    <p>Learn the structure of web pages.</p>
</div>

Forms

Basic Form

<form action="/submit" method="post">
    <label for="email">Email</label>
    <input type="email" id="email" name="email">

    <button type="submit">Subscribe</button>
</form>

Form Tags

  • <form> wraps form fields.
  • <label> describes a form field.
  • <input> creates an input field.
  • <textarea> creates a multi-line text field.
  • <select> creates a dropdown.
  • <option> creates a dropdown option.
  • <button> creates a clickable button.
  • <fieldset> groups related fields.
  • <legend> adds a label for a field group.

Common Input Types

<input type="text" name="username">
<input type="email" name="email">
<input type="password" name="password">
<input type="number" name="age">
<input type="date" name="birthday">
<input type="checkbox" name="subscribe">
<input type="radio" name="plan" value="basic">
<input type="file" name="avatar">
<input type="submit" value="Send">

Input Type Uses

  • text creates a short text field.
  • email creates an email field.
  • password hides entered text.
  • number creates a number field.
  • date creates a date picker.
  • checkbox creates an on/off choice.
  • radio creates one choice from a group.
  • file creates a file upload field.
  • submit creates a submit control.

Useful Form Attributes

<input
    type="email"
    id="email"
    name="email"
    placeholder="you@example.com"
    required
>

Common Form Attributes

  • id connects an input to a label.
  • name identifies the submitted form value.
  • placeholder adds hint text inside the field.
  • required makes the field required.
  • value sets a default value.
  • disabled disables the field.
  • readonly makes the field read-only.
  • min sets a minimum value.
  • max sets a maximum value.
  • maxlength limits text length.

Textareas and Dropdowns

Textarea

<label for="message">Message</label>
<textarea id="message" name="message"></textarea>

Dropdown

<label for="language">Choose a language</label>
<select id="language" name="language">
    <option value="html">HTML</option>
    <option value="css">CSS</option>
    <option value="javascript">JavaScript</option>
</select>

Grouped Radio Buttons

<fieldset>
    <legend>Choose a plan</legend>

    <label>
        <input type="radio" name="plan" value="basic">
        Basic
    </label>

    <label>
        <input type="radio" name="plan" value="pro">
        Pro
    </label>
</fieldset>

Buttons

<button type="button">Click me</button>
<button type="submit">Submit</button>
<button type="reset">Reset</button>

Button Types

  • button creates a generic button.
  • submit submits a form.
  • reset resets form fields.

Use <button> for actions. Use <a> for navigation.

Tables

Use tables for structured data, not page layout.

<table>
    <caption>Team Members</caption>
    <thead>
        <tr>
            <th>Name</th>
            <th>Role</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Alex</td>
            <td>Developer</td>
        </tr>
        <tr>
            <td>Sam</td>
            <td>Designer</td>
        </tr>
    </tbody>
</table>

Table Tags

  • <table> creates a table.
  • <caption> adds a table title or description.
  • <thead> groups header rows.
  • <tbody> groups body rows.
  • <tfoot> groups footer rows.
  • <tr> creates a table row.
  • <th> creates a header cell.
  • <td> creates a data cell.

Audio and Video

Audio

<audio controls>
    <source src="audio/lesson.mp3" type="audio/mpeg">
    Your browser does not support the audio element.
</audio>

Video

<video controls width="640">
    <source src="videos/demo.mp4" type="video/mp4">
    Your browser does not support the video element.
</video>

Useful Media Attributes

  • controls shows browser playback controls.
  • autoplay starts playback automatically.
  • muted mutes audio.
  • loop repeats playback.
  • poster adds a preview image for video.
  • width sets the video width.

Embeds and Iframes

<iframe
    src="https://example.com"
    title="Example website"
    width="600"
    height="400">
</iframe>

Useful Iframe Attributes

  • src sets the embedded page URL.
  • title describes the iframe for accessibility.
  • width sets the frame width.
  • height sets the frame height.
  • loading="lazy" delays loading.

Lazy-Loaded Iframe

<iframe
    src="https://example.com"
    title="Example page"
    loading="lazy">
</iframe>

HTML Entities

Use entities for reserved characters and common symbols.

Common Entities

  • < is written as &lt;
  • > is written as &gt;
  • & is written as &amp;
  • " is written as &quot;
  • ' is written as &apos;
  • © is written as &copy;
  • ® is written as &reg;
  • € is written as &euro;
  • A non-breaking space is written as &nbsp;

Example:

<p>Use &lt;h1&gt; for the main heading.</p>

Global Attributes

Global attributes work on most HTML elements.

<p id="intro" class="lead" title="Intro text">Welcome to the page.</p>

Common Global Attributes

  • id creates a unique identifier.
  • class creates a reusable CSS or JavaScript hook.
  • style adds inline CSS.
  • title adds extra hover text.
  • hidden hides an element.
  • tabindex controls keyboard focus order.
  • data-* stores custom data.
  • aria-* adds accessibility information.

Custom Data Attribute

<button data-user-id="42">View Profile</button>

Accessibility Basics

Use Semantic HTML First

<button type="button">Open menu</button>

Avoid clickable <div> elements.

<div onclick="openMenu()">Open menu</div>

Better:

<button type="button" onclick="openMenu()">Open menu</button>

Label Form Fields

<label for="username">Username</label>
<input type="text" id="username" name="username">

Add Useful Alt Text

<img src="chart.png" alt="Chart showing monthly revenue growth">

Use Empty Alt Text for Decorative Images

<img src="decorative-line.png" alt="">

Comments

<!-- This is an HTML comment -->

Use comments to explain sections or temporary notes.

<!-- Main navigation -->
<nav>
    <a href="/">Home</a>
    <a href="/courses.html">Courses</a>
</nav>

Do not put private information in HTML comments. Users can view page source.

Connecting CSS

External CSS

<link rel="stylesheet" href="styles.css">

Internal CSS

<style>
    body {
        font-family: Arial, sans-serif;
    }
</style>

Inline CSS

<p style="color: blue;">Blue text</p>

External CSS is best for most projects because it keeps structure and styles separate.

Connecting JavaScript

External JavaScript

<script src="script.js"></script>

Inline JavaScript

<script>
    console.log("Page loaded");
</script>

Place scripts near the end of <body> when they depend on page elements.

<body>
    <button id="button">Click me</button>

    <script src="script.js"></script>
</body>

Common Page Pattern

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="description" content="A simple HTML page example.">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Course Landing Page</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <header>
        <h1>Learn HTML</h1>
        <p>Build the structure of web pages.</p>
    </header>

    <nav aria-label="Main navigation">
        <a href="/">Home</a>
        <a href="/courses.html">Courses</a>
        <a href="/contact.html">Contact</a>
    </nav>

    <main>
        <section>
            <h2>Featured Lesson</h2>
            <article>
                <h3>HTML Basics</h3>
                <p>Learn tags, attributes, and page structure.</p>
                <a href="/lessons/html-basics.html">Start lesson</a>
            </article>
        </section>

        <section>
            <h2>Subscribe</h2>
            <form action="/subscribe" method="post">
                <label for="email">Email</label>
                <input type="email" id="email" name="email" required>

                <button type="submit">Subscribe</button>
            </form>
        </section>
    </main>

    <footer>
        <p>&copy; 2026 Example Website</p>
    </footer>

    <script src="script.js"></script>
</body>
</html>

Common Mistakes

Missing the alt Attribute

<img src="image.jpg">

Better:

<img src="image.jpg" alt="Person learning HTML on a laptop">

Using a Link as a Button

<a href="#" onclick="saveForm()">Save</a>

Better:

<button type="button" onclick="saveForm()">Save</button>

Using a Table for Layout

<table>
    <tr>
        <td>Sidebar</td>
        <td>Main content</td>
    </tr>
</table>

Better: use semantic HTML and CSS layout.

<main class="layout">
    <aside>Sidebar</aside>
    <section>Main content</section>
</main>

Forgetting Form name Attributes

<input type="email" id="email">

Better:

<input type="email" id="email" name="email">

Forms need name values to submit data correctly.

Quick Reference

Create a Page

Use:

<!DOCTYPE html>
<html>
<head></head>
<body></body>
</html>

Add a Heading

Use:

<h1>Main heading</h1>

Add Text

Use:

<p>Paragraph text</p>

Add a Link

Use:

<a href="https://example.com">Link text</a>

Add an Image

Use:

<img src="image.jpg" alt="Image description">

Add a List

Use:

<ul>
    <li>Item</li>
</ul>

Add a Form

Use:

<form>
    <label for="email">Email</label>
    <input type="email" id="email" name="email">
</form>

Add a Button

Use:

<button type="button">Click me</button>

Add a Table

Use:

<table>
    <tr>
        <th>Heading</th>
    </tr>
    <tr>
        <td>Value</td>
    </tr>
</table>

Link CSS

Use:

<link rel="stylesheet" href="styles.css">

Add JavaScript

Use:

<script src="script.js"></script>