logo

Very Short Question and Answers - Input Elements


Q 1.
What is an input element in HTML?

Ans:

An input element is a building block of HTML forms that allows users to enter data or make choices on a webpage.

Q 2.
Which attribute of the <input> tag is used to specify the kind of input control?

Ans:

The 'type' attribute is used to specify the kind of input control in the <input> tag.

Q 3.
Name two input types that allow a user to enter information as text.

Ans:

The two input types are 'text' and 'password'.

Q 4.
What is the main difference between a checkbox and a radio button?

Ans:

Checkboxes allow multiple selections, while radio buttons allow only one choice in a group.

Q 5.
Write the syntax for creating a textbox for entering a username.

Ans:

<input type="text" name="username" />

Q 6.
List any two attributes of a textbox input and mention their purpose.

Ans:

'placeholder' shows hint text inside the textbox, while 'maxlength' limits the number of characters the user can enter.

Q 7.
How can you set a default value for a textbox?

Ans:

By using the 'value' attribute, e.g.,

<input type="text" value="default text">
Q 8.
How do you make a checkbox selected by default?

Ans:

By adding the 'checked' attribute, e.g.,

<input type="checkbox" checked />
Q 9.
Why should all radio buttons in a group have the same 'name' attribute?

Ans:

So that only one option in that group can be selected at a time.

Q 10.
Give an example of HTML code to create two radio buttons for selecting gender.

Ans:

<input type="radio" name="gender" value="male"> Male 
<input type="radio" name="gender" value="female"> Female
Q 11.
How does a password field improve privacy compared to a normal text field?

Ans:

A password field hides the entered characters using dots or stars, preventing others from seeing what is entered.

Q 12.
Which input type would you use to let users select multiple hobbies?

Ans:

The 'checkbox' input type.

Q 13.
Write the syntax for an input field that only allows up to 10 characters.

Ans:

<input type="text" maxlength="10">

Q 14.
What does the 'placeholder' attribute do in a textbox?

Ans:

It displays a hint inside the textbox before the user enters any data.

Q 15.
Explain the use of the 'value' attribute in a checkbox input.

Ans:

The 'value' attribute specifies the data sent to the server if the checkbox is checked.

Q 16.
What do the <input type="submit"> and <input type="reset"> buttons do in a form?

Ans:

'submit' sends the form data to the server, while 'reset' clears all the inputs in the form.

Q 17.
How do you create a password field for a user to enter a password?

Ans:

By using <input type="password" name="userpwd">

Q 18.
If you want only 'Reading' to be checked in a list of three hobbies by default, what attribute should you use?

Ans:

Add the 'checked' attribute to the 'Reading' checkbox input.

Q 19.
Why is the 'name' attribute important in <input> elements?

Ans:

Because it identifies the data and is needed to send the input information to the server.

Q 20.
Summarize the main uses of 'textbox', 'checkbox', 'radio button', and 'password' input types.

Ans:

Textbox: for single-line text input; Checkbox: for multiple selections; Radio button: for one choice among many; Password: for hidden/confidential text input.