iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

HTML Input Attributes

Beyond type, the <input> element accepts a long list of attributes that control validation, behaviour, and presentation.

Common input attributes

AttributePurpose
nameKey used when the form is submitted.
valueThe current (or default) value.
placeholderHint text shown when the field is empty.
requiredForm won't submit until this field is filled.
readonlyUser can't change the value (but it is still submitted).
disabledUser can't interact, and the value is not submitted.
min / max / stepNumeric range for number, range, dates.
minlength / maxlengthString length limits.
patternA regex the value must match.
autocompleteTells the browser what kind of value it is (email, given-name, cc-number…).
autofocusReceive focus when the page loads.
multipleAccept multiple values (for email, file).
Tip: Set autocomplete for known field types. Browsers and password managers fill faster, and passkey flows work better.

Example

Example
<!DOCTYPE html>
<html>
<head>
    <title>HTML Input Attributes</title>
</head>
<body>

<h1>HTML Input Attributes</h1>
<p>This is a demo page for the "HTML Input Attributes" lesson.</p>

</body>
</html>
Try it Yourself »

Exercise

Make this input required before the form can submit.

<input type="email" >

Test yourself

Q1. Mark a field as required with…
Q2. Built-in pattern validation uses…
Q3. Default value on an input is set with…

Discussion

Loading…