
A PURE HTML/CSS functional calendar?! 😲🤯 (+CSS APIs and all the fun things we can do with them + A
4 November, 2021
4
4
0
Contributors
Yesterday I went back to my frontend experiments after a load of JavaScript work. I experimented with the CSS custom property toggle trick (more on that later) which can allow me to have if/else logic in CSS, and with a bit of experimenting I made this CSS only calendar!

CSS only calendar!
content: var(--content)
!:after
,
but the other properties look strange. Those properties are totally
valid according to spec (the properties contain a value which is " ")
and we can use them to make if else logic.•
--color
changes from initial to an empty space.•
--color
is initial- That makes the variable
--color-when-small
contain the valueinitial red
which is invalid. - So when we actually set the color and call that variable like background-color:
var(--color-when-small, var(--color-when-big));
, the second value (the fallback) is used because the first is invalid.
•
- That makes the variable
--color-when-small
contain the value(space)red
, which is valid - So when we actually set the color and call that variable like background-color:
var(--color-when-small, var(--color-when-big));
, the first value is used
span
s with all my months:--january
is set to " "
, --display-when-correct
becomes (space)block
, which is valid. And since --february
, --march
all don't exist, they become invalid (and so they are display: none
.CSS APIs
css
html
tricks
webdev