Published at
Updated at
Reading time
9min
The Web Weekly newsletter keeps you up to date, teaches you web development tricks and covers all things working in tech.

Guten Tag! Guten Tag! ๐Ÿ‘‹

Have you had a look at CSS functions already? Do you use AbortController in JavaScript? And do you know that the HTML output element is an ARIA live region?

Turn on the Web Weekly tune and find some answers below. Enjoy!

Yoganathan listens to "Fox Stevenson - Curtain Call"

Fox Stevenson is an underrated electronic artist who usually makes banger Drum and Bass, but this one has got such bouncy pop vibes. Have got it on repeat.

Do you want to share your favorite song with the Web Weekly community? Hit reply; there are 5 more songs left in the queue.

A ton of karma points go to vaibhav this week! Thank you for supporting Web Weekly! โค๏ธ

If you want to support my work with Web Weekly, too, you can't imagine how much I celebrate every Patreon or GitHub Sponsors donation.

You probably know about the fairly new light-dark() CSS function which lets you set colors that depend on the current color scheme inline. That's right, you don't need to use a media query!

:root {   color-scheme: light dark; } body {   color: light-dark(#333b3c, #efefec);   background-color: light-dark(#efedea, #223a2c); }

If you ask me, the CSS function seemed oddly specific and it's a bummer that it only works with color values. And I don't know if this will be a thing, but what happens when we'll have a third color scheme in the future. Will we abandon light-dark() then? Tricky, tricky, tricky...

And then there's Bramus telling us that we can create our own light-dark function soon:

I explored combining CSS custom functions and CSS if(), leading to the creation of a custom --light-dark() CSS function that works with any value (not just colors!).

Disclaimer: we're in CSS future land here, but that's very cool!

@function --light-dark(--l, --d) {   result: if(color-scheme(dark): var(--d); else: var(--l)); }

light-dark() could easily be replaced with a custom --light-dark() CSS function. I dig it!

CSS functions also unlock an entire new set of utilities. Here's Sindre playing around with a CSS utility library called css-extras.

.element { /* Math functions */ padding: --negate(var(--spacing)); margin: --abs(-20px); /* Color functions */ background: --opacity(blue, 50%); border-color: --tint(var(--primary-color), 20%); /* And many more! */ }

All this new CSS function stuff got me wondering, though. Was adding light-dark() to CSS a mistake when a more generic and more flexible way of doing the same things appeared a year later?

And do you remember :focus-within? It's an oddly specific pseudo-class, too, and we can now do the same (and more) things using :has().

Don't get me wrong, I don't want to criticize all the fine folks wrangling the CSS specs for us, but these examples show how tough it is "to invent" things for the web because you'll never know when someone shows up with a smarter idea.

If you enjoy Web Weekly, share it with your friends and family.

A quick "repost" really helps this indie newsletter out. Thank you! โค๏ธ

Something that made me smile this week

rudeCaptcha

I don't think you should use the rudeCaptcha for public sites but it's clearly more entertaining than all the puzzles we need to deal with all day.

Don't be offended

No code

When container query units help you position elements

   .parent:active .element {   translate: 0 calc(100cqb - 100%); }

Have you ever used the cqb and cqi units? I must admit I haven't but Ryan makes a strong argument about using them to position elements.

Use the container

The forced-color-adjust foot gun

@media (forced-colors: active) {   button[aria-pressed=true] {     forced-color-adjust: none;     background-color: Highlight;     color: HighlightText;   } }

Do you know that when people use high contrast mode, most of your CSS colors are rewritten to system colors? And do you know that you can use the forced-color-adjust CSS property to prevent this from happening?

Of course, it's not that easy and Sarah explains when you should use forced-color-adjust but why it's a foot gun more often than not.

Be careful

Don't Sleep on AbortController

fetch(url, {   // Abort this request automatically if it takes   // more than 3000ms to complete.   signal: AbortSignal.timeout(3000), })

This post is a year old, but it's still a great primer on AbortController and how to cancel things in JavaScript.

Cancel!

Newer Array methods

const grouped = Object.groupBy(tasks, task => task.status);

I know that many people have a strong dislike towards reduce functions. I'm not one of them, but I do like all these modern array utility methods. If you haven't used groupBy, this post is for you!

Forget about reduce

You're halfway through!

Wowza! Would you enjoy getting Web Weekly straight to your inbox?

The wonderful weird web โ€“ Adrift

Adrift is a quiet space where doubts become paper boats and drift together across a shared sea.

I love this! Adrift is a very calm site on which people can share doubts but also care for each other. โค๏ธ

Let it out

Random CSS color facts

.gradient.long-way {   background: linear-gradient(     in hsl longer hue 90deg,     var(--color-1),     var(--color-2)   ); }

Kevin covers CSS colors, alpha channel syntax history, color spaces and gradients in this post. It's a mixed bag of CSS color knowledge and I love it!

Be colorful

Side note: if you're looking for more color manipulation resources, our friends at CSS-Tricks released a fairly new guide on the matter.

The often forgotten output element

<input id="a" type="number"> + <input id="b" type="number"> = <output for="a b"></output>

Be honest, do you know what the HTML output element does? If you want to learn more about it, Den has you covered!

Put things out

TIL โ€” Keyframe animation styles are "special"

The cascading algorithm determines what properties to apply to an element in the following order: 1. user-agent normal 2. user normal 3. author normal 4. keyframe animations 5. author !important 6. user !important 7. user-agent !important 8. transitions

Last week I learned that styles applied via CSS @keyframe animations have a special role in the CSS cascade. What? Yeah, exactly... ๐Ÿ˜…

Overrule with animations

cache-control hidden gotchas

Cache-Control for Civilians

I've seen some people talking about caching this week, so why not plug Harry's evergreen resource explaining everything you need to know. Do you wonder what's the difference between no-store, no-cache and no-transform; this post is one for your bookmarks.

Keep your cache

Random MDN โ€“ overscroll-behavior

.messages {   height: 220px;   overflow: auto;   overscroll-behavior-y: contain; }

From the unlimited MDN knowledge archive...

Do you know that you can control what should happen when someone reaches the end of a scroll container? Now you do!

Stop the scroll

TIL recap โ€“ indexOf equality

['foo', 123, true, undefined, NaN].indexOf(NaN) // -1

Here's a JS trivia question: how do you check if an array holds a NaN value?

Hint: indexOf won't do it because NaN isn't equal to itself...

Detect NaN

Find more short web development learnings in my "Today I learned" section.

New on the baseline

details::details-content {   opacity: 0;   transition:     opacity 600ms,     content-visibility 600ms allow-discrete; }  details[open]::details-content {   opacity: 1; }

It's a small thing, but if you're using the details element, targeting the element content is now possible with ::details-content. Firefox 143 joined the party!

Target the content

Bramus shared many more ::details-content examples than those included on MDN, if you want to learn more about it.

Three valuable projects to have a look at

A "new" Tiny Helper

Slowfil.es

Here's an absolute classic; if you want to test out how and if a slow file would affect your performance bottom line, slowfil.es allows you to control the response time via query parameters. It's a handy tool if you're knee deep in a perf analysis.

Slow down

Find more single-purpose online tools on tiny-helpers.dev.

Thought of the week

Since reading "Your Strengths Are Your Weaknesses" I keep seeing this concept literally everywhere...

The qualities we celebrate in our team members are usually the same ones causing our biggest headaches.

Did you learn something from this issue?

โค๏ธ If so, join 25 other Web Weekly supporters and give back with a small monthly donation on Patreon or GitHub Sponsors.

This is all, friends!

Loved this email? Hated this email? I want to hear about it!

If you think something needs improvement or something sparked some joy, reply to this email because I want to know more!

And with that, take care of yourself - mentally, physically, and emotionally.

I'll see you next week! ๐Ÿ‘‹

If you enjoyed this article...

Join 6.2k readers and learn something new every week with Web Weekly.

Web Weekly โ€” Your friendly Web Dev newsletter
Reply to this post and share your thoughts via good old email.
Stefan standing in the park in front of a green background

About Stefan Judis

Frontend nerd with over ten years of experience, freelance dev, "Today I Learned" blogger, conference speaker, and Open Source maintainer.

Related Topics

Related Articles