Skip to content

[css-values] Time based numerical functions #13659

@johannesodland

Description

@johannesodland

Splitting off from #13655.

Using the current time can be useful for creating dynamic computed themes and layouts.
To avoid flashes of wrongly styled content, this is currently only possible by adding blocking scripts to set a custom property or attribute.

Proposal

Add time functions that return <number> values:

  • year()
  • month()
  • day()
  • day-of-week()
  • day-of-year()
  • weak-of-year()
  • ...

The time functions should roughly match the Temporal ZonedDateTime properties to make it easier to learn.

To provide values specific to one time zone or calendar, the functions could optionally accept time zone and calendar as a parameter:

day-of-year("Europe/Brussels" iso8601)

To provide values specific to one zoned date time, the functions could optionally accept a RFC 9557 string:

day-of-year("2026-03-15T11:00:00+01:00[Europe/Oslo]")

Use cases

1. Time based theming

A mini-game is set up to have a generative color theme based on the day of the year. Each day the game has a new combination of colors.

--background-color-1: ...;
--background-color-2: ...;
--background-color-3: ...;
--background-index: mod(day-of-year(), 3);


background-color: var(ident("--background-color-" var(--background-index)));

2. Highlighting simple timetables

A local hackerspace has a time table with the daily opening hours and the person responsible.
day-of-week() could be used in a style query to highlight the row corresponding to the current week day,
although conditional time queries as discussed in #9710 could be better for this purpose if supported.

<table>
  <tr data-timetable-day=1>...</tr>
  <tr data-timetable-day=2>...</tr>
</table>
--timetable-day: attr("data-timetable-day" type(<number>));

font-weight: if(
  style(--timetable-day: day-of-week()): bold;
  else: normal;
);

Related proposals

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions