HTML Forms: form, label, input Types, textarea, select, radio, checkbox, button and fieldset with Accessible Labels

HTML5 and CSS3 55 min min read Updated: Nov 17, 2026 Beginner
HTML Forms: form, label, input Types, textarea, select, radio, checkbox, button and fieldset with Accessible Labels
Beginner Topic 2 of 3

The Form Element

html <form action="/subscribe" method="post"> <!-- fields go here --> <button type="submit">Send</button> </form>
  • action is the address that receives the data
  • method is get (data in the address) or post (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
  • fieldset and legend group related fields with a title

Buttons

CodeResult
<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

  1. Build a contact form with name, email, message and a send button
  2. Add a radio group and a checkbox
  3. 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.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators