html forms mcq with answers improve your preparation

HTML Forms are a very important topic in HTML. They are used to collect data from users. By taking this MCQ test, you can improve your understanding of the HTML Forms topic. In this test

Q1. Which of the following is NOT an HTML form attribute?

type
value
<label>
maxlength
✅ Correct Answer: <label>

label is not an HTML form attribute. It is an HTML tag used to provide a label or name for an input field.

Q2. In the following code <input type='text'>, identify the attribute.

input
type
text
none of these
✅ Correct Answer: type

In this code, 'type' is an attribute, 'input' is the tag, and 'text' is the value of the attribute.

Q3. What is the use of the 'required' attribute?

The field can be left empty
The field must be filled after form submission
The field must be filled
none of these
✅ Correct Answer: The field must be filled

The required attribute makes a field mandatory. The user must fill the field before submitting the form.

Q4. Which tag is used when we want to take a large amount of text input from the user?

<input>
<textarea>
<label>
<bigtext>
✅ Correct Answer: <textarea>

When we need to take a large amount of text from the user, we use the <textarea> tag in HTML forms.

Q5. Which tag is used to create a dropdown list in an HTML form?

select
option
radio
A and B both
✅ Correct Answer: A and B both

In HTML forms, the <select> tag is used to create a dropdown list and the <option> tag is used to define the options inside it.

Q6. Choose the correct code to take a telephone number from the user.

<input type='tel'>
<input type='phone'>
<input type='nm'>
<input type='enter no'>
✅ Correct Answer: <input type='tel'>

To take a telephone number from the user, we use the value 'tel' in the type attribute. It often opens a numeric keypad on mobile devices.

Q7. Which code allows a user to choose a color in an HTML form?

<input type='chosecolor' name='favcolor'>
<input type='color' name='favcolor'>
<input type='color name' name='favcolor'>
all of these
✅ Correct Answer: <input type='color' name='favcolor'>

When we want to allow the user to choose a color, we use the value 'color' in the type attribute. This displays a color picker for the user.

Q8. What will be the output of the code <input type='text' maxlength='20'> ?

The user cannot enter more than 20 characters in the text field
The user cannot enter less than 20 characters in the text field
The user cannot enter text
The user can only enter numbers
✅ Correct Answer: The user cannot enter more than 20 characters in the text field

The maxlength attribute defines the maximum number of characters allowed in the input field. In this case, the user can enter up to 20 characters only.

Q9. Which attribute is used in a form to specify where the data should be sent?

method
action
autocomplete
novalidate
✅ Correct Answer: action

The action attribute is used to specify the URL or location where the form data will be sent after submission.

Q10. Which of the following tags is NOT used to take input from the user?

<input>
<select>
<textarea>
<p>
✅ Correct Answer: <p>

The <p> tag is used to write a paragraph in HTML and is not used to take input from the user.