Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Enhancing Forms with Input Attributes | HTML Forms and User Input
Ultimate HTML

bookEnhancing 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.
Note
Note

value cannot be used with type="file".

index.html

index.html

copy

autofocus

Automatically focuses an input when the page loads.

Note
Note

It doesn't work in the example below because, when you press Run Code, the page doesn't reload.

index.html

index.html

copy

required

Makes an input mandatory. The form cannot be submitted until the field is filled.

index.html

index.html

copy

placeholder

Displays helper text inside the input until the user types. Useful for formats like phone numbers or card details.

index.html

index.html

copy
Note
Note

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?

question mark

Which attribute is used to set the default value for an input element?

Select the correct answer

question mark

Which attribute is used to set a hint or an example of the expected value for an input element?

Select the correct answer

question mark

Which attribute is used to specify that an input field must be filled out before submitting the form?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 4

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

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?

bookEnhancing 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.
Note
Note

value cannot be used with type="file".

index.html

index.html

copy

autofocus

Automatically focuses an input when the page loads.

Note
Note

It doesn't work in the example below because, when you press Run Code, the page doesn't reload.

index.html

index.html

copy

required

Makes an input mandatory. The form cannot be submitted until the field is filled.

index.html

index.html

copy

placeholder

Displays helper text inside the input until the user types. Useful for formats like phone numbers or card details.

index.html

index.html

copy
Note
Note

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?

question mark

Which attribute is used to set the default value for an input element?

Select the correct answer

question mark

Which attribute is used to set a hint or an example of the expected value for an input element?

Select the correct answer

question mark

Which attribute is used to specify that an input field must be filled out before submitting the form?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 4
some-alt