Fieldset and Form Validation
fieldset groups related controls and legend names the group, which helps screen reader users. The browser can check required, type, min, max and pattern before the form is sent.
Browser validation is a convenience only. Always validate again on the server, because anyone can bypass the browser.
Example
<form onsubmit="event.preventDefault(); alert('Sent!')">
<fieldset>
<legend>Contact</legend>
<p><label>Email <input type="email" required></label></p>
<p><label>Age <input type="number" min="13" max="99" required></label></p>
</fieldset>
<button>Submit</button>
</form>Exercise
Name a group of fields.
<fieldset> <>Contact</> </fieldset>
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.