All Exams Test series for 1 year @ ₹349 only
Question

In HTML, month attribute defines a control with ______

The correct answer is

Month and year

Understanding the HTML month Input Type

The question asks about the purpose of the month attribute in HTML input controls. Specifically, what kind of value does an input field with type="month" define or allow the user to select?

Let's look at the options provided:

  1. Date and time
  2. Only date
  3. Only month
  4. Month and year

In HTML5, the <input> element has various types to create different form controls. The type="month" is one such type designed for a specific purpose.

An input field with type="month" is intended to let the user easily specify a month and a year. Browsers typically provide a calendar interface or a spinner control that allows the user to select a month from a list and specify the year. This control does not include the day of the month or any time information.

Let's analyze why the other options are incorrect:

  • Option 1: Date and time - This is incorrect. The month type does not allow selecting a specific day or time. For date and time combined, HTML provides <input type="datetime-local">.
  • Option 2: Only date - This is incorrect. While "date" implies day, month, and year, the month type specifically excludes the day. For selecting a full date (year, month, day), HTML provides <input type="date">.
  • Option 3: Only month - This is incorrect. The month type requires both a month and a year to be selected. You cannot just select "January" without specifying the year.
  • Option 4: Month and year - This is correct. The defined purpose of the <input type="month"> control is to allow the user to select a specific month within a specific year.

Therefore, the month attribute (used with <input type="month">) defines a control for selecting a month and a year.

Example of HTML month Input

Here is how you would use the <input type="month"> in your HTML code:

<label for="start-month">Select Start Month and Year:</label>
<input type="month" id="start-month" name="start-month">

When rendered in a browser, this would display a form control that, upon interaction, allows the user to pick a month and year.

Revision Table: HTML Input Types

Input Type Purpose Format/Value Example
text Single-line text input Any text string
number Numeric input 123, -45
date Date selection (year, month, day) YYYY-MM-DD (e.g., 2023-10-27)
month Month and year selection YYYY-MM (e.g., 2023-10)
week Week and year selection YYYY-Wnn (e.g., 2023-W43)
time Time selection hh:mm or hh:mm:ss
datetime-local Date and time selection (no timezone) YYYY-MM-DDThh:mm

Additional Information on HTML Date and Time Inputs

HTML5 introduced several new input types specifically for handling date and time values, making form validation and user input easier. These types are:

  • date: For picking a calendar date (year, month, day).
  • month: For picking a specific month within a specific year.
  • week: For picking a specific week within a specific year.
  • time: For picking a time of day (hour, minute, and optionally second).
  • datetime-local: For picking a date and time, without any timezone information.

Using these specific types provides better user interfaces (like calendar pickers) and helps ensure that the data submitted by the form is in a consistent and expected format, improving both user experience and data integrity.

Was this answer helpful?

Important Questions from HTML

  1. Which of the following tag creates a checkbox for a form in HTML?

  2. In a HTML form, which of the following input control is used for allowing users to make multiple selections?

  3. What is the full form of SGML?

  4. Which of the following is NOT a pair tag in HTML?

  5. _______ specifies the HTML Element that you want to style.

Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App