๐ŸŽ›๏ธ Chapter 26: Specialized HTML5 Input Types & Modern Data Capture

Month and Week Inputs (type="month" & type="week")

Capturing billing cycles (`YYYY-MM`), fiscal sprint calendars (`YYYY-Www`), browser compatibility matrices, and progressive enhancement polyfills.

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 valueAsNumber property 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.
๐ŸŽฌ INTERACTIVE VISUAL PIPELINE Core Architecture Simulation
๐ŸŒ
1. Input
Directives & Tags
โš™๏ธ
2. Parse
Tokenizer & AST
๐ŸŒณ
3. Layout
Box Model & Flow
๐ŸŽจ
4. Render
GPU Paint & Composite
PHASE 1: INPUT & DIRECTIVES
Browser receives declarative markup stream, parsing tag tokens and initializing component state.

๐Ÿ“– 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 (0001 through 9999).
  • MM: Two-digit month (01 through 12).
<!-- 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, valueAsNumber is 0.
  • For 2026-08, valueAsNumber is $(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 01 to 53.
<!-- 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');
}

SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
HTML STARSHIP CODE TERMINAL example.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45ยฐC
INSPECTING DOM: VALID
TAGS: SCANNING...

๐Ÿ’ป 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 of pattern="[0-9]{4}-(0[1-9]|1[0-2])" acts as an automatic validation safety net in browsers that degrade to type="text".
  • Lines 139โ€“152: The <input type="week"> captures the ISO sprint week (2026-W34). The pattern validates standard ISO weeks from 01 to 53.
  • Lines 159โ€“173: The JavaScript utility dynamically tests whether the rendering engine natively supports type="month" and type="week", updating the status badges to inform the developer and user.

Expected Browser Render Output


SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
HTML STARSHIP CODE TERMINAL playground.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45ยฐC
INSPECTING DOM: VALID
TAGS: SCANNING...
+-------------------------------------------------------------+
| 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:

  1. Create a form with action="/billing/upgrade" and method="POST".
  2. Add a Card Expiration Date input:
    • Must use type="month".
    • Must specify id="cc-exp" and name="card_expiration".
    • Must include autocomplete="cc-exp".
    • Must be required.
    • Must enforce a fallback pattern for YYYY-MM.
  3. Add a Target Onboarding Week input:
    • Must use type="week".
    • Must specify id="onboarding-week" and name="onboarding_week".
    • Must be constrained between 2026-W01 and 2026-W52.
  4. Include a submit button labeled "Complete Upgrade".

๐Ÿ Starter Code Sandbox

SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
STARTER CODE SANDBOX exercise.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45ยฐC
INSPECTING DOM: VALID
TAGS: SCANNING...

โš ๏ธ Common Pitfalls

  1. Assuming All Browsers Render a Calendar Widget: Failing to provide placeholder="YYYY-MM" and a pattern will leave Safari users staring at a blank text box with no indication of the required format.
  2. 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.
  3. Missing Uppercase 'W' in Week Strings: Writing 2026-w34 (lowercase) is rejected by HTML5 parsers. It must strictly be uppercase 2026-W34.

๐Ÿ’ก Pro Tips

  1. 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"
    
  2. Leveraging autocomplete="cc-exp": Always attach autocomplete="cc-exp" on subscription payment forms; it reduces checkout abandonment by streamlining credit card autofill.

๐Ÿ“Œ Key Takeaways

  • <input type="month"> captures YYYY-MM formats ideal for billing cycles and credit card expiration.
  • <input type="week"> captures YYYY-Www formats 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 month and week inputs with placeholder and regex pattern attributes for robust progressive enhancement.
  • In ISO 8601, weeks begin on Monday, and Week 01 contains the first Thursday of January.
  • --
โญ LEARN: HTML ๐ŸŒŸ โš”๏ธ QUIZ BATTLE ARENA // ACTIVE
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 1 / 3

What is the valid wire format submitted by <input type="week">?

Question 1 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 2 / 3

What happens in desktop Safari when it encounters <input type="month">?

Question 2 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 3 / 3

What does input.valueAsNumber represent on an <input type="month"> element with value="1970-03"?

Question 3 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP