HTML input attributes are extra settings you write inside an <input> tag to control what the field shows, what the user can type and how the browser checks the value before the form is sent. This guide explains 20 of the most used input attributes with a short example for each, compares readonly and disabled, and ends with a 25-question MCQ quiz for diploma, engineering, BCA and BCS students and freshers. If you are new to forms, first read our HTML input types MCQ guide.
Basic HTML Input Attributes
These attributes appear in almost every form. They name the field, give it a starting value and help the user understand what to type.
- name: the key under which the value is sent to the server, for example
username=quizlancer. A field without a name is not submitted. - value: the starting value of the field. It is sent with the form unless the user changes it.
- placeholder: a grey hint shown inside the empty field. It disappears when the user types and is never submitted.
- id: a unique name in the page, used to connect a
<label for="...">to the field and by CSS and JavaScript. - size: the visible width of the box in characters. It does not limit how much the user can type.
- autofocus: puts the cursor in the field when the page loads. Use it on one field only.
<label for="username">Username</label>
<input type="text" id="username" name="username" placeholder="Enter your username" size="30" autofocus>Validation Attributes
Validation attributes let the browser check the value before the form is sent. If a check fails, the browser blocks the submit and shows a message next to the field. Always check the data again on the server too, because a user can change the HTML in the browser.
- required: the field cannot be empty.
- minlength and maxlength: the smallest and largest number of characters allowed in a text field.
- min and max: the smallest and largest value allowed in a number, range or date field.
- step: the allowed gap between values. With
min="0" step="5", only 0, 5, 10, 15 and so on are valid. - pattern: a regular expression the whole value must match. Add a
titlethat explains the format, because browsers show it in the error message.
<input type="password" name="password" required minlength="8" maxlength="20">
<input type="number" name="marks" min="0" max="100" step="5">
<input type="text" name="pincode" pattern="[0-9]{6}" title="Enter a 6-digit PIN code">
readonly vs disabled
Both attributes stop the user from editing a field, but they behave very differently when the form is submitted. This is one of the most common interview questions on HTML input attributes.
| Feature | readonly | disabled |
|---|---|---|
| User can edit | No | No |
| User can focus and copy | Yes | No |
| Value sent with the form | Yes | No |
| Checked by required, pattern and so on | No | No |
| Usual look | Normal | Greyed out |
| Typical use | Show a fixed value that must be sent, like an order ID | Turn off a field until another choice is made |
<input type="text" name="order_id" value="QL-1024" readonly>
<input type="text" name="coupon" value="SAVE10" disabled>In this example, the server receives order_id=QL-1024 but no coupon value at all.
Autocomplete, inputmode and Other Useful Attributes
- autocomplete: tells the browser what kind of data the field holds so it can suggest saved values. Use
offto stop suggestions,emailorusernameon login forms, andnew-passwordon sign-up forms so the browser does not fill an old password and can suggest a strong one. - inputmode: chooses the on-screen keyboard on phones, for example
numericfor a number keypad. It does not validate the value. - multiple: allows more than one file in
type="file", or more than one email address intype="email". - list: connects the field to a
<datalist>of suggestions. The user can still type any value. - aria-label: gives the field a name for screen readers when there is no visible label.
<input type="email" name="email" autocomplete="email" required>
<input type="password" name="new_pass" autocomplete="new-password" minlength="8">
<input type="text" name="otp" inputmode="numeric" maxlength="6">
<input type="file" name="photos" multiple>
<input list="cities" name="city">
<datalist id="cities">
<option value="Pune">
<option value="Mumbai">
<option value="Nashik">
</datalist>You can read the full list of input attributes in the MDN input element reference.
HTML Input Attributes MCQ Quiz
Test yourself now. The quiz has a pool of 25 questions and every attempt gives you 10 random ones. Press Submit at the end to see your score, the correct answers and a short explanation for each question.
Frequently Asked Questions
What is the difference between placeholder and value?
value is real text in the field and is sent with the form. placeholder is only a hint that disappears when the user types and is never sent.
What is the difference between maxlength and max?
maxlength limits the number of characters in a text field. max limits the largest value in a number, range or date field.
Is browser validation enough?
No. Attributes like required and pattern give quick feedback to the user, but anyone can remove them in the browser. Always validate the data again on the server, for example in PHP.
Conclusion
HTML input attributes turn a plain box into a useful form field: name and value carry the data, required, pattern and the length and range attributes check it, and readonly, disabled, autocomplete and inputmode control how the user interacts with it. Try each example in a test file, then take the quiz above and read the explanations for any answer you got wrong.
Get one new quiz every week. Join Quiz Lancer on Telegram →
Full-stack developer with 5+ years of experience in PHP, Laravel and JavaScript. I create these quizzes to help students and freshers prepare for web development interviews.



