Tuesday, July 7, 2026

HTML INPUT ATTRIBUTES | HTML REQUIRED ATTRIBUTES

HTML input attributes are properties that control the behavior, appearance, and validation of the <input> element in HTML forms.

Here are some common HTML input attributes:

AttributeDescriptionExample
typeSpecifies the type of input.<input type="text">
nameIdentifies the input when submitting a form.<input name="username">
valueSets the initial value.<input value="John">
placeholderDisplays hint text.<input placeholder="Enter your name">
requiredMakes the field mandatory.<input required>
readonlyPrevents editing of the input.<input readonly>
disabledDisables the input field.<input disabled>
maxlengthSets the maximum number of characters.<input maxlength="20">
minlengthSets the minimum number of characters.<input minlength="5">
minSpecifies the minimum value (for number/date inputs).<input type="number" min="1">
maxSpecifies the maximum value.<input type="number" max="100">
stepSpecifies valid intervals for numeric values.<input type="number" step="5">
checkedPre-selects a checkbox or radio button.<input type="checkbox" checked>
multipleAllows multiple file or email selections.<input type="file" multiple>
acceptRestricts file types for file uploads.<input type="file" accept=".jpg,.png">
patternSpecifies a regular expression for validation.<input pattern="[A-Za-z]{3,}">
autocompleteEnables or disables autocomplete.<input autocomplete="off">
autofocusAutomatically focuses the input on page load.<input autofocus>
sizeSets the visible width of the input.<input size="30">

Example

<form>
  <label>Name:</label>
  <input
    type="text"
    name="username"
    placeholder="Enter your name"
    required
    maxlength="30"
    autofocus
  >

  <br><br>

  <label>Age:</label>
  <input
    type="number"
    min="1"
    max="120"
    required
  >

  <br><br>

  <input type="submit" value="Submit">
</form>

These attributes help define how users interact with form fields, enforce input rules, and improve the overall user experience.

No comments:

Post a Comment