Tag input

The input tag is used to create interactive form elements that allow users to input data. It is a self-closing tag and forms the backbone of most web forms.


🔧 Basic Syntax:

<input type="text" name="username" placeholder="Enter your name">

🧩 Common Attributes:

AttributeDescription
typeSpecifies the type of input (e.g. text, password, email, checkbox).
nameName of the input field (used when submitting form data).
valueSets the default value.
placeholderDisplays hint text inside the input field.
requiredMakes the input mandatory to fill out.
readonlyMakes the input non-editable.
disabledDisables the input (grayed out and unclickable).
maxlengthSets the maximum number of characters allowed.
min / maxFor numeric/date input types, defines limits.
stepFor number inputs, defines the step size.

✅ Common Input Types:

type ValueDescription
textSingle-line text input
passwordHides typed characters
emailValidates email format
numberNumeric input with step, min, max
checkboxAllows toggling on/off
radioSelect one from a group
submitSubmit button for the form
buttonCustom button (needs JS for actions)
dateDate picker
fileFile upload input
rangeSlider input
colorColor picker

🧪 Example (Login Form):

<form action="/login" method="post">
<input type="text" name="username" placeholder="Username" required>
<input type="password" name="password" placeholder="Password" required>
<input type="submit" value="Login">
</form>

🧠 Best Practices:

  • Always pair <input> fields with <label> elements for accessibility.
  • Use requiredpattern, and type to validate input client-side.
  • Group related radio buttons using the same name value.
  • Keep usability and mobile-friendliness in mind (use correct type).