<label for="email">Email <span aria-hidden="true">*</span></label>
<input type="email" id="email" required>
<!-- :invalid CSS styles applied automatically on submit attempt -->
Field Validation
Native HTML5 form validation using required, type, and :invalid/:valid CSS pseudo-classes. No JavaScript needed for basic validation.
Required Field
Invalid State
Use data-invalid="true" on the field container to show error state. Associate the error message with aria-describedby:
<label for="email">Email</label>
<input type="email" id="email"
aria-describedby="email-error"
aria-invalid="true">
<p id="email-error" role="alert">
<span class="axicon render" data-name="Alert-Circle"></span>
Please enter a valid email address.
</p>
Valid State
<input type="email" id="email" value="jane@example.com"
aria-describedby="email-msg">
<p id="email-msg">
<span class="axicon render" data-name="Check-Circle"></span>
Email looks good.
</p>
Constraint Types
| Attribute | Validates | Example |
|---|---|---|
required | Field must have a value | <input required> |
type="email" | Valid email format | <input type="email"> |
type="url" | Valid URL format | <input type="url"> |
minlength | Minimum character count | <input minlength="8"> |
maxlength | Maximum character count | <input maxlength="100"> |
min / max | Numeric range | <input type="number" min="1" max="10"> |
pattern | Regex pattern match | <input pattern="[A-Za-z]{3}"> |
JavaScript Validation
const form = document.querySelector('form');
form.addEventListener('submit', (e) => {
// Check validity before submitting
if (!form.checkValidity()) {
e.preventDefault();
// Find first invalid field and focus it
const invalid = form.querySelector(':invalid');
if (invalid) invalid.focus();
}
});
// Live validation on blur
form.querySelectorAll('input, textarea, select').forEach(field => {
field.addEventListener('blur', () => {
field.setAttribute('aria-invalid', !field.validity.valid);
});
});
Accessibility
- Use
aria-invalid="true"on the input when invalid — not just visual styles - Connect error messages with
aria-describedbypointing to the errorid - Use
role="alert"on error messages so they're announced immediately - Never rely on colour alone — include an icon or text label
- Required fields: use
requiredattribute and indicate visually with * + legend
Features
- Semantic Structure - Built with native HTML5 elements for maximum reliability.
- Theme Aware - Automatically adapts to all 22 Axiom01 themes via OKLCH tokens.
- Fully Responsive - Scales perfectly from mobile to desktop screens.
- No JS Dependency - Core functionality relies on pure CSS for maximum performance.
- Customizable - Easily extendable via Axiom01's design tokens and modifiers.
Use Cases
The Field Validation component is designed for versatile implementation across modern web applications. Ideal scenarios include:
- Dashboards & Admin Panels - Structured data presentation and interface control.
- Content Management Systems - Organizing complex information hierarchies and media.
- E-Commerce Platforms - Enhancing product discovery and user workflows.
- Marketing Sites - Highlighting key product offerings cleanly and effectively.
- SaaS Applications - Delivering native-feeling, responsive app experiences.