Skip to content

HTML Forms Tutorial: Inputs, Labels, Validation and Accessibility

A practical HTML forms tutorial — form structure, input types, labels, built-in validation, accessibility, styling basics and how form data is sent securely.
HTML Forms Tutorial: Inputs, Labels, Validation and Accessibility — WebDesigningPune guide
Quick answer

An HTML form collects user input with the <form> element and controls such as <input>, <textarea>, <select> and <button>. Every control needs a <label>, a name attribute and the right input type (email, tel, number, date). Use built-in validation attributes like required and minlength, but always validate again on the server.

HTML forms are how websites listen. Every enquiry, newsletter sign-up, booking and checkout starts with a form, which makes forms some of the most valuable — and most frustrating — parts of the web. A well-built form feels effortless; a poorly built one loses customers at the last step.

This tutorial covers the HTML you need to build forms that work for everyone, including people using keyboards, screen readers and phones.

A basic HTML form: the contact form

Code editor or browser screenshot supporting “A basic contact form”
<form action="/contact" method="post">
  <label for="name">Name</label>
  <input id="name" name="name" type="text" autocomplete="name" required>

  <label for="email">Email</label>
  <input id="email" name="email" type="email" autocomplete="email" required>

  <label for="message">Message</label>
  <textarea id="message" name="message" rows="5" minlength="10" required></textarea>

  <button type="submit">Send message</button>
</form>

Form attributes

Attribute Purpose
action URL that receives the data
method get (data in URL, for searches) or post (data in the request body)
enctype Set to multipart/form-data for file uploads
novalidate Turns off browser validation (when using custom JavaScript validation)

Useful input types

Type Use Mobile benefit
email Email addresses Keyboard with @
tel Phone numbers Number pad
number Quantities Numeric keyboard and spinner
date Dates Native date picker
url Web addresses Keyboard with .com and /
checkbox / radio Multiple or single choice —
file Uploads Access to camera and files

Built-in validation

<input type="text" name="postcode" required pattern="[A-Za-z0-9 ]{3,10}"
       title="Enter a valid postcode">
<input type="number" name="guests" min="1" max="10">
<input type="password" name="password" minlength="12" autocomplete="new-password">

Warning: Browser validation is a convenience, not security. Anyone can bypass it, so validate and sanitise every field on the server, and protect forms against spam and CSRF.

Screenshot or photo that supports “Built-in validation” in a guide about html forms

Accessible forms checklist

  • Every field has a visible <label> linked with for and id.
  • Group related options with <fieldset> and <legend>.
  • Use autocomplete values to help users and password managers.
  • Show clear error messages next to the field, not only in colour.
  • Make sure the form works with the keyboard alone.

Styling forms

input, textarea, select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #CBD5E1;
  border-radius: 8px;
  font: inherit;
}
input:focus-visible, textarea:focus-visible {
  outline: 3px solid #1D5FB4;
  outline-offset: 2px;
}
input:user-invalid { border-color: #B91C1C; }

Usability tips that improve completion

  • Put labels above fields so they stay visible while typing.
  • Use the right input types so phones show the right keyboard.
  • Group related fields with fieldset and legend.
  • Mark optional fields rather than every required field, if most are required.
  • Show helpful error messages next to the field.
  • Keep the submit button text specific, such as “Send enquiry”.
Checklist graphic summarising “Usability tips that improve completion”

Autocomplete values that save time

Field autocomplete value
Full name name
Email email
Phone tel
Street address street-address
Postcode / ZIP postal-code
New password new-password

Test your form

  1. Keyboard onlyComplete the form using Tab, Shift+Tab and Enter.
  2. Screen readerCheck labels are read correctly.
  3. MobileCheck keyboards and spacing.
  4. ErrorsSubmit empty and invalid data.
  5. DeliveryConfirm submissions reach their destination.

Continue with HTML guides, try HTML projects for beginners, or add a form to WordPress with our contact form plugins list.

Frequently asked questions

How do I create a form in HTML?

Use a form element with an action and method, add inputs with labels and name attributes, and include a submit button.

What is the difference between GET and POST in forms?

GET sends data in the URL and suits searches. POST sends data in the request body and suits sensitive or larger submissions.

Can HTML forms send email by themselves?

No. A form needs a server-side script or a form service to process the data and send email.

How do I make a field required in HTML?

Add the required attribute to the input, textarea or select element.

Should I use placeholder text instead of labels?

No. Placeholders disappear when typing and are often low contrast. Use visible labels and optional placeholder hints.

How do I add a file upload to a form?

Use an input with type=”file” and set the form’s enctype to multipart/form-data. Validate file types and sizes on the server.

Can I style checkboxes and radio buttons?

Yes, with CSS, while keeping native inputs accessible. Modern CSS such as accent-color makes simple styling easy.


Further reading: MDN’s web development learning area.

First published November 17, 2026 · Last updated November 26, 2026