The snippet library.
Small, practical examples. Search by task or narrow things down below.
Allow several selected options
HTML: A multiple select exposes each selected option as a value with the same control name.
HTML✓ Tested
Constrain a calendar date input
HTML: Use ISO date values for the date control’s minimum and maximum.
HTML✓ Tested
Limit a numeric input to an inclusive range
HTML: Number inputs expose range validation separately from the entered text.
HTML✓ Tested
Limit typed text to a maximum length
HTML: Maxlength limits ordinary user editing without replacing server-side validation.
HTML✓ Tested
Require a checkbox to be selected
HTML: A required checkbox is invalid until that individual control is checked.
HTML✓ Tested
Require a nonempty text value
HTML: The required attribute makes an empty text control fail native constraint validation.
HTML✓ Tested
Require numeric values on a chosen step
HTML: The step interval is measured from the minimum value when one is provided.
HTML✓ Tested
Select a time in quarter-hour increments
HTML: A time step is expressed in seconds, so 900 represents fifteen minutes.
HTML✓ Tested
Validate a structured text identifier
HTML: The pattern attribute matches the entire nonempty input; required handles the empty case.
HTML✓ Tested
Validate the shape of an absolute URL
HTML: A URL input checks syntax, not whether a resource exists or is safe.
HTML✓ Tested