required
Makes a field mandatory before submission.
Learn required, minlength, maxlength, pattern, min, max, step as part of the HTML attribute system: what they configure, where they belong and which mistakes to avoid.
Validation
HTML validation attributes let the browser catch simple mistakes such as missing values, invalid email addresses, too-short text or numbers outside a range.
They are not a security layer. They are a usability layer. The server must still validate every submitted value.
required, minlength, maxlength, pattern, min, max, step. Browser validation attributes that catch simple mistakes before submit. What belongs here
requiredMakes a field mandatory before submission.
minlength + maxlengthControls text length.
patternRequires text to match a regular expression.
min + maxSets number, range or date boundaries.
stepControls increments for number/range inputs.
typeSome types have built-in validation, such as email and url.
Syntax in context
Combine the right input type with specific validation attributes for clear browser feedback.
<label for="postcode">Postcode</label> <input id="postcode" name="postcode" required minlength="6" maxlength="7"> <label for="email">Email</label> <input id="email" name="email" type="email" required>
Good versus weak
<label for="postcode">Postcode</label> <input id="postcode" name="postcode" required minlength="6" maxlength="7"> <label for="email">Email</label> <input id="email" name="email" type="email" required>
<input name="email"> <input name="postcode"> <button>Submit</button>
Rules that matter
It gives quick feedback before a request is sent.
Users can bypass or change HTML validation.
A strict pattern without explanation can frustrate users.
Do not use pattern when a better input type already exists.
Production thinking
Attributes are small, but they change how an element works. A good attribute can make a link usable, an image understandable, a form easier to complete or a script safer to load.
Validation should explain what went wrong and how to fix it. Native validation is helpful but not always enough.
Good validation attributes reduce junk submissions, but serious filtering belongs on the backend too.
Live code lab
Edit the HTML or CSS, then use Run to refresh the preview. The preview is isolated, so links and forms stay inside this practice area.
Mini assignment
Practice assignment
Try it yourself
Self-check
Do not only read this page. Answer these questions out loud or write the answers in your own notes. If one answer feels vague, revisit the examples before moving on.