HTML Attributes
HTML pattern attribute
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
| Name | Type | Description |
|---|---|---|
| pattern | JavaScript regular expression source | 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. |
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