</> Code Corner

HTML · HTML Forms · Lesson 44

HTML Input Attributes

value, placeholder, required, min, max, pattern…

Input attributes control default values, validation and behaviour.

Example

<form>
  <input type="text" value="John" readonly><br><br>
  <input type="text" placeholder="Disabled" disabled><br><br>
  <input type="text" placeholder="Required" required><br><br>
  <input type="text" maxlength="4" placeholder="Max 4 chars"><br><br>
  <input type="number" min="1" max="10" step="2"><br><br>
  <input type="text" pattern="[A-Za-z]{3}" title="Three letter country code"><br><br>
  <input type="text" autofocus placeholder="I am focused">
  <input type="submit">
</form>
Attribute Description
value Initial value
readonly Cannot be changed, but is submitted
disabled Unusable and not submitted
required Must be filled in before submitting
maxlength Maximum number of characters
min / max / step Numeric limits and steps
pattern Regular expression the value must match
placeholder Hint text shown when empty
autofocus Focus the input when the page loads

Keep reading “HTML Input Attributes”

Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.

Chat with us 👋