0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Marks a form control that must have a value before its form can be submitted. Works without JavaScript; Vanilla Breeze adds the asterisk, the error styling and custom messages.
Overview
required is a boolean attribute that makes a control invalid while it has no value. An invalid control blocks form submission, matches :invalid (and :user-invalid once the user has interacted), and is announced as "required" by screen readers.
Applies to:<input> (every type except hidden, range, color and the button types), <select> and <textarea>.
Required fields with form-field
123456789101112131415
<formdata-validate><form-field><labelfor="name">Full name</label><inputtype="text"id="name"name="name"autocomplete="name"requireddata-message-valuemissing="Enter your name as it appears on your ID." /><outputclass="error"for="name"aria-live="polite">Enter your name.</output></form-field><form-field><labelfor="bio">Bio</label><textareaid="bio"name="bio"rows="2"></textarea></form-field><buttontype="submit">Create account</button></form>
No asterisk is typed into the label: <form-field> adds it for any field that contains a required control.
Values
required is boolean: present means required, absent means optional. required="false" still makes the field required.
Control
Counts as empty when
Text-like <input>, <textarea>
The value is the empty string. Whitespace counts as a value.
<select>
No option is selected, or the selected option is the placeholder label option: the first option, with value="", directly in a <select> that has no multiple and a display size of 1. A required select without such an option always has a value.
<select multiple>
No option is selected.
Checkbox
It is not checked.
Radio
No radio with the same name in the same form is checked. required on any one radio makes the whole group required.
File
No file is selected.
Examples
Select with a placeholder option
Required select
<form-field><labelfor="country">Country</label><selectid="country"name="country"autocomplete="country"requireddata-message-valuemissing="Choose the country you ship to."><optionvalue="">Choose a country</option><optionvalue="CA">Canada</option><optionvalue="DE">Germany</option><optionvalue="JP">Japan</option></select><outputclass="error"for="country"aria-live="polite"></output></form-field>
Radio group
Wrap the group's <fieldset> in one <form-field>. The asterisk goes on the legend, and the field binds every radio that shares the name.
Required radio group
<form-field><fieldset><legend>Plan</legend><label><inputtype="radio"name="plan"value="free"requireddata-message-valuemissing="Pick a plan to continue." /> Free</label><label><inputtype="radio"name="plan"value="pro" /> Pro</label><label><inputtype="radio"name="plan"value="team" /> Team</label></fieldset><outputclass="error"aria-live="polite"></output></form-field>
Required checkbox
Consent checkbox
<form-fielddata-type="checkbox"><label><inputtype="checkbox"id="terms"name="terms"requireddata-message-valuemissing="Accept the terms to create an account." /> I accept the terms of service</label><outputclass="error"for="terms"aria-live="polite"></output></form-field>
"At least N" checkboxes
required on a checkbox means that one box must be checked. For "pick at least one of these", put data-min-checked on the fieldset of a data-validate form instead.
Asterisk.form-field:has(:required) adds a red * after the field's label, or after the legend of a fieldset it wraps (src/custom-elements/form-field/styles.css). It is silent to screen readers, which announce the native required state instead. Never type * into the label text; you would get two.
Error and valid styling.:user-invalid or [aria-invalid="true"] gives the field the error border with a thicker inline-start edge (src/native-elements/input/styles.css). Inside <form-field>, a required field that becomes :user-valid gets the success border and its hint collapses.
Messages without script.data-message-valuemissing on the control sets the text shown in output.error, in place of the browser's generic "Please fill out this field". The other data-message-* keys are listed on form-field.
Timing.<form-field> validates when focus leaves the field, then on every edit once an error has shown. form[data-validate] validates everything on submit, focuses the first error and can fill an error summary.
Hidden sections.data-show-when, data-hide-when and data-wizard-if disable every control in a section they hide (marked data-conditional-disabled). A required field in a hidden section therefore neither blocks submit nor sends a value, and it is re-enabled when the section shows again (src/lib/form-conditions.js).
Wizard. In a data-wizard form, Next validates the current step's controls (required included), and the final submit jumps back to the step that holds the first invalid field.
Accessibility
Screen readers announce native required. Don't add aria-required="true" as well; it is only for custom controls without the native attribute.
Show which fields are required before the user submits. The form-field asterisk does that; say what it means once, near the top of long forms ("Fields marked * are required"), or mark the optional fields instead when most are required.
Error text must say what to do. Put it in data-message-valuemissing so it appears in the field's live output.error.
Don't disable the submit button until the form is valid. A disabled button gives no reason; let the user submit and show the errors.
Gotchas
Validity is live; reporting waits. A required field is invalid from the start and becomes valid the moment it has a value, so :invalid matches on page load. The browser only reports the error (bubble, focus) on submit or reportValidity(). Style with :user-invalid, which waits for interaction.
disabled and readonly controls are barred from validation, so required on them has no effect.
required does nothing on a <select> whose first option has a real value: something is always selected.
novalidate on the form, or formnovalidate on the submit button, skips the check on a plain form. A data-validate form checks every submit; see formaction for Save-draft buttons.
Whitespace is a value. " " satisfies required; add a pattern such as .*\S.* if that matters.