Bhylu

HTML Input Attributes

Input attributes describe initial values, constraints, and usability hints. They improve the browser experience, while the server remains responsible for deciding whether submitted data is acceptable.

How it works

  • required prevents an empty required control from passing ordinary browser validation. minlength, maxlength, min, max, and step apply only to relevant input types.
  • readonly generally keeps a supported control’s value in submission while preventing edits. disabled controls are unavailable and normally omitted from submitted form data.
  • autocomplete and inputmode are hints. pattern checks a text value against a pattern, but a useful label and visible instruction should explain the required format.

A practical example

HTML

<label for="booking-code">Booking code</label>
<p id="booking-hint">Two capital letters followed by four digits, such as AB2048.</p>
<input id="booking-code" name="booking_code"
       pattern="[A-Z]{2}[0-9]{4}" required
       aria-describedby="booking-hint" autocomplete="off">

An ordinary form submission can be blocked if the code does not match the requested shape. Your server should repeat the rule and show a useful error message.