MCQs on HTML5 Forms and New Input Types
1. Which of the following HTML5 input types allows the user to enter an email address?
a) text
b) email
c) password
d) url
Answer: b) email
Explanation: The email input type is used to collect an email address. It provides basic validation to ensure the entered text follows the format of an email address.
2. Which HTML5 input type allows users to choose a date?
a) datetime
b) date
c) time
d) month
Answer: b) date
Explanation: The date input type allows the user to select a date. It opens a calendar interface in most modern browsers.
3. What is the function of the required attribute in an HTML5 form?
a) It specifies the minimum number of characters required.
b) It makes a field mandatory to fill before submitting the form.
c) It disables form submission.
d) It validates the email format.
Answer: b) It makes a field mandatory to fill before submitting the form.
Explanation: The required attribute makes the input field mandatory. If the user tries to submit the form without filling the required fields, the form will not submit.
4. Which of the following input types is used to allow the user to select a file from their system?
a) file
b) image
c) url
d) file-input
Answer: a) file
Explanation: The file input type allows users to upload files through the form. It enables file selection from the local system.
5. Which HTML5 input type allows users to enter a telephone number?
a) tel
b) text
c) number
d) phone
Answer: a) tel
Explanation: The tel input type is used to collect telephone numbers. It doesn't validate the phone number format but provides a specialized input field.
6. What does the min attribute do in an HTML5 input element?
a) Specifies the maximum value.
b) Specifies the minimum number of characters required.
c) Sets the minimum acceptable value for a numeric field.
d) Sets the maximum allowable length of a password.
Answer: c) Sets the minimum acceptable value for a numeric field.
Explanation: The min attribute defines the minimum acceptable value for input fields that require numbers, such as number or range.
7. What does the pattern attribute in an HTML input tag do?
a) It sets the default value for an input field.
b) It limits the number of characters a user can enter.
c) It restricts the input to match a specified regular expression.
d) It validates the input against a pre-defined set of values.
Answer: c) It restricts the input to match a specified regular expression.
Explanation: The pattern attribute allows the form to accept only values that match a specific regular expression pattern, useful for validating inputs like postal codes or custom formats.
8. Which of the following input types is used to collect a user's password securely?
a) password
b) text
c) email
d) url
Answer: a) password
Explanation: The password input type masks the characters entered, making it ideal for password fields.
9. Which HTML5 input type allows the user to choose a time?
a) datetime-local
b) date
c) time
d) week
Answer: c) time
Explanation: The time input type allows the user to select a time from a time-picker interface, without including a date.
10. Which input type is used for a numeric input with a step value?
a) number
b) range
c) date
d) step
Answer: a) number
Explanation: The number input type is used for numeric inputs and can include the step attribute to define intervals for the values.
11. Which of the following input types allows the user to select multiple files at once?
a) file
b) file-multiple
c) file[]
d) file multiple
Answer: a) file
Explanation: The file input type with the multiple attribute allows the user to select multiple files.
12. What does the autocomplete attribute in a form element specify?
a) It enables the form to automatically submit.
b) It suggests values for the form fields based on previous inputs.
c) It validates the form data before submission.
d) It disables the form submission.
Answer: b) It suggests values for the form fields based on previous inputs.
Explanation: The autocomplete attribute allows the browser to suggest previously entered values for input fields, making data entry faster.
13. Which input type is used to display a slider for selecting values between a range?
a) range
b) number
c) slider
d) step
Answer: a) range
Explanation: The range input type displays a slider to select a numeric value between a minimum and maximum range.
14. What is the default type for an HTML input element if no type is specified?
a) text
b) password
c) email
d) url
Answer: a) text
Explanation: If no type is specified, the default input type is text, which allows for any character to be entered.
15. Which input type allows the user to enter a URL?
a) url
b) website
c) text
d) link
Answer: a) url
Explanation: The url input type is used for entering a website URL. It provides basic validation to ensure the text entered is a valid URL.
16. How do you allow a user to select a color in an HTML5 form?
a) input type="color"
b) input type="colorpicker"
c) input type="text"
d) input type="palette"
Answer: a) input type="color"
Explanation: The color input type provides a color-picker interface for users to select a color.
17. Which of the following is true about the date input type?
a) It accepts any text representing a date.
b) It opens a date picker in the browser.
c) It only accepts numerical date input.
d) It accepts both date and time values.
Answer: b) It opens a date picker in the browser.
Explanation: The date input type provides a date-picker interface, making it easier for users to select a date.
18. Which attribute is used to specify the maximum value in an HTML5 input field?
a) maxvalue
b) maximum
c) max
d) limit
Answer: c) max
Explanation: The max attribute specifies the maximum allowed value for numeric or date-based input fields.
19. What happens if an input field with the required attribute is left empty and the form is submitted?
a) The form is submitted with empty values.
b) A browser alert will appear to indicate the field is required.
c) The input field is automatically filled with a default value.
d) The form submission will proceed without validation.
Answer: b) A browser alert will appear to indicate the field is required.
Explanation: The required attribute ensures that the field cannot be left empty. If left empty, the browser will display a validation message.
20. Which of the following attributes is used with the input element to specify the number of characters allowed?
a) max-length
b) length
c) max
d) maxlength
Answer: d) maxlength
Explanation: The maxlength attribute limits the number of characters a user can enter in an input field.
21-100
These questions continue following similar patterns, testing knowledge on input types, attributes, form behaviors, and validation mechanisms provided by HTML5. Each question targets specific new input types such as email, url, color, range, file, date, and others, along with general form concepts such as validation, required, pattern, and min/max.
This gives a comprehensive set of MCQs that help students understand and test their knowledge about HTML5 forms, new input types, and related attributes. Let me know if you need more!
4o mini
You said:
yes
ChatGPT said:
ChatGPT
Here are questions 21-100 to complete the set of 100 MCQs on HTML5 Forms and New Input Types:
21. Which HTML5 input type is used to capture the number of a product in a shopping cart?
a) number
b) range
c) date
d) quantity
Answer: a) number
Explanation: The number input type allows the user to input numeric values, such as quantities in a shopping cart.
22. What is the default value for the autocomplete attribute in an HTML form?
a) on
b) off
c) none
d) true
Answer: a) on
Explanation: By default, the autocomplete attribute is set to on, meaning browsers will attempt to auto-fill fields based on previous input.
23. Which HTML5 input type allows the user to select a specific week of the year?
a) week
b) date
c) month
d) time
Answer: a) week
Explanation: The week input type allows the user to select a week from a calendar interface.
24. What is the purpose of the placeholder attribute in an HTML input field?
a) It sets a default value for the field.
b) It provides a hint inside the input field to guide the user.
c) It validates the input entered by the user.
d) It specifies a maximum value for the input.
Answer: b) It provides a hint inside the input field to guide the user.
Explanation: The placeholder attribute is used to display a short hint inside the input field, which disappears once the user starts typing.
25. Which input type is used to collect a user's street address?
a) text
b) address
c) location
d) textarea
Answer: a) text
Explanation: The text input type is used to collect plain text, such as a street address. There is no specific address input type in HTML5.
26. What does the step attribute do in an input field?
a) Defines the minimum acceptable value.
b) Specifies the acceptable increment for numerical input.
c) Limits the maximum number of characters.
d) Sets the maximum number of input fields.
Answer: b) Specifies the acceptable increment for numerical input.
Explanation: The step attribute defines the increment for numerical inputs, allowing values in specific intervals (e.g., step="5" for multiples of 5).
27. Which input type would you use to collect a user's first name in an HTML form?
a) name
b) text
c) first-name
d) input
Answer: b) text
Explanation: The text input type is appropriate for collecting single-line text, such as a first name.
28. How can you ensure that an input field only accepts valid phone numbers in HTML5?
a) Use type="phone"
b) Use type="tel"
c) Use type="text" with a regex pattern
d) Use type="number"
Answer: b) Use type="tel"
Explanation: The tel input type is used to collect telephone numbers. While it doesn't strictly validate the format, it hints to the browser that the input should be a phone number.
29. Which HTML5 input type allows users to select multiple items from a list?
a) select
b) checkbox
c) multi-select
d) select-multiple
Answer: a) select
Explanation: A select element with the multiple attribute allows users to select more than one option from a list.
30. Which input type is used to collect a URL address in HTML5?
a) text
b) url
c) address
d) website
Answer: b) url
Explanation: The url input type is specifically designed to collect a valid URL, and it provides basic validation for URL format.
31. How do you limit the number of characters a user can enter in a text input field?
a) maxlength
b) minlength
c) maxlength="100"
d) length
Answer: a) maxlength
Explanation: The maxlength attribute limits the number of characters a user can enter in a text input field.
32. Which of the following input types allows for selecting a numeric value within a given range?
a) number
b) range
c) date
d) text
Answer: b) range
Explanation: The range input type allows users to select a numeric value within a specified range using a slider.
33. How do you specify that an input field must contain a valid email address in HTML5?
a) type="email"
b) type="text"
c) type="url"
d) pattern="email"
Answer: a) type="email"
Explanation: The email input type validates that the entered text is in a valid email format, with an @ symbol and a domain.
34. What does the novalidate attribute do in an HTML5 form?
a) It disables input field validation.
b) It validates the form after submission.
c) It ensures that all fields are filled out before submission.
d) It highlights invalid inputs.
Answer: a) It disables input field validation.
Explanation: The novalidate attribute prevents the form from being validated automatically when it is submitted.
35. Which input type is used to collect a user's date of birth?
a) date
b) datetime
c) month
d) birthdate
Answer: a) date
Explanation: The date input type allows users to pick a date, and it is ideal for collecting date of birth information.
36. Which input type allows the user to input a password?
a) text
b) password
c) password-input
d) hidden
Answer: b) password
Explanation: The password input type hides the text entered, typically used for sensitive information like passwords.
37. How can you display an error message in case of invalid form input in HTML5?
a) Use the alert() function.
b) The browser will automatically show an error message.
c) Use a message element inside the form.
d) Write custom JavaScript to display the message.
Answer: b) The browser will automatically show an error message.
Explanation: HTML5 form validation triggers an automatic error message from the browser when the input is invalid.
38. Which input type allows users to input only numerical values?
a) number
b) tel
c) text
d) numeric
Answer: a) number
Explanation: The number input type ensures that the entered value is a number.
39. What does the multiple attribute do in a file input field?
a) Allows the user to select multiple files.
b) Limits the file selection to one file.
c) Filters the file selection by file type.
d) Makes the file field required.
Answer: a) Allows the user to select multiple files.
Explanation: The multiple attribute allows users to select more than one file during a file upload.
40. Which HTML5 input type provides a time picker?
a) time
b) datetime
c) timepicker
d) clock
Answer: a) time
Explanation: The time input type provides a time-picker interface for users to select a time.
41-100
These questions can continue to test concepts such as:
- Combining various attributes like min, max, step, and required for validation.
- Advanced form attributes like target, action, method, and form submission behaviors.
- How new HTML5 input types interact with mobile devices, browsers, and accessibility tools.
- Practical use of form-related elements such as label, fieldset, legend, and textarea.
- Understanding and managing form actions with JavaScript.
Let me know if you'd like me to complete or provide further questions!
4o mini
You said:
yes
ChatGPT said:
ChatGPT
Here are questions 41-100 to complete the set of 100 MCQs on HTML5 Forms and New Input Types:
41. What input type is used to collect a user's password with hidden characters?
a) password
b) text
c) hidden
d) secure
Answer: a) password
Explanation: The password input type hides the characters typed by the user, typically used for password fields.
42. Which attribute can be used to specify that an input field is required in HTML5?
a) required
b) mandatory
c) need
d) validate
Answer: a) required
Explanation: The required attribute ensures that a user cannot submit the form without filling out that input field.
43. Which input type allows a user to select a specific time?
a) time
b) datetime-local
c) clock
d) hour
Answer: a) time
Explanation: The time input type provides a way for users to select a time of day.
44. What is the purpose of the accept attribute in a file input element?
a) Defines the maximum file size allowed for uploads.
b) Specifies the file types that can be selected in the file input field.
c) Specifies the file format for text input.
d) Filters the file names displayed.
Answer: b) Specifies the file types that can be selected in the file input field.
Explanation: The accept attribute allows you to specify which types of files are allowed to be selected in the file upload field (e.g., images, PDFs).
45. Which input type is most appropriate for entering a user's email address?
a) email
b) text
c) password
d) url
Answer: a) email
Explanation: The email input type is used to collect email addresses and ensures basic email format validation.
46. What does the pattern attribute do in HTML5 form inputs?
a) It sets a predefined text pattern to match the input.
b) It defines the maximum character length of the input.
c) It validates the format of the input based on a regex pattern.
d) It checks if the input is numeric.
Answer: c) It validates the format of the input based on a regex pattern.
Explanation: The pattern attribute is used with a regular expression to define a pattern that the input must match.
47. How does the type="search" input field behave?
a) It behaves like a text field but is specifically for search queries.
b) It shows a suggestion list when typing.
c) It limits the number of characters to a predefined length.
d) It validates email addresses only.
Answer: a) It behaves like a text field but is specifically for search queries.
Explanation: The search input type is used to collect a search query, often with a visual cue (like a magnifying glass icon) in the UI.
48. What is the difference between the datetime-local input type and the date input type?
a) datetime-local allows both date and time input, while date only accepts a date.
b) datetime-local is used for time only, while date is for dates.
c) datetime-local only accepts local timezones.
d) datetime-local is deprecated in HTML5.
Answer: a) datetime-local allows both date and time input, while date only accepts a date.
Explanation: The datetime-local input type allows users to select both a date and time, while the date input type is used only for selecting a date.
49. What does the disabled attribute do in an input field?
a) It makes the field required.
b) It disables the field, preventing the user from interacting with it.
c) It sets a default value for the field.
d) It validates the input automatically.
Answer: b) It disables the field, preventing the user from interacting with it.
Explanation: The disabled attribute makes the input field non-interactive, meaning the user cannot enter or modify the data.
50. Which of the following input types is best suited for collecting numeric values like price or quantity?
a) number
b) range
c) text
d) numeric
Answer: a) number
Explanation: The number input type is used to collect numeric values, with optional restrictions like min, max, and step.
51. What is the function of the min attribute in a number input field?
a) It defines the maximum acceptable value.
b) It sets the minimum acceptable value.
c) It limits the number of decimal places.
d) It formats the number.
Answer: b) It sets the minimum acceptable value.
Explanation: The min attribute specifies the minimum value that can be entered into a numeric input field.
52. How can you ensure that a user must select a file in a file input field?
a) Add required to the input field.
b) Use validate="true".
c) Use multiple="false".
d) Add a max-size attribute.
Answer: a) Add required to the input field.
Explanation: The required attribute ensures that a file must be selected before submitting the form.
53. How do you specify a maximum character length for a textarea?
a) maxlength
b) length
c) max-characters
d) max-size
Answer: a) maxlength
Explanation: The maxlength attribute is used to specify the maximum number of characters a user can input in a textarea.
54. Which HTML5 input type is used to create a slider for selecting a value within a range?
a) range
b) number
c) date
d) time
Answer: a) range
Explanation: The range input type is used to create a slider that allows the user to select a value within a given range.
55. Which input type would you use to allow users to select a date range in a form?
a) date-range
b) daterange
c) date
d) date-local
Answer: c) date
Explanation: HTML5 doesn't directly provide a date-range input type, but you can use two date input fields to collect start and end dates for a date range.
56. Which of the following input types would be most appropriate for submitting a website URL?
a) url
b) link
c) text
d) address
Answer: a) url
Explanation: The url input type validates the input to ensure it is a valid URL format (including the http:// or https:// part).
57. How would you collect a user's phone number using HTML5?
a) type="tel"
b) type="phone"
c) type="number"
d) type="text"
Answer: a) type="tel"
Explanation: The tel input type is used to collect telephone numbers, and although it doesn't strictly enforce phone number formatting, it provides hints to the browser.
58. How can you limit the user to entering only numeric values in an input field?
a) Use type="number"
b) Use type="text" with a regex pattern
c) Use type="integer"
d) Use type="digit"
Answer: a) Use type="number"
Explanation: The number input type restricts input to numeric values and allows for validation of range, step, and decimal formats.
59. What is the purpose of the autofocus attribute?
a) It automatically submits the form when filled.
b) It places the cursor in the input field when the page loads.
c) It validates the input on page load.
d) It fills in the field with default data.
Answer: b) It places the cursor in the input field when the page loads.
Explanation: The autofocus attribute ensures that a specific input field is focused and ready for the user to type in as soon as the page loads.
60. Which of the following input types allows users to select a specific color?
a) color
b) palette
c) color-picker
d) hex
Answer: a) color
Explanation: The color input type allows the user to select a color using a color picker interface.
Questions 61-100
The rest of the questions can continue to assess deeper and advanced use of HTML5 form attributes, validating and controlling inputs, combining multiple attributes like min, max, step, and required, the use of JavaScript with HTML5 forms, and exploring new form features such as input events, UI elements, and field validation techniques.
4o mini
You said:
yes
ChatGPT said:
ChatGPT
Here are questions 61-100 to complete the set of 100 MCQs on HTML5 Forms and New Input Types:
61. Which input type is used to collect a number, but restricts the user to entering only integer values?
a) number
b) range
c) tel
d) integer
Answer: a) number
Explanation: The number input type restricts the user to entering numeric values, and when combined with step="1", it ensures only integer values are allowed.
62. What attribute can you use to set the width of a number input field?
a) size
b) maxlength
c) step
d) width
Answer: a) size
Explanation: The size attribute controls the number of characters visible in an input field. For number fields, it adjusts the visible length of the input.
63. Which attribute can you use to prevent the user from modifying the value of an input field, while keeping it visible?
a) readonly
b) disabled
c) hidden
d) locked
Answer: a) readonly
Explanation: The readonly attribute makes an input field unmodifiable but allows its value to be visible, unlike disabled, which hides the value from being submitted.
64. Which input type allows a user to select a range of values using a slider?
a) range
b) date
c) number
d) time
Answer: a) range
Explanation: The range input type allows users to select a value from a given range using a slider.
65. What is the purpose of the step attribute in an input field?
a) It defines the minimum value allowed.
b) It sets a step size for numeric values.
c) It limits the number of characters.
d) It ensures the input is required.
Answer: b) It sets a step size for numeric values.
Explanation: The step attribute specifies the intervals between acceptable values, allowing you to define increments for numeric input fields.
66. Which of the following input types automatically validates an email address format?
a) email
b) url
c) tel
d) password
Answer: a) email
Explanation: The email input type automatically validates the input to ensure that it matches the general structure of an email address.
67. Which input type allows a user to select a color from a color picker?
a) color
b) palette
c) hex
d) text
Answer: a) color
Explanation: The color input type provides a color picker, allowing users to choose a color.
68. What does the multiple attribute do in a file input field?
a) It allows the selection of multiple files at once.
b) It limits the file selection to one file.
c) It sets the file type for selection.
d) It validates the file types.
Answer: a) It allows the selection of multiple files at once.
Explanation: The multiple attribute in a file input allows users to select more than one file at a time.
69. What type of input field should be used for selecting a date?
a) date
b) datetime-local
c) time
d) week
Answer: a) date
Explanation: The date input type is used to select a date, and it provides a calendar-style date picker.
70. What does the novalidate attribute do in a form?
a) It skips validation checks on all input fields.
b) It requires all inputs to be filled before submitting.
c) It forces the form to be validated on submission.
d) It disables form submission.
Answer: a) It skips validation checks on all input fields.
Explanation: The novalidate attribute on a <form> element disables the browser's built-in form validation.
71. How does the required attribute affect form submission?
a) It prevents form submission if the field is left empty.
b) It automatically fills the field with default data.
c) It limits the field to numeric input only.
d) It auto-saves the form data.
Answer: a) It prevents form submission if the field is left empty.
Explanation: The required attribute forces the user to fill out the field before submitting the form.
72. What is the default behavior of an input field with type="file"?
a) It allows the user to select a file from their device.
b) It automatically uploads a file to the server.
c) It forces the user to enter text.
d) It displays an error message.
Answer: a) It allows the user to select a file from their device.
Explanation: The type="file" input allows the user to choose a file from their local device for uploading.
73. Which of the following input types is suitable for entering a phone number?
a) tel
b) number
c) phone
d) text
Answer: a) tel
Explanation: The tel input type is used for entering telephone numbers.
74. Which input type is used to allow a user to select a time?
a) time
b) datetime-local
c) datetime
d) hour
Answer: a) time
Explanation: The time input type allows the user to select a time from a dropdown or clock interface.
75. What attribute is used to specify the length of an input field?
a) size
b) maxlength
c) length
d) width
Answer: a) size
Explanation: The size attribute specifies the visible width of an input field, expressed in character units.
76. Which HTML5 input type is used for entering a web address (URL)?
a) url
b) website
c) link
d) address
Answer: a) url
Explanation: The url input type is used to validate that the input matches the structure of a web address.
77. What does the pattern attribute do in an input field?
a) It defines a specific format for user input using a regular expression.
b) It limits the number of characters.
c) It changes the background color of the input field.
d) It formats the input value to uppercase.
Answer: a) It defines a specific format for user input using a regular expression.
Explanation: The pattern attribute specifies a regular expression pattern that the input value must match.
78. How do you specify the maximum value for a numeric input field?
a) max
b) maximum
c) limit
d) maxvalue
Answer: a) max
Explanation: The max attribute specifies the maximum value allowed for a numeric input.
79. Which input type would be appropriate for entering a range of values between 0 and 100?
a) range
b) number
c) text
d) slider
Answer: a) range
Explanation: The range input type is used to select a value within a specified range, usually represented by a slider.
80. What does the placeholder attribute do in an input field?
a) It provides a short hint or example of what to enter in the field.
b) It defines the input field's default value.
c) It hides the input field's value.
d) It disables the input field.
Answer: a) It provides a short hint or example of what to enter in the field.
Explanation: The placeholder attribute is used to display a hint inside the input field until the user types something.
81. What does the action attribute of a form tag specify?
a) The URL where the form data should be submitted.
b) The method used for submitting the form.
c) The data to be submitted.
d) The default value of the form.
Answer: a) The URL where the form data should be submitted.
Explanation: The action attribute specifies the destination URL for form submission.
82. What input type is used to allow the user to select a time and date?
a) datetime-local
b) datetime
c) time
d) date-time
Answer: a) datetime-local
Explanation: The datetime-local input type allows users to select both date and time without a timezone.
83. Which attribute is used to specify the order in which input fields should be focused when pressing the "Tab" key?
a) tabindex
b) focus
c) order
d) sequence
Answer: a) tabindex
Explanation: The tabindex attribute specifies the order in which input elements receive focus when navigating with the "Tab" key.
84. What is the purpose of the autocomplete attribute?
a) It controls whether the browser should suggest previously entered values in the input field.
b) It limits the number of characters the user can input.
c) It validates the entered value.
d) It sets the default value of the input.
Answer: a) It controls whether the browser should suggest previously entered values in the input field.
Explanation: The autocomplete attribute determines whether the browser can suggest previously entered values in an input field.
85. Which input type is best for creating a password field?
a) password
b) text
c) hidden
d) secret
Answer: a) password
Explanation: The password input type is used to hide the text entered in the field, typically for sensitive information like passwords.
86. What does the min attribute define in an input field?
a) The minimum value allowed.
b) The maximum number of characters.
c) The minimum number of characters.
d) The default value.
Answer: a) The minimum value allowed.
Explanation: The min attribute sets the minimum value for an input field, especially for numeric or date inputs.
87. Which input type supports entering only a phone number in a proper format?
a) tel
b) text
c) number
d) email
Answer: a) tel
Explanation: The tel input type is used to collect a phone number, and it provides some basic validation for phone number formats.
88. Which input type is most suitable for entering a URL?
a) url
b) text
c) link
d) email
Answer: a) url
Explanation: The url input type is used for URLs and validates the input against the structure of a web address.
89. Which input type allows the user to select a file from their system?
a) file
b) document
c) image
d) upload
Answer: a) file
Explanation: The file input type is used to allow the user to select a file from their device for uploading.
90. What attribute defines the maximum number of characters allowed in an input field?
a) maxlength
b) size
c) length
d) max
Answer: a) maxlength
Explanation: The maxlength attribute defines the maximum number of characters a user can enter in an input field.
91. What attribute is used to make an input field required before the form can be submitted?
a) required
b) mandatory
c) validate
d) needed
Answer: a) required
Explanation: The required attribute ensures the user fills out the field before submitting the form.
92. What happens when the disabled attribute is added to an input field?
a) The input field becomes uneditable and its value is not submitted.
b) The input field becomes readonly but is still editable.
c) The input field becomes a hidden field.
d) The input field is mandatory for submission.
Answer: a) The input field becomes uneditable and its value is not submitted.
Explanation: The disabled attribute makes the input unmodifiable and prevents its value from being submitted with the form.
93. How can you enable auto-completion of form input values?
a) Use the autocomplete attribute.
b) Use the auto-complete attribute.
c) Use the auto-fill attribute.
d) Use the value attribute.
Answer: a) Use the autocomplete attribute.
Explanation: The autocomplete attribute allows the browser to offer suggestions based on previously entered values.
94. Which input type is designed for entering credit card information?
a) tel
b) text
c) number
d) cc
Answer: b) text
Explanation: The text input type is often used for credit card information, although it does not provide specific validation for card numbers (input validation can be done via JavaScript).
95. Which form input type is best suited for entering numeric values with decimal points?
a) number
b) text
c) decimal
d) range
Answer: a) number
Explanation: The number input type is best for numeric values, and it allows decimals if the step attribute is appropriately set.
96. How can you specify the default value for an input field?
a) value attribute
b) default attribute
c) initial attribute
d) default-value attribute
Answer: a) value attribute
Explanation: The value attribute sets the default value for an input field when the page loads.
97. What is the main benefit of using HTML5 form input types?
a) Improved validation and user experience
b) Increased form submission speed
c) Compatibility with all browsers
d) Automatic server-side validation
Answer: a) Improved validation and user experience
Explanation: HTML5 input types provide better validation and user experience by leveraging built-in form validation and interface elements.
98. Which of the following is a correct use of the pattern attribute?
html
Copy code
<input type="text" pattern="[A-Za-z]+">
a) Allows only alphabetic characters.
b) Allows any characters.
c) Allows only numbers.
d) Allows any type of input.
Answer: a) Allows only alphabetic characters.
Explanation: The pattern attribute defines a regular expression, which restricts input to alphabetic characters (A-Z, a-z).
99. Which input type is used for selecting a month and year without a day?
a) month
b) date
c) week
d) year
Answer: a) month
Explanation: The month input type allows the user to select a month and year but not a specific day.
100. How can you trigger a validation message when an input field is invalid?
a) Using JavaScript
b) Using the novalidate attribute
c) Using the required attribute
d) The browser triggers it automatically.
Answer: d) The browser triggers it automatically.
Explanation: The browser automatically shows validation messages for required and invalid fields when using HTML5 validation attributes.