devcrea

Native HTML Form Validation: What Browsers Check and Skip

See what native HTML form validation attributes check and skip in 2026, from required and pattern to ValidityState flags and :user-invalid CSS.

// The short answer

Native HTML form validation attributes (required, type, minlength, maxlength, min, max, step, and pattern) block invalid submissions in the browser via the Constraint Validation API before any JavaScript runs. However, browsers silently skip whitespace-only required inputs, prefilled minlength values until user edit, pattern on textareas or number inputs, and all constraints during form.submit() calls. Pair semantic attributes with :user-invalid CSS, visible aria-describedby hints, and matching server-side validation.

Full walkthrough, edge cases and why it works
In this guide · 7 sections
  1. 01Native HTML Form Validation Attributes: Checks vs. Skips
  2. 02How Each Validation Attribute Behaves (and Fails)
  3. 03Submission Triggers and Silent Validation Bypasses
  4. 04Styling Validation States: :user-invalid vs. :invalid
  5. 05Why the title Tooltip Is Not Enough
  6. 06Cross-Browser Verification Matrix (Chrome, Firefox, Safari)
  7. 07Where Native HTML Validation Stops

Every modern browser comes with a built-in validation engine that stops bad form submissions before a single byte of JavaScript loads. You can enforce required fields, character limits, number bounds, and regex patterns using plain HTML attributes, then style the feedback directly with CSS. Knowing where the browser stops checking, and where it quietly waves invalid inputs through, keeps broken forms and bad assumptions out of production.

  • Core scope: Zero-JS HTML form validation attributes (required, type, pattern, minlength, maxlength, min, max, step), ValidityState flags, and :user-invalid CSS styling.
  • Prerequisites: Comfort with HTML form controls, CSS pseudo-classes, and browser DevTools.
  • Browser baseline (2026): Constraint validation works across all modern engines. :user-invalid and :user-valid work natively in Chrome 119+, Firefox 88+, and Safari 16.5+.
  • Hard boundary: Native validation improves user experience only. It never acts as a security barrier, so you must always mirror these checks on the server.

Native HTML Form Validation Attributes: Checks vs. Skips

Each validation attribute maps to a specific boolean flag on the element's ValidityState object. When any flag flips to true, element.validity.valid drops to false and the browser blocks submission.

Attribute Applies To What the Browser Checks What It Silently Skips ValidityState Flag
required <input>, <select>, <textarea> Non-empty value (or checked state for checkboxes and radios) Whitespace-only strings (" "), plus disabled or readonly fields valueMissing
type="email" <input> Presence of @ and basic domain syntax Missing top-level domains (user@localhost passes) and real deliverability typeMismatch
type="url" <input> Presence of a valid URI scheme (like https:) Missing hostnames in some schemes and unreachable URLs typeMismatch
type="number" <input> Numeric syntax (badInput triggers on letters) Scientific notation e/E passes through, and leading zeros get stripped badInput
type="tel" <input> Nothing natively (only triggers the mobile keypad) Any phone format, country code, or character restriction None
minlength / maxlength Text-like <input>, <textarea> UTF-16 code unit count after you edit the field Prefilled or script-set values (dirty value flag) and type="number" tooShort / tooLong
min / max number, range, date, time, month, week, datetime-local Lower and upper numeric or date/time bounds Keyboard typing past the limit (flagged only on submit, never blocked while typing) rangeUnderflow / rangeOverflow
step Same as min / max Value alignment to (value - base) % step === 0 Floating-point precision quirks, and disabled altogether when step="any" stepMismatch
pattern Text-like <input> only (text, tel, email, url, password, search) Full-value regex match (implicitly anchored with ^(?:...)$) Empty values (unless required is also set), <textarea>, type="number", and broken regex syntax patternMismatch

Here is a minimal, zero-JavaScript form that combines these constraints:

html34 lines
<form action="/register" method="post">
  <label for="handle">Handle</label>
  <input
    id="handle"
    name="handle"
    type="text"
    required
    minlength="3"
    maxlength="16"
    pattern="[a-z0-9_]+"
    aria-describedby="handle-hint"
  />
  <p id="handle-hint">3 to 16 lowercase letters, numbers, or underscores.</p>

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

  <label for="seats">Seats</label>
  <input id="seats" name="seats" type="number" min="1" max="50" step="1" required />

  <label for="plan">Plan</label>
  <select id="plan" name="plan" required>
    <option value="">Select a plan</option>
    <option value="starter">Starter</option>
    <option value="pro">Pro</option>
  </select>

  <label>
    <input type="checkbox" name="terms" required />
    I agree to the terms
  </label>

  <button type="submit">Create account</button>
</form>

How Each Validation Attribute Behaves (and Fails)

required on Inputs, Selects, Checkboxes, and Radios

required stops submission when a control has no value, though three edge cases catch developers off guard:

  • Spaces count as a value: Typing three spaces into a required text input satisfies valueMissing === false because the browser never trims whitespace. If blank-looking text shouldn't pass, pair required with pattern=".*\S.*" or trim and re-check on the server.
  • Select placeholder rule: On a <select required>, the browser only treats the first <option> as a placeholder when its value attribute is an empty string (<option value="">Select a plan</option>). Leave out value="", and the browser treats the option's text label as a valid pick.
  • Barred controls: Adding disabled or readonly pulls a control out of constraint validation completely. A required readonly input will never stop a form from submitting.

type Validation (email, url, number, date, tel)

Picking the right type gets you format checks and mobile keyboard layouts without extra attributes, though every type has firm boundaries:

  • type="tel" validates nothing. Phone formats vary around the world, so browsers never trigger typeMismatch on tel inputs. Pair type="tel" with pattern whenever you need actual format enforcement.
  • type="url" expects a full valid URL with a scheme. Typing example.com fails typeMismatch, whereas [https://example.com](https://example.com) goes right through.
  • type="email" follows a deliberately loose spec rule. It accepts addresses without a top-level domain, such as admin@localhost. For the exact RFC deviations and ways to enforce a TLD safely, check out our guide on HTML input type="email" TLD validation.
  • type="number" accepts e, +, and -, drops leading zeros during numeric parsing (valueAsNumber), and reacts to mouse scroll wheels. Skip it for ZIP codes, phone numbers, or credit cards. For a closer look at numeric input traps and inputmode="numeric" alternatives, check out our guide on HTML input type="number" gotchas.

minlength and maxlength (and the Dirty Value Flag)

minlength and maxlength count UTF-16 code units on text-like <input> elements and <textarea>. On type="number", browsers ignore them completely.

The biggest MDN and WHATWG catch here involves the dirty value flag: browsers only run minlength and maxlength checks after a person manually edits the field. When a value comes prefilled via the HTML value attribute or gets injected by JavaScript (input.value = "a"), input.validity.tooShort stays false and the form submits without complaint.

min, max, and step

These attributes set bounds on numeric and date/time inputs. On type="number", step defaults to 1, so anyone typing 2.5 into <input type="number" min="0"> hits stepMismatch unless you explicitly add step="0.01" (for currency) or step="any" (for arbitrary decimals).

Keep in mind that min and max only cap the browser's up/down spinner buttons. Someone can still type 99999 into a field with max="50" on their keyboard, the browser won't block those keystrokes and only flags rangeOverflow once they try to submit.

pattern (Anchored Regex Without Flags)

pattern checks text-like <input> controls against a regular expression. The browser wraps your expression in ^(?: and )$ behind the scenes, so the entire input value has to match, writing ^ and $ yourself does nothing extra.

Two common failure modes show up here:

  • pattern does nothing on <textarea> and type="number". Slap pattern onto a <textarea>, and the browser walks right past it.
  • Broken regex syntax fails silently. If your pattern has a syntax error, the browser drops the attribute, treats the field as valid, and only leaves a quiet warning in the DevTools console. Modern browsers compile pattern with the Unicode v flag, which breaks older unescaped character classes like [\w-] in certain spots. For the full rundown on v-flag syntax breaks and fixes, see our guide on fixing HTML pattern v-flag failures alongside our JavaScript regex guides.

Submission Triggers and Silent Validation Bypasses

How you trigger a form submission decides whether native validation runs at all.

Trigger Method Runs Constraint Validation? Fires submit Event? Shows Native Error Bubble?
User clicks <button type="submit"> Yes Yes Yes
submitButton.click() Yes Yes Yes
form.requestSubmit() Yes Yes Yes
form.submit() No (bypassed) No No

Calling form.submit() from JavaScript quietly skips every HTML validation attribute on the page. Reach for form.requestSubmit() instead whenever you submit programmatically so the browser still enforces your rules.

To check what the browser sees on any field without writing a validation script, inspect the ValidityState object straight from your browser console:

js16 lines
const input = document.querySelector('#handle');
console.log(input.validity);
// ValidityState {
//   badInput: false,
//   customError: false,
//   patternMismatch: false,
//   rangeOverflow: false,
//   rangeUnderflow: false,
//   stepMismatch: false,
//   tooLong: false,
//   tooShort: true,
//   typeMismatch: false,
//   valid: false,
//   valueMissing: false
// }
console.log(input.validationMessage);

Styling Validation States: :user-invalid vs. :invalid

The :invalid pseudo-class matches a control the second the DOM renders. Style input:invalid with a red border, and every empty required field on your page loads red before anyone even touches the keyboard.

:user-invalid (along with :user-valid) fixes that behavior out of the box. A control only matches :user-invalid after someone interacts with it, usually once they edit and blur the field, or after they try submitting the form.

  • Browser differences to watch: Chrome (119+), Firefox (88+), and Safari (16.5+) all support :user-invalid, though exact trigger timing differs slightly on untouched fields when tabbing through without typing, and on <select> or checkbox changes before blur.

Make :user-invalid your primary selector, and layer a fallback only when you need to support older browser versions:

css18 lines
/* Modern browsers (Chrome 119+, Firefox 88+, Safari 16.5+) */
input:user-invalid,
select:user-invalid,
textarea:user-invalid {
  border-color: #c62828;
  background-color: #fff5f5;
}

input:user-valid {
  border-color: #2e7d32;
}

/* Fallback for older engines using :placeholder-shown (requires placeholder=" ") */
@supports not selector(:user-invalid) {
  input:not(:placeholder-shown):invalid {
    border-color: #c62828;
  }
}

Keep in mind that :not(:placeholder-shown):invalid needs a non-empty placeholder attribute (even a single space) and still misses an empty required field that someone focused and blurred without typing. When you need exact parity on legacy browsers, toggle a .touched class on the blur event and target .touched:invalid.

Why the title Tooltip Is Not Enough

When a pattern constraint fails, browsers tack the input's title attribute text onto the native validation bubble. That gives sighted mouse users a quick hint after a failed submit, yet leaning on title alone creates immediate usability headaches:

  • Touch-screen users on mobile cannot hover to read title tooltips. * Keyboard-only users never see hover tooltips while tabbing through fields. * Screen readers handle title inconsistently and often skip right over it when a <label> already exists.

Put format requirements in visible text right next to the field and hook it up with aria-describedby:

html10 lines
<label for="sku">Product SKU</label>
<input
  id="sku"
  name="sku"
  type="text"
  required
  pattern="[A-Z]{2}-[0-9]{4}"
  aria-describedby="sku-format"
/>
<p id="sku-format">Format: two uppercase letters, a hyphen, and four digits (e.g., AB-1234).</p>

Cross-Browser Verification Matrix (Chrome, Firefox, Safari)

Test Case Expected WHATWG Spec Behavior ValidityState / Outcome
required with " " (spaces) Passes whitespace-only text valueMissing: false
minlength="5" prefilled "abc" via HTML value Passes until user edits tooShort: false
type="email" with user@localhost Passes single-label domain typeMismatch: false
type="number" with step="0.01" and 1.005 Fails step alignment stepMismatch: true
pattern on <textarea> Ignored on textarea valid: true
form.submit() on invalid form Bypasses validation and submits No submit event or bubble
:user-invalid on empty required field at load Does not match before interaction Matches only after edit/submit

To test these behaviors in your own project, open DevTools on your form page, run document.querySelector('form').checkValidity() before and after editing each field, and confirm that form.requestSubmit() moves focus straight to the first invalid control.

Where Native HTML Validation Stops

Native attributes handle single-field format, presence, length, and range checks with zero JavaScript. Once your form needs cross-field rules, custom inline error layouts, or security enforcement, head over to the dedicated guides in this series:

  • pattern Unicode v-flag syntax failures: Why valid legacy regexes quietly break in modern browsers and how to rewrite them.
  • type="email" quirks and TLD enforcement: Why browsers accept a@b and how to layer stricter email checks.
  • Password composition rules: Why native pattern attributes hurt password UX and how to validate HTML password fields cleanly.
  • Security and server-side mirroring: Why client-side attributes are trivial to bypass and client-side validation security and server mirroring.
  • Custom inline errors and ARIA wiring: How to turn off native bubbles with novalidate, route ValidityState flags with setCustomValidity(), and custom inline form errors and ARIA.
  • Form association across complex layouts: How to tie inputs outside the <form> wrapper using HTML nested forms alternatives for the form="id" attribute pattern.

Quick answers

Frequently asked questions

Why does my required HTML input accept spaces as a valid value?

The HTML required attribute only checks if a field is an empty string, so spaces or tabs pass validation without trouble. Browsers never trim input values automatically before checking them. If you want to block whitespace-only entries without JavaScript, add pattern=".*\S.*" directly to the input or trim and validate the value on your server.

Why does minlength not validate a prefilled or script-set input value?

Browsers only enforce minlength and maxlength once you manually edit a field, which flips on the internal dirty value flag. When a value comes from the HTML value attribute or a script assignment like input.value = "ab", input.validity.tooShort stays false. Validate any prefilled data on your server or check the value length explicitly in JavaScript before submitting the form.

Why does form.submit() bypass native HTML form validation?

Calling form.submit() sends your form straight to the server without firing the submit event or running the browser's constraint validation checks. To trigger built-in validation rules and native error bubbles from JavaScript, call form.requestSubmit() or trigger click() on a submit button instead.

Does the pattern attribute work on a textarea or number input?

No, browsers ignore the pattern attribute on textarea elements and inputs with type="number". You can only use pattern on text-like input types such as text, tel, email, url, password, and search. Control number inputs with min, max, and step instead, and enforce complex rules on textarea fields using JavaScript or server-side checks.

How do you stop required inputs from turning red before the user types anything?

Swap the :invalid CSS pseudo-class for :user-invalid, which only matches after someone interacts with the field or tries to submit the form. Chrome 119+, Firefox 88+, and Safari 16.5+ all support :user-invalid natively without any JavaScript. For older browsers, combine input:not(:placeholder-shown):invalid with a non-empty placeholder attribute or toggle a custom class on blur.

Why does type="email" allow addresses without a domain extension like user@localhost?

The WHATWG HTML specification defines email validation with a rule that requires an @ symbol and a domain label, but no dot or top-level domain. Because of that rule, intranet addresses like user@localhost pass native checks. If your app needs a standard public domain with a TLD, pair type="email" with a pattern attribute and verify the address on your server.

Is the title attribute enough to explain pattern requirements to users?

No, browsers only append the title attribute to the validation bubble after a failed submission, leaving it invisible on mobile touch screens and unreliable for keyboard and screen-reader users. Write your format rules in visible helper text right next to the input and link that text with aria-describedby.

Can native HTML validation attributes replace server-side validation?

No, browser validation is strictly a user-experience feature and gives you zero security protection. Anyone can bypass HTML constraints by opening DevTools, turning off JavaScript, or sending a direct HTTP request with curl. Mirror every required, length, range, and format check on your backend.

Something wrong or out of date?

Tools change fast. Tell the editor what no longer works.