HTML Forms: form, label, input Types, textarea, select, radio, checkbox, button and fieldset with Accessible Labels
The Form Element
html
<form action="/subscribe" method="post">
<!-- fields go here -->
<button type="submit">Send</button>
</form>
actionis the address that receives the datamethodisget(data in the address) orpost(data in the request body)- Each field needs a
name. Only named fields are sent
Label and Input
html
<label for="fullname">Full name</label>
<input type="text" id="fullname" name="fullname" autocomplete="name">
for matches the input id. Clicking the label focuses the input. Screen readers read the label. Never use only a placeholder instead of a label.
Text and Choice Fields
html
<label for="msg">Message</label>
<textarea id="msg" name="msg" rows="4" cols="40"></textarea>
<label for="country">Country</label>
<select id="country" name="country">
<option value="">Choose one</option>
<option value="in">India</option>
<option value="us">United States</option>
</select>
<fieldset>
<legend>Preferred contact</legend>
<label><input type="radio" name="contact" value="email" checked> Email</label>
<label><input type="radio" name="contact" value="phone"> Phone</label>
</fieldset>
<label><input type="checkbox" name="news" value="yes"> Send me the newsletter</label>
- Radio buttons with the same name allow only one choice
- Checkboxes allow many choices
fieldsetandlegendgroup related fields with a title
Buttons
| Code | Result |
|---|---|
<button type="submit"> | Sends the form |
<button type="reset"> | Clears the form |
<button type="button"> | Does nothing until JavaScript uses it |
Style a Form
css
label { display: block; margin-top: 1rem; font-weight: 600; }
input[type="text"], input[type="email"], select, textarea {
width: 100%;
max-width: 28rem;
padding: .6rem .7rem;
border: 1px solid #99a3b3;
border-radius: .4rem;
font: inherit;
}
input:focus, select:focus, textarea:focus {
outline: 3px solid #8ab4ff;
outline-offset: 1px;
}
button { margin-top: 1rem; padding: .7rem 1.2rem; border: 0; border-radius: .4rem; background: #0b5fff; color: #fff; font: inherit; cursor: pointer; }
Do not remove focus Never write
outline: none without a replacement. Keyboard users need to see where they are.
Practice
- Build a contact form with name, email, message and a send button
- Add a radio group and a checkbox
- Style it and tab through it with the keyboard
Conclusion
Good forms use a label for every field, correct input types, grouped choices and visible focus.
Quick Summary: Form element; labels; text and choices; buttons; styling.

