Faragiri

Learn Forms HTML

Five validity flags and the messages they produce with no script loaded, the three jobs a label does at once, and why none of it counts as validation.

4Sections
3Min read
4Depth

Recommended Before This

0 / 2

The browser validates a form before any script runs, and it reports exactly
what is wrong. Measured in a browser on 2026-09-02, an empty
required number field answers
Please fill out this field. from
input.validationMessage, the same field set to 0 with
min="1" answers
Value must be greater than or equal to 1., and an email field with
nope in it answers
Please include an '@' in the email address.. No JavaScript was
loaded on that page.

The constraint API behind those is what to read rather than the messages.
input.validity is an object of flags:
valueMissing is true for the empty required field,
rangeUnderflow for 0 against min 1, rangeOverflow for
900 against max="500", typeMismatch for the bad email
and patternMismatch for a five digit value against
pattern="[0-9]{10}". Each names the rule that failed, so custom
messages need no re-implementation of the check.

The label is a control, not a caption

<label for="tiles"> paired with
<input id="tiles"> does three things at once, and the third is
the one people miss. It gives the field its accessible name, so a screen reader
announces Tiles rather than edit text. It makes input.labels a list
of length 1, so scripts can find the label from the field. And clicking the
label moves focus into the input, which was confirmed by clicking it and reading
document.activeElement.id, which answered tiles.

Three gains, one attribute

What pairing a label with its input does at once

Connecting label for="tiles" to input id="tiles" wires up three behaviours that placeholder text cannot replace.

label[for] + input[id]
  • Accessible nameScreen readers announce Tiles instead of generic edit text
  • input.labels listGives scripts a direct list of length 1 back to the label
  • Larger tap targetClicking the label moves focus straight into the input

Placeholder text fails all three: it vanishes on focus, is not an accessible name in every browser, and gives no extra tap area on a phone.

Interactive Practice Lab

Edit and run this snippet directly in your browser (zero setup)

HTML
<article style="padding:14px;border:1px solid color-mix(in srgb,currentColor 24%,transparent);border-radius:12px">  <h3 style="margin:0 0 6px">Semantic Card</h3>  <p style="margin:0 0 10px;opacity:.85">Edit this HTML and click Run to preview live.</p>  <button onclick="console.log('Button clicked at', new Date().toLocaleTimeString())">Test Event</button></article>

Live Big-O Complexity & Binary Search Race Lab

Compare complexity curves at scale and watch Linear vs Binary Search race live.

That last one is a real usability gain on a phone, where the label is a much
larger target than the field. Placeholder text is not a substitute for any of
the three: it disappears on focus, it is not an accessible name in every
browser, and it leaves the user with no way to check what they were asked
for.

Two things the type attribute changes

type="number" brings up a numeric keypad on a phone and gives
you valueAsNumber, which answered 240 where value
answered the string. Reading value and converting is where a form
gets a string into a total, so read the typed property when there is one.

Native types vs generic markup

What changes when controls use the right elements

The type attribute and the button element change keyboard input, script properties, and tab order without a line of extra code.

Typed HTML controlstype="number" and button type="submit"
Untyped string and divPlain value read and clickable div
Phone keyboardBrings up numeric keypadDefaults to full text layout
Script readvalueAsNumber returns 240value returns a string to parse
Tab orderbutton has tabIndex 0div has tabIndex -1 and is skipped
Keyboard submitAnswers Enter and Space nativelySilent without custom keydown code

Nothing visible on the page warns you when a clickable div sits at tabIndex -1; keyboard users simply cannot reach submit.

The other is the submit control. A <button type="submit">
has tabIndex 0, so it is in the tab order and answers Enter and
Space. A <div> with a click handler has
tabIndex -1, which is not in the tab order at all, so the form is
unusable by keyboard and nothing on the page says so. Both were read from the
same document.

What to run in 2026

The browser's own constraint validation is the tool, free with the platform,
and it replaced a JavaScript validation library for the majority of forms.
novalidate on the form turns off the browser's bubbles while
leaving the validity object working, which is how you keep the
checks and style the messages yourself.

Built-in checks in 2026

How platform validation and a label checker work together

Two free browser tools replace custom validation libraries and manual tab-through audits.

  1. 01Start with native constraintsUse required, min, max, and pattern before adding script
  2. 02Add novalidate for custom stylingSuppresses default bubbles while keeping input.validity active
  3. 03Read validity flags directlyStyle messages from valueMissing or rangeUnderflow without rewriting rules
  4. 04Run an accessibility checkerCatches unlabeled fields that sighted testers overlook

Automated checkers find missing labels reliably because sighted testers already know where each input sits on screen.

An accessibility checker is the second, free as a browser extension. Point it
at a form and it reports the fields with no label, which is the defect that never
shows up in testing because the person testing can see where the field is. It
replaced tabbing through by hand, which finds the same faults and only when
somebody remembers to do it.

Where this stalls people

The stall is treating client validation as the validation. Everything on this
page runs in the browser, and the browser is under the control of whoever is
using it: the attributes can be edited, the script can be disabled, and the
request can be sent without the form at all. A form that only validates in the
browser has no validation.

One form, no script

What the browser checks before your code sees anything

Every yes is one attribute. The no rows are not oversights: they are checks that need something the browser cannot know.

  1. YesThe field was filled inrequired, and valueMissing says soYes
  2. YesThe number is in rangemin and max, giving rangeUnderflow and rangeOverflowYes
  3. YesIt looks like an emailtype=email, and typeMismatch when it does notYes
  4. YesIt matches a shapepattern, and patternMismatch on a five digit postcodeYes
  5. NoThe email address existsNothing in the browser can know thisNo
  6. NoThe postcode is a real oneA lookup on the server, not a patternNo
  7. Not checkedThe request came from this form at allNobody checked. The browser is not the only thing that can send itNot checked

The unknown row is why the four yes rows are a convenience rather than a defence. Every attribute above can be edited in the inspector in about four seconds, and the server has to repeat all of them.

The rule is that client validation is a convenience for honest users and the
server check is the real one, and both must exist. The same fields, the same
rules, in two places, on purpose. What the server does with the submission is
request in, response
out, and everything between
, the elements the form is built from are
elements that say what they are,
and who that helps
, and where the whole document's order comes from is
head, body, and the order a
document is read in
, inside
the structure under every page.

Alongside this

Above this