Skip to main content

HTML input type="week"

HTML input type week is a type of form control that allows users to input a week number and year in ISO 8601 format. This input type is particularly useful for collecting data related to events or tasks that occur on a weekly basis.

The syntax for using the input type week is as follows:

<input type="week" id="week" name="week">

The name attribute is used to specify the name of the input field, while the type attribute is set to "week" to indicate that this is a week input field. When the user selects a week and year combination, the value stored in the input field will be in the format "YYYY-W##".

Other examples:

<label for="employee-schedule">Select a week:</label>
<input type="week" id="employee-schedule" name="employee-schedule">
<label for="default-week">Select Week:</label>
<input type="week" id="default-week" name="default-week" value="2023-W14">
<label for="styled-week">Select Week:</label>
<input type="week" id="styled-week" name="styled-week" style="color: red; font-size: 20px;">

In this example, we have a week input field for collecting the user's preferred week, with custom styling applied using the style attribute. This allows you to customize the appearance of the input field to match your website or application's design.