HTML Attributes

HTML pattern attribute

Build a form with the HTML form generator

Adds a whole-value pattern constraint to supported text-like inputs. Modern HTML uses Unicode Sets (v flag) semantics. Do not wrap the pattern in slash delimiters; combine with required to reject empty input. Applicable elements include: <input>. Check each element’s value rules.

Formal Syntax & Structure

html syntaxhtml
pattern="[0-9]{4}"

Parameters & Attributes

NameTypeDescription
patternJavaScript regular expression sourceAdds a whole-value pattern constraint to supported text-like inputs. Modern HTML uses Unicode Sets (v flag) semantics. Do not wrap the pattern in slash delimiters; combine with required to reject empty input.

Working Example

Example Snippethtml
<label>  PIN  <input inputmode="numeric" pattern="[0-9]{4}" required></label>

Browser Compatibility

Minimum supported versions across modern rendering engines

Chrome
4
Yes
Edge
12
Yes
Firefox
4
Yes
Safari
5
Yes
Opera
≤12.1
Yes
Checked desktop BCD snapshot: pattern on eligible input types; regex features vary. Versions denote the recorded start of support (≤ means at least that early), not a guarantee of all behavior. Unresolved mirror and preview rows omitted.
HTML Living Standard
HTML Reference