Back to HTML

Input Types and When to Use Each One

Coding Tutorials Team 2 July 2026

The input element takes many forms depending on its type attribute, and the choice affects far more than appearance. It determines which keyboard appears on a phone, what validation the browser applies, and how autofill behaves.

Text and its relatives

The default type is text, a single line field with no validation. It is the right choice whenever the content does not fit a more specific type.

The email type validates that the value resembles an address and brings up a keyboard with the at symbol and full stop readily available. The url type does the same for web addresses. The search type is functionally a text field, and browsers often add a clear button and style it distinctively.

The tel type applies no validation, because phone number formats vary too widely for any useful rule, but it does bring up a numeric keypad, which is the practical benefit.

Password

The password type masks the characters as they are typed. That is all it does, and it is worth being clear that it provides no security by itself. The value is transmitted exactly like any other field, so an encrypted connection is what protects it.

Masking has usability costs, which is why a reveal toggle has become standard. Blocking paste into a password field is a habit worth abandoning, since it prevents the use of password managers and pushes people towards simpler passwords they can type by hand.

The number type and its problems

The number type accepts numeric values, offers stepper arrows and a numeric keyboard, and supports minimum, maximum and step constraints.

It is appropriate for quantities where arithmetic makes sense: a count, an age, a price. It is a poor choice for anything that merely consists of digits, such as a postcode, a card number or a reference. Those are strings, and the number type will strip leading zeros, reject spaces and hyphens people naturally type, and offer stepper arrows that make no sense on a card number.

A further quirk is that scrolling over the field can change its value in some browsers, which produces edits nobody intended. For digit strings, a text input with an appropriate input mode is the better answer.

Dates and times

Date, time, month, week and datetime-local each present a native picker. On mobile these are excellent, since the operating system provides an interface people already know.

On desktop the pickers vary considerably between browsers and cannot be styled, which is the usual reason projects replace them with a scripted alternative. Before doing so, weigh what is lost: the native controls are keyboard accessible, work with assistive technology, and respect the user's locale for display order while submitting a consistent format.

The submitted value is always in a standard year, month, day format regardless of how it is displayed, which is one of the more useful things the type does.

Choices

Checkbox allows any number of independent selections. Radio allows exactly one from a group, and grouping is established by sharing a name attribute rather than by any container.

Both send nothing when unselected, and both need a value attribute, or a checked box submits a default that carries no meaning.

File, colour and range

The file type opens a picker and requires the form to use POST with multipart encoding. The accept attribute filters which files are offered, and the multiple attribute allows several.

The colour type opens a colour picker and returns a hexadecimal value. The range type presents a slider, which is appropriate when the precise value does not matter and inappropriate when it does, since a slider makes exact input difficult and shows no value at all unless you display one.

Hidden and its limits

A hidden input carries a value the user does not see, commonly a record identifier or a security token. It is not secret in any sense, since anyone can read it in the page source and change it before submitting.

This is worth stating plainly because hidden fields are regularly used to carry values a server then trusts. A price in a hidden field is an invitation, and every value arriving from a form must be validated on the server regardless of where it came from.

Unknown types fall back to text

A type the browser does not recognise is treated as text, which makes newer types safe to adopt. The field still works, it simply lacks the enhanced interface, so there is no reason to avoid a type on compatibility grounds.