HTML · Chapter 38 of 45

HTML Input Attributes

Input elements support attributes that fine-tune behavior: value (default/current content), maxlength (character limit), min/max (numeric or date ranges), and readonly/disabled to control editability.

disabled fields are not submitted with the form and appear greyed out, while readonly fields are submitted but cannot be edited by the user.

Syntax
<input type="number" min="1" max="10">

Limiting input

maxlength restricts the number of characters allowed. min and max set boundaries for number, date, or range inputs.

disabled vs readonly

disabled fields are excluded from form submission entirely and can't be focused. readonly fields are still submitted but the user can't change their value.

Example 1 (html)
<input type="text" maxlength="10" value="Hello">
Output
(field pre-filled with 'Hello', max 10 characters)

value sets a default and maxlength caps how much more the user can type.

Example 2 (html)
<input type="number" min="1" max="5" value="3">
<input type="text" value="Locked" readonly>
Output
(number limited 1-5; text field shown but not editable)

min/max bound numeric input; readonly prevents edits but still submits the value.

Key points

  • value sets the default/current content of an input.
  • maxlength limits how many characters can be entered.
  • min and max bound numeric, date, or range values.
  • disabled excludes a field from submission; readonly does not.
💡 Note: Use disabled for fields that should never be submitted, and readonly for fields that must be visible but locked.

📝 Quick Quiz

1. Which attribute limits the number of characters typed?

2. What is the difference between disabled and readonly?

3. Which attributes bound numeric input ranges?