Required, Disabled, and Readonly Attributes
You'll learn how to control whether users can interact with form inputs and whether they must fill them out before submitting.
When building forms, you often need to control how users interact with your input fields. HTML gives you three powerful attributes to manage this behavior: required, disabled, and readonly.
The required Attribute
The required attribute tells the browser that a field must be filled out before the form can be submitted. Think of it like a bouncer at a club checking for ID—you can't get past without it.
<input type="email" name="user_email" required>
When users try to submit without completing required fields, the browser automatically shows an error message.
The disabled Attribute
The disabled attribute makes an input field completely off-limits. Users can't click it, type in it, or interact with it at all. The field appears grayed out and its value won't be sent when the form submits. It's like a museum exhibit behind glass—you can see it, but you can't touch it.
<input type="text" name="username" value="admin" disabled>
The readonly Attribute
The readonly attribute is more subtle. Users can see and select the text, but they cannot change it. Unlike disabled, the value will be submitted with the form. Think of it like reading a laminated menu—you can look at it all you want, but you can't mark it up.
<input type="text" name="order_id" value="12345" readonly>
Key Takeaway: Use required to enforce form completion, disabled to completely prevent interaction (and submission), and readonly to display unchangeable values that still get submitted.