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! ๐Ÿ‘‹

Are you excited about @scope hitting the baseline soon? And do you know that there's also a :scope in JavaScript? And have you ever used enterkeyhint in HTML?

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

Gerardo listens to "Los hermanos Reyes 'Dos horas de balazos'" and says:

It is a typical adventure of cowboys, 4 go to save the ranch stolen, they recover the terrains, and the funny thing is that we don't know who of the 4 conquers the lady owner of the lands.

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

Last week I shared Roma's post It is OK to Say "CSS Variables" Instead of (or Alongside) "Custom Properties" and if you're having the urge to correct people when they talk about CSS variables, you should definitely check it out.

After sharing last week's newsletter Axel pointed me again to the CSS Custom Properties spec (which lives under /css-variables) and there is written:

This module introduces cascading variables as a new primitive value type that is accepted by all CSS properties, and custom properties for defining them.

This is of course spec language so Bramus rephrased it:

Custom Properties is how variables are implemented in CSS.

So, --something is a custom property and it was introduced to enable cascading CSS variables.

This all makes sense and with these points made, I'm now finally able to let go of my grudge against people talking about CSS variables. Are you, too?

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

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

A huge bag of karma points goes to Bjรถrn this week. Thank you for buying me a monthly coffee and covering a small fraction of sending Web Weekly every week! โค๏ธ

If you enjoy Web Weekly, too, join 30 supporters and support indie publishing on Patreon or GitHub Sponsors. It really makes a difference for me!

Something that made me smile this week

Cat placeholder images.

You know, I'm more of a dog person, but hey, animal placeholder images are always more than welcome!

Load some cats

No code

@scope will be dang useful for component styles

<div>   <style>     @scope {       p { color: red; }     }   </style>   <p>this is red</p> </div> <p>not red</p>

Firefox 146 will be released in two weeks and with it we'll have another CSS goodie hitting the baseline: CSS @scope.

Scoped CSS rules will allow you to... well... limit or scope your CSS rules to components or DOM subtrees. Ollie reminded me about another little detail. If you place @scope into style elements, the CSS scope will only be applied to the parent DOM element. Does this feel like magic? It surely does!

Style your components

And if you now wonder how you could make this work for inline demos, Roma shares how his <LiveExample /> component uses @scope.

:scope is dang useful in JS, too!

const main = document.querySelector(".main"); const content = main.querySelector(":scope .wrapper .content"); // Result: null

Speaking of scoped stuff: do you know that :scope is a thing in querySelector calls, too?

Scope your DOM queries

Features missing only in one browser

Web platform features explorer

Speaking of web features that are missing in only one browser. Do you know about the Web Platform Features Explorer?

It's one of the many tools I use to inform you about new browser features entering the baseline. Check it out if you want to learn what browsers hold back web features from going into cross-browser support territory.

Investigate!

CSS random()

.star {   background: red;   height: calc(1dvh * var(--rand));   width: random(2px, 6px);   aspect-ratio: 1; }

Chris has been playing with the new CSS random() function, and while it'll still take a while until we can use it because it's only supported in Safari Tech Preview, I wonder what fancy effects we all can create with randomized CSS values. This post is a good starter to get some inspiration.

Draw some stars

You're halfway through!

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

The wonderful weird web โ€“ The 512KB Club

The 512kb club

I just checked; my entire blog's home page weight is 223KB (before compression) so that I can call myself a proud member of the 512KB club.

Are you a club member, too? Maybe we can highlight some Web Weekly reader sites next week!

Measure

Build a custom router with UrlPattern

const routerConfig = [   { pathName: new URLPattern("/home{/}?"), component: "my-home" },   { pathName: new URLPattern("/posts{/}?"), component: "my-posts" },   { pathName: new URLPattern("/about{/}?"), component: "my-about" }, ];

If you've been reading Web Weekly for long enough, you must have noticed my UrlPattern excitement. The new JS API works across browsers since September of this year and it makes URL operations so much easier!

Jim explained how you can use it to build your own custom router and this will be right down your alley if you enjoy building your own stuff!

Parse all the URLs

TIL โ€” light-dark() isn't the same as prefers-color-scheme

Interactive widget showing two controls to choose a color scheme and the rendered result below.

I've always thought that light-dark() is a drop-in replacement for prefers-color-scheme queries... I was wrong and you can learn more about this on the blog.

Toggle all the themes

string[] or Array<string>?

function add(items: Array\<string\>, newItem: string)   function add(items: string[], newItem: string)

Oldie but goldie; when you define arrays in TypeScript do you go for the [] or Array<> notation? Dominik has a strong opinion and even stronger arguments on the topic...

Shorter is not always better

Why tree-shaking doesn't work for JS classes

The problem of using a class to build a JavaScript service is that it leads to the code being larger than it actually needs to be, for two reasons.

Guilherme reminded me about JS performance optimizations and explained ECMAScript classes aren't working well with bundler optimizations like tree-shaking. Check it out if you want to keep your bundles as small as possible!

Keep things lean

Random MDN โ€“ enterkeyhint

input enterkeyhint devsheet showing different enter keys on mobile keyboards.

From the unlimited MDN knowledge archive...

Do you know that you can control what the ENTER key shows in virtual keyboards using the enterkeyhint HTML attribute? Now you do!

Give some hints

TIL recap โ€“ How to iterate over TS union types

type Random = "Joo" | "Foo" | 123 | 234;   // Iterate of the types included in `Random`. // // If type `T` is of type `string` prefix it. type Prefix\<T\> = T extends string ? `String: ${T}` : T; type MappedTypes = Prefix\<Random\>;

Is it just me or are TypeScript extends kinda scary? A while ago, I learned how to use them to iterate over union types and some things finally clicked for me.

Iterate

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

New'ish on the baseline

section {   content-visibility: auto;   contain-intrinsic-size: auto 500px; }

Rendering very large HTML documents can become a real challenge for mobile devices that aren't high-end. content-visibility isn't cutting edge anymore but only went into the baseline last year. Check it out if you're struggling with rendering too much markup and are desperately looking for a possible performance boost!

Delay the rendering

Three valuable projects to have a look at

A new Tiny Helper

ColorPallete Pro interface looking like a synthesizer.

There are plenty of color palette tools listed on Tiny Helpers but the ColorPalette Pro is by far the best looking one!

Get some colors

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

Thought of the week

I'm that kind of person not answering their phone and I must also admit that I prefer text for many interactions, but if things are urgent and you really need help, as Jim points out in "Everything is broken", a human is who I want to speak to.

A direct line to a human feels like the ultimate luxury at this point.

Did you learn something from this issue?

โค๏ธ If so, join 30 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