HTML input element

Reference for the HTML input element: void content model, common type groups, constraint validation versus the server, and disabled versus readonly.

The input element is a void element: it has no end tag and no children. Its behavior is controlled mainly by type. The missing value default and invalid value default for type are text. This page deepens the catalog card for <input> and groups common types instead of listing every state as a separate page.

A name is required for the control to be submitted. The value attribute supplies the initial value (and the submitted value for checkbox, radio, and some button types). A placeholder is a hint, not a label. Associate a label with for and id, or by wrapping the control.

Examples are structural markup only. Constraint validation UI, focus, file pickers, and form submission were not executed in a browser here.

Official sources: MDN <input> element and the WHATWG HTML Living Standard. Fragments were checked with Python 3.13 html.parser. That parser builds an element tree; it is not a WHATWG conformance checker, and this is not a browser or accessibility test.

HTML tag catalog → · HTML tutorial overview →

Void element and common type groups

Group the usual type values by what they collect. Textual types include text (the default), search, email, url, tel, and password. Numeric types include number and range. Date and time types include date, time, datetime-local, month, and week. checkbox is an independent on/off flag. radio buttons that share a name form one group. file chooses files. hidden carries a value that is not shown. submit, reset, button, and image are button-like and are usually better written as a button element when you need visible content inside the control.

color is a color well. Support and the exact picker UI vary by user agent and were not tested here. The example below uses one control from several common groups, including a radio group and a file input.

Common input types in one form

<input type="text">
<input type="email" required>
<input type="number" min max>
<input type="radio" name>
<input type="checkbox">
<input type="file">
<input type="hidden">

type selects the control kind. The default type is text. This is one form, not six separate pages.

AttributeDescription
typeThe control kind. The default is text. Invalid values are also treated as text.
nameThe submitted key. Nameless controls are not successful.
valueInitial value, or the submitted value for checkbox, radio, and some button types.
checkedFor checkbox and radio, the initial on state. Only the checked radio in a name group is successful.
acceptFor file inputs, a hint for allowed file types. It is not a security check.
min, max, step, maxlengthConstraints for types that support them. They affect client validation and some steppers, not server enforcement.
  • accept and required are hints or client checks. They do not inspect or upload a user file in this documentation, and they do not replace server-side checks.
html
<form>
  <p>
    <label for="title">Title</label>
    <input id="title" name="title" type="text" maxlength="80">
  </p>
  <p>
    <label for="email">Email</label>
    <input id="email" name="email" type="email" required>
  </p>
  <p>
    <label for="qty">Quantity</label>
    <input id="qty" name="qty" type="number" min="1" max="9" value="1">
  </p>
  <fieldset>
    <legend>Format</legend>
    <label><input type="radio" name="format" value="html" checked> HTML</label>
    <label><input type="radio" name="format" value="text"> Plain text</label>
  </fieldset>
  <p>
    <label><input type="checkbox" name="draft" value="1"> Save as draft</label>
  </p>
  <p>
    <label for="photo">Photo</label>
    <input id="photo" name="photo" type="file" accept="image/png,image/jpeg">
  </p>
  <input type="hidden" name="step" value="practice">
  <button type="submit">Check locally</button>
</form>

What this markup means

The form demonstrates textual, numeric, radio, checkbox, file, and hidden inputs together. type="email" plus required is only a client constraint. The file input does not upload a file from this page. There is no third-party action.

Related: Tag catalog: <input>, <form>, <button>, <label>, <select>, <textarea>

MDN documentation → · WHATWG HTML Standard →

Constraint validation cannot replace the server

Attributes such as required, min, max, minlength, maxlength, step, pattern, and type-specific checks (for example email or url) participate in HTML constraint validation. A form may set novalidate to skip those checks on submit. Browsers can also show a validation message. None of that was executed here.

Constraint validation is a user-interface convenience. It can be bypassed: the request can be built outside the page, required fields can be omitted, and types can be ignored. Never treat a required email field, a pattern, or a hidden input as authorization or as proof that a value is safe. Validate again on the server, and do not collect real personal data in practice forms.

disabled versus readonly

disabled and readonly are not interchangeable. A disabled input is not editable, is not focusable in ordinary use, is barred from constraint validation, and is not a successful control, so its name and value are not submitted. A readonly input is not editable, but it can still be focused, and it can still be submitted.

readonly applies to textual, numeric, and date/time types that support it. It does not apply to checkbox, radio, file, hidden, range, color, or the button-like types. disabled applies to input generally.

readonly is submitted; disabled is not

<input readonly>
<input disabled>

readonly keeps the value in the submission set. disabled removes the control from submission.

AttributeDescription
readonlyBoolean. The value is not editable but can still be submitted. Not used on checkbox, radio, file, hidden, range, color, or button-like types.
disabledBoolean. The control is not editable, not ordinarily focusable, not validated, and not submitted.
  • This is a markup contrast, not a measured tab-order or submit payload from a browser.
html
<form>
  <p>
    <label for="locked">Read-only token</label>
    <input id="locked" name="token" value="demo-token" readonly>
  </p>
  <p>
    <label for="off">Disabled token</label>
    <input id="off" name="token-off" value="demo-token" disabled>
  </p>
  <button type="submit">Check locally</button>
</form>

What this markup means

If this form were submitted, the readonly token field would be a successful control named token. The disabled field named token-off would be omitted. The values are dummy documentation strings, not secrets, and the form has no remote action.

Related: <button> disabled, <textarea> readonly and disabled, <form>

MDN documentation → · WHATWG HTML Standard →