Skip to content

Menu

HTML Elements Cheat Sheet: Forms, Meta Tags, Images and Dialog

Checked against HTML (WHATWG Living Standard) WHATWG HTML Living Standard (last updated 27 Nov 2026) and MDN reference pages on 28 November 2026. Each section links to the official docs it was checked against.

This sheet is for front-end and full-stack developers who know HTML but keep shipping the same small bugs: forms that submit on the wrong click, images that shift the layout, modals that trap no one. HTML is a living standard with no version numbers, so each row follows the WHATWG spec as of 27 Nov 2026 and MDN's reference pages read the same day. We didn't run these rows in a browser; they're all checked against the docs only and marked untested.

When to use what

Prefer the native element before you reach for a component library. <dialog> opened with showModal() gives you focus handling, an inert background and Escape to close for free. <details> with a shared name is an accordion with no JavaScript. A real <button> is focusable and fires on Enter and Space; a <div onclick> is neither until you add a pile of ARIA and key handlers.

For forms, the label and the input type do most of the accessibility and mobile work. A <label for> gives the field a name screen readers announce and a bigger tap target; type="email" and autocomplete="email" get the right keyboard and autofill. Placeholder text disappears as soon as someone types, so don't use it as the label.

In the head, the non-negotiables are <meta charset="utf-8"> near the top, a viewport tag, a <title> and lang on <html>. After that, add a canonical link and a description; our meta tag generator writes the set for you and the canonical URL checker tells you what a live page actually declares. For ARIA, check our ARIA attribute reference before adding roles to elements that already have one, and see the responsive images post for srcset in depth.

The spec says a title is required in most documents and allows at most one <base> element (WHATWG semantics).

<html lang="en-GB">

Set the page language with a BCP 47 tag; screen readers use it for pronunciation and lang="" means unknown

From the docs, not run by us
<meta charset="utf-8">

Must be UTF-8 and must sit entirely in the first 1024 bytes of the document

From the docs, not run by us
<meta name="viewport" content="width=device-width">

Render at device width so media queries work; MDN says initial-scale=1 is usually optional

From the docs, not run by us
user-scalable=no / maximum-scale=1

Avoid: blocks zoom for low-vision users; iOS 10+ ignores it by default

From the docs, not run by us
<meta name="description" content="…">

Page summary that search engines may show in results

Try it: Meta Tag GeneratorFrom the docs, not run by us
<title>Page name</title>

Required child of <head> in most documents; one per page

From the docs, not run by us

Button behaviour is from the MDN button page; label rules from the label page.

<button type="button">

No default action; set it on every button inside a form that isn't meant to submit

From the docs, not run by us
<button>

Inside a form, a missing, empty or invalid type means submit

From the docs, not run by us
<label for="email">

Match the input's id; clicking the label focuses the field. Don't put links or buttons inside a label

From the docs, not run by us
<input>

A missing or unknown type falls back to text

From the docs, not run by us
<input type="number" step="any">

Default step is 1, so 4.2 fails validation unless you change it

From the docs, not run by us
<input pattern="[A-Z]{3}[0-9]{4}">

Must match the whole value (wrapped as ^(?:…)$); no slashes

Try it: Regex TesterFrom the docs, not run by us
<input> without name

An input with no name (or an empty one) is not submitted with the form

From the docs, not run by us
<input type="checkbox">

Submits on when checked and nothing at all when unchecked, unless you set value

From the docs, not run by us
inputmode="numeric"

Ask for a numeric keyboard without the validation and spinner of type="number"

From the docs, not run by us
autocomplete="email" / "name" / "tel"

Contact fields; MDN prefers one name field over split first and last names

From the docs, not run by us
autocomplete="username" + "current-password"

Login form pair so password managers fill the right fields

From the docs, not run by us
autocomplete="new-password"

Sign-up and change-password fields, so the manager suggests a new password

From the docs, not run by us
autocomplete="one-time-code"

SMS or authenticator code field

From the docs, not run by us
autocomplete="street-address" / "postal-code"

Address fields; street-address excludes city, postcode and country

From the docs, not run by us
autocomplete="off"

Browsers may ignore this on login fields so password managers keep working

From the docs, not run by us
alt="A penguin on a beach"

Text replacement; mandatory. Without it some screen readers read the file name

Try it: Image SEO ChecklistFrom the docs, not run by us
alt=""

Marks an image as decorative so assistive tech can skip it

From the docs, not run by us
width="400" height="300"

Lets the browser reserve the aspect ratio before load and avoid layout shift

Try it: Image Ratio FinderFrom the docs, not run by us
loading="lazy"

Defer until near the viewport; default is eager. Don't lazy-load the hero image

From the docs, not run by us
fetchpriority="high"

Hint to fetch this image ahead of others; default auto

From the docs, not run by us
srcset="a.png 200w, b.png 400w" sizes="50vw"

Width candidates; sizes defaults to 100vw and you can't mix w and x descriptors

From the docs, not run by us

<details> rows follow the MDN details page.

dialog.showModal()

Open as modal: rest of page inert, Escape closes, ::backdrop styles the overlay

From the docs, not run by us
<dialog open>

Opens non-modal only; use show() or showModal() instead of setting the attribute

From the docs, not run by us
<form method="dialog">

Submitting closes the dialog and sets returnValue to the clicked button's value

From the docs, not run by us
<button commandfor="d" command="show-modal">

Open a dialog declaratively; close and request-close also exist

From the docs, not run by us
<details name="faq"><summary>…

Same name makes an exclusive accordion; <summary> must be the first child

From the docs, not run by us
<details open="false">

Still open: open is boolean, so remove the attribute to close it

From the docs, not run by us
<button popovertarget="menu">

Toggle an element with the popover attribute; default action is toggle

From the docs, not run by us

Worked example: Fix a sign-up form that submits when you click 'Show password'

A common bug report: clicking the eye icon that reveals the password submits the form. Here is the markup:

<form action="/signup" method="post">
  <input id="email" placeholder="Email">
  <input id="pw" type="password">
  <button onclick="togglePw()">Show password</button>
  <button>Create account</button>
</form>

There are four problems. The toggle button has no type, and inside a form that means submit, so the click submits. Neither input has a name, so even a correct submit would send nothing. The email field relies on a placeholder instead of a label and uses the default text type. And the password field gives the password manager no hint that this is a new password. The fixed version:

<form action="/signup" method="post">
  <label for="email">Email</label>
  <input id="email" name="email" type="email" autocomplete="email" required>
  <label for="pw">Password</label>
  <input id="pw" name="password" type="password" autocomplete="new-password" required>
  <button type="button" onclick="togglePw()">Show password</button>
  <button type="submit">Create account</button>
</form>

What to look for when you test it: the toggle no longer navigates, the request body now contains email and password, phones show an email keyboard, and the password manager offers to generate a password. We didn't run this in a browser, so each point comes from the MDN pages cited in the sections above.

Common mistakes

  • Leaving type off buttons inside a form that open menus, toggle passwords or add rows.

    Write type="button" on every non-submit button; the default inside a form is submit.

  • Using placeholder as the only label for a field.

    Add a visible <label for> matching the input's id; keep the placeholder for an example value if you want one.

  • Shipping images without width and height and then chasing layout shift.

    Set both attributes to the image's real pixel size and let CSS scale it; the browser uses them for the aspect ratio.

  • Writing <details open="false"> or disabled="false" to turn a boolean attribute off.

    Remove the attribute. Any value, including false, turns a boolean attribute on.

  • Opening a modal by adding the open attribute to <dialog>.

    Call showModal(). The attribute only gives a non-modal dialog, with no inert background and no Escape handling.

  • Setting autocomplete="off" on a login form to stop autofill.

    Browsers may ignore it there. Use the right tokens (username, current-password) and let password managers work.

  • Disabling zoom with user-scalable=no to stop layout jumps on mobile.

    Remove it and fix the overflowing element instead; blocking zoom fails people with low vision.

Sources

How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe
Reviews and commentsShow

Comments

Sign in to leave a comment.

Loading comments…