Enhancing Forms with Input Attributes
HTML <input> elements can be customized with attributes that change how they behave. Below are some of the most commonly used ones.
value
Sets the initial value of an input.
- For buttons: defines the button text;
- For text/password fields: sets the default text;
- For checkboxes/radios: sets the value sent when selected.
value cannot be used with type="file".
index.html
autofocus
Automatically focuses an input when the page loads.
It doesn't work in the example below because, when you press Run Code, the page doesn't reload.
index.html
required
Makes an input mandatory. The form cannot be submitted until the field is filled.
index.html
placeholder
Displays helper text inside the input until the user types. Useful for formats like phone numbers or card details.
index.html
Each example uses different type attributes, which affect how the input behaves. You'll explore input types in the next chapter.
1. Which attribute is used to set the default value for an input element?
2. Which attribute is used to set a hint or an example of the expected value for an input element?
3. Which attribute is used to specify that an input field must be filled out before submitting the form?
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Can you give examples of how to use these attributes in HTML?
What other input attributes are commonly used?
Can you explain the difference between value and placeholder?
Awesome!
Completion rate improved to 2.38
Enhancing Forms with Input Attributes
Swipe to show menu
HTML <input> elements can be customized with attributes that change how they behave. Below are some of the most commonly used ones.
value
Sets the initial value of an input.
- For buttons: defines the button text;
- For text/password fields: sets the default text;
- For checkboxes/radios: sets the value sent when selected.
value cannot be used with type="file".
index.html
autofocus
Automatically focuses an input when the page loads.
It doesn't work in the example below because, when you press Run Code, the page doesn't reload.
index.html
required
Makes an input mandatory. The form cannot be submitted until the field is filled.
index.html
placeholder
Displays helper text inside the input until the user types. Useful for formats like phone numbers or card details.
index.html
Each example uses different type attributes, which affect how the input behaves. You'll explore input types in the next chapter.
1. Which attribute is used to set the default value for an input element?
2. Which attribute is used to set a hint or an example of the expected value for an input element?
3. Which attribute is used to specify that an input field must be filled out before submitting the form?
Thanks for your feedback!