LEARNING OBJECTIVES โต
- Understand the ISO 8601 wire formats for
<input type="month">(YYYY-MM) and<input type="week">(YYYY-Www). - Master the ISO 8601 week-numbering standard (Weeks 01โ53) and its calculation rules.
- Inspect the DOM
valueAsNumberproperty for month and week elements. - Navigate the cross-browser support matrix and design resilient fallback experiences for Safari and Firefox.
- Pair month inputs with
autocomplete="cc-exp"for payment card processing.
๐ The Mental Model & Story (Intuitive Foundation)
Imagine booking an annual corporate advertising campaign on a city billboard or planning a software engineering sprint roadmap.
When you purchase billboard ad space for August 2026, you don't pick "August 14th at 2:15 PM"; your contract runs for the entire calendar month. Similarly, when an Agile engineering team plans Sprint 34, they plan for the full calendar week, not an individual hour.
+-------------------------------------------------------------------------------+
| MACRO-PERIOD TEMPORAL GRANULARITY |
| |
| Day Picker (type="date"): [ 2026-08-21 ] |
| - High Granularity (Specific Day) |
| |
| Month Picker (type="month"): [ 2026-08 ] |
| - Macro Granularity: Entire Billing Month (Credit Cards, Subscriptions)|
| |
| Week Picker (type="week"): [ 2026-W34 ] |
| - Macro Granularity: Full ISO Work Week (Sprints, Fiscal Rosters) |
+-------------------------------------------------------------------------------+
Forcing users to pick an arbitrary day when only a month or week is needed introduces cognitive friction and data ambiguity. <input type="month"> and <input type="week"> provide native macro-level date pickers.
Technical Deep Dive & Specifications
The type="month" Specification
The value, min, and max attributes of <input type="month"> must strictly match:
$$\text{YYYY-MM}$$
- YYYY: Four-digit year (
0001through9999). - MM: Two-digit month (
01through12).
<!-- Wire Value: August 2026 -->
<input type="month" name="subscription_start" value="2026-08" min="2026-01" max="2028-12">
DOM valueAsNumber for Month Inputs
For type="month", valueAsNumber returns the total number of months elapsed since January 1970:
$$\text{valueAsNumber} = (\text{Year} - 1970) \times 12 + (\text{Month} - 1)$$
- For
1970-01,valueAsNumberis0. - For
2026-08,valueAsNumberis $(2026 - 1970) \times 12 + (8 - 1) = 56 \times 12 + 7 = 679$.
The type="week" Specification & ISO 8601 Weeks
The value, min, and max attributes of <input type="week"> must strictly match:
$$\text{YYYY-Www}$$
- YYYY: Four-digit ISO week-numbering year.
- W: The mandatory literal uppercase letter
"W". - ww: Two-digit week index from
01to53.
<!-- Wire Value: Week 34 of 2026 -->
<input type="week" name="sprint_cycle" value="2026-W34" min="2026-W01" max="2026-W52">
How ISO 8601 Defines "Week 01":
+-------------------------------------------------------------------------------+
| THE ISO 8601 WEEK 01 FORMULA |
+-------------------------------------------------------------------------------+
| - A week always begins on MONDAY and ends on SUNDAY. |
| - Week 01 of any year is the week that contains the FIRST THURSDAY of January |
| (or equivalently, the week that contains January 4th). |
| - If January 1st falls on a Friday, Saturday, or Sunday, those days belong |
| to Week 52 or 53 of the PREVIOUS year! |
+-------------------------------------------------------------------------------+
Cross-Browser Support Matrix & Progressive Fallbacks
While Chromium-based browsers (Chrome, Edge, Opera, Samsung Internet) provide native visual calendar pickers for month and week, Safari (desktop) and Firefox have historically treated them as standard text inputs.
+-------------------------------------------------------------------------------+
| BROWSER COMPATIBILITY MATRIX |
+----------------------+--------------------+-----------------------------------+
| Browser Engine | type="month" | type="week" |
+----------------------+--------------------+-----------------------------------+
| Chromium / Edge | โ
Native Picker | โ
Native Picker |
| Firefox (Desktop) | โ ๏ธ Text Fallback | โ ๏ธ Text Fallback |
| Safari (macOS) | โ ๏ธ Text Fallback | โ ๏ธ Text Fallback |
| iOS Safari | โ
Native Roller | โ ๏ธ Text Fallback |
| Android Chrome | โ
Native Picker | โ
Native Picker |
+----------------------+--------------------+-----------------------------------+
The HTML Graceful Degradation Guarantee
When any browser encounters an input type it does not recognize or support, it automatically degrades to <input type="text"> without throwing an error.
Progressive Enhancement Pattern:
To ensure unsupported browsers still collect valid data, always attach a regex pattern and clear placeholder:
<!-- Month with progressive fallback -->
<input
type="month"
id="card-exp"
name="exp_month"
placeholder="YYYY-MM"
pattern="[0-9]{4}-(0[1-9]|1[0-2])"
title="Please enter a valid month in YYYY-MM format"
autocomplete="cc-exp"
required
>
<!-- Week with progressive fallback -->
<input
type="week"
id="sprint"
name="sprint_week"
placeholder="YYYY-Www"
pattern="[0-9]{4}-W(0[1-9]|[1-4][0-9]|5[0-3])"
title="Please enter an ISO week in YYYY-Www format (e.g., 2026-W34)"
required
>
JavaScript Feature Detection
function isInputTypeSupported(type) {
const input = document.createElement('input');
input.setAttribute('type', type);
return input.type === type;
}
if (!isInputTypeSupported('month')) {
console.log('Native month picker not supported; initializing custom fallback UI');
}
๐ป Interactive Code Playground
Starter Code
Line-by-Line Code Breakdown
- Lines 123โ136: The
<input type="month">captures the billing period (2026-08). The inclusion ofpattern="[0-9]{4}-(0[1-9]|1[0-2])"acts as an automatic validation safety net in browsers that degrade totype="text". - Lines 139โ152: The
<input type="week">captures the ISO sprint week (2026-W34). Thepatternvalidates standard ISO weeks from01to53. - Lines 159โ173: The JavaScript utility dynamically tests whether the rendering engine natively supports
type="month"andtype="week", updating the status badges to inform the developer and user.
Expected Browser Render Output
+-------------------------------------------------------------+
| SaaS Contract & Sprint Roadmap |
| Select billing subscription month and release week |
| |
| [ Month: Native Picker ] [ Week: Native Picker ] |
| |
| Subscription Commencement Month * |
| [ August 2026 ๐
] |
| |
| Production Deployment Sprint (ISO Week) * |
| [ Week 34, 2026 ๐
] |
| |
| [ Activate Contract & Assign Sprint ] |
+-------------------------------------------------------------+๐๏ธ Hands-On Exercise
๐ฏ The Challenge: Credit Card Expiration & Agile Milestone Picker
You are creating an account upgrade form with payment details and agile onboarding timeline.
Requirements:
- Create a
formwithaction="/billing/upgrade"andmethod="POST". - Add a Card Expiration Date input:
- Must use
type="month". - Must specify
id="cc-exp"andname="card_expiration". - Must include
autocomplete="cc-exp". - Must be
required. - Must enforce a fallback
patternforYYYY-MM.
- Must use
- Add a Target Onboarding Week input:
- Must use
type="week". - Must specify
id="onboarding-week"andname="onboarding_week". - Must be constrained between
2026-W01and2026-W52.
- Must use
- Include a submit button labeled
"Complete Upgrade".
๐ Starter Code Sandbox
โ ๏ธ Common Pitfalls
- Assuming All Browsers Render a Calendar Widget: Failing to provide
placeholder="YYYY-MM"and apatternwill leave Safari users staring at a blank text box with no indication of the required format. - ISO Week 1 Misconception: Believing that Week 1 always starts on January 1st. In ISO 8601, Week 1 always starts on the Monday of the week containing January 4th.
- Missing Uppercase 'W' in Week Strings: Writing
2026-w34(lowercase) is rejected by HTML5 parsers. It must strictly be uppercase2026-W34.
๐ก Pro Tips
- Converting Month Value to Human Readable Display:
const [year, month] = monthInput.value.split('-'); const date = new Date(year, month - 1); const formatted = date.toLocaleDateString('en-US', { month: 'long', year: 'numeric' }); console.log(formatted); // "August 2026" - Leveraging
autocomplete="cc-exp": Always attachautocomplete="cc-exp"on subscription payment forms; it reduces checkout abandonment by streamlining credit card autofill.
๐ Key Takeaways
<input type="month">capturesYYYY-MMformats ideal for billing cycles and credit card expiration.<input type="week">capturesYYYY-Wwwformats for sprint roadmaps and fiscal planning based on the ISO 8601 standard.- Browsers lacking native picker support automatically degrade to
<input type="text">. - Always pair
monthandweekinputs withplaceholderand regexpatternattributes for robust progressive enhancement. - In ISO 8601, weeks begin on Monday, and Week 01 contains the first Thursday of January.
- --