Fancy Frontend Features

Hi, Nicolai Schwarz here
textformer.de
Designer & Webdeveloper
Dortmund, Germany

doing Drupal since around 2008
mostly Site Building & Frontend stuff

written 100+ articles in the last 15 years for Screenguide, PC Magazin, Webstandards Magazin, t3n, PHP Magazin

Nicolai Schwarz

Topics

Link Icon

Link, at the end
(Linklist + Slides)

Can I use this?
Right now?

Baseline

Screenshot Baseline Website

Baseline gives you clear information about which web platform features are ready to use in your projects today. The core browser set: Chrome, Edge, Firefox & Safari.

Icon Baseline: limited usage

Limited availability across major browsers
(= don’t use it in production)

Icon Baseline: limited usage

Newly available across major browser

Icon Baseline: Widely available

Widely available across major browsers

Screenshot Baseline Website web.dev
Screenshot mdn Website developer.mozilla.org Screenshot Can I Use Website caniuse.com

:has

Baseline 2023 Newly available

Sometimes called the parent selector. Selects elements containing specific content.

Teaser with Text and teaser with image/text

CSS, without has:

CSS, with has:

Example: More than a parent selector

:has

Baseline 2023 Newly available

  • Chrome
    since Aug 22

  • Edge
    since Sep 22

  • Opera
    since Sep 22

  • Firefox
    since Dec 23

  • Safari
    since Mar 22

See caniuse.com

Old Polyfill / new PostCSS plugin

Container Queries (size)

Baseline 2023 Newly available

A most wanted feature since the rise of Responsive Design.

Apply CSS to an element based on the size of that element.

Media Query

Container Query

HTML

Container Query

The @container style trigger is based on the size of the nearest ancestor with a containment context.

Container Query with name

Container Queries (size)

Baseline 2023 Newly available

  • Chrome
    since Sep 22

  • Edge
    since Oct 22

  • Opera
    since Dec 22

  • Firefox
    since Feb 23

  • Safari
    since Sep 22

See caniuse.com

Polyfill (there are more)

Container Queries (style)

Limited availability

Check regular CSS declarations
(not yet supported)

When supported, this basic example will make the background color of any b and strong elements yellow when the parent is already bold. See mdn.

Example with registered property

Only elements that differ from the initial value, in this case, the main and its descendants that inherit that changed value, are a match. Again mdn.

Limited availability

  • Chrome
    partial support

  • Edge
    partial support

  • Opera
    partial support

  • Firefox
    not supported

  • Safari
    not supported

See caniuse.com

inert

Baseline 2023 Newly available

A global HTML attribute to make an element inactive.
No clicking. No focus. No select. Also hidden from the accessibility tree.

A div with usual elements.

Same div with inert → no interaction

A simple slider with teaser elements

Same slider with inert

Warning Icon

Be careful how you use it. Every user needs to know if an element can be interacted with or not. inert itself does not change the design.

For individual controls it is better to use the disabled attribute – and :disabled class.

inert

Baseline 2023 Newly available

  • Chrome
    since May 22

  • Edge
    since May 22

  • Opera
    since Jun 22

  • Firefox
    since Apr 23

  • Safari
    since May 22

See caniuse.com

Bacon ipsum dolor amet turducken t-bone rump buffalo labore cupim ut meatloaf corned beef hamburger proident. Laborum boudin bacon, ullamco frankfurter chuck cillum doner sint dolore. Sirloin pork belly tenderloin enim et commodo sed lorem chuck.

sausage velit, voluptate in bresaola flank ground round. Ut veniam drumstick shank landjaeger. Spare ribs adipisicing consequat anim bacon aliqua labore pastrami brisket fatback beef exercitation duis aute. Aliqua aute landjaeger, pariatur velit t-bone sausage nisi fugiat enim magna sint.

Spam Spam Spam Spam

<dialog>

Baseline 2022 Newly available

HTML element for a modal or non-modal dialog box or other interactive component.

Example from mdn: HTML

The dialog is hidden by default.

Example from mdn: CSS

A pseudo-element to style the background.

Example from mdn: JS

What do you get?

<dialog>

Baseline 2022 Newly available

  • Chrome
    since Aug 14(!)

  • Edge
    since Jan 20

  • Opera
    since Sep 14(!)

  • Firefox
    since Mar 22

  • Safari
    since Mar 22

See caniuse.com

popover

Baseline 2024 Newly available

The popover global attribute is used to designate an element as a popover element.

Similar to dialog, but there are differences.

Example from mdn, JS

Look ma, no JavaScript!

popover

Baseline 2024 Newly available

  • Chrome
    since May 23

  • Edge
    since Jun 23

  • Opera
    since Jun 23

  • Firefox
    since Apr 24

  • Safari
    since Jun 23

See caniuse.com

dialog vs. popover

CSS Nesting

Baseline 2023 Newly available

Just like you know it from SASS or LESS.
For the most part.

CSS, without nesting selector &

CSS, with nesting selector &

equivalent to this CSS

Nesting with combinators

Here the & nesting selector is optional.

Nesting with compound selectors

For compound selectors (multiple conditions on a single element) the & nesting selector must be used.

Appended nesting selector

Concatenation

CSS Nesting

Baseline 2023 Newly available

  • Chrome
    since Dec 23 (partial before)

  • Edge
    since Dec 23 (partial before)

  • Opera
    since Dec 23 (partial before)

  • Firefox
    since Aug 23

  • Safari
    since Dec 23 (partial before)

See caniuse.com

PostCSS plugin

What about mixins?

A @mixin in SCSS

CSS Mixins & Functions Proposal

CSS Mixins & Functions

There is a proposal by Miriam Suzanne from Sep 13, 2023. This includes not just Mixins, but also Functions.

On Feb 12, 2024, the CSS Working Group has resolved to adopt this proposal, and begin drafting a new specification for CSS Mixins & Functions.

This actually became a W3C Editor’s Draft during my time in Burgas: CSS Functions and Mixins Module

CSS Cascade Concept

Find a value

  1. Relevance:
    Find all the declaration blocks with a selector match for each element.

Origin and Cascade

Specificity: example l

Specificity: example 2

Specificity: example 3

:where and :is

supported by all browsers since 2021

Specificity: example 3 (again)

 

Approach: Use only classes

Approach: BEM

Approach: Tailwind

More realistic example

More realistic example

1. Change #main code

2. Use !important

3. Use higher specificity

4. Work with @layer

CSS Layers

Baseline 2022 Newly available

A way to organize CSS to avoid specificity problems.

Simple layers

Better order your layers

Anonymous layers & unlayered declarations

Let’s get dangerous

Example taken from mdn

Nested layers are possible

Layers can be imported

CSS Layers

Baseline 2022 Newly available

  • Chrome
    since Mar 22

  • Edge
    since Mar 22

  • Opera
    since Mar 22

  • Firefox
    since Feb 22

  • Safari
    since Mar 22

See caniuse.com

My take

Keep it simple

CSS @scope

Limited availability

Limit the reach of your selectors.

Easy example

Another way

But, we already know how to do that

New selector :scope

Possible Variations

Specificity

Not the same

The Donut rises

The Donut rises

The Donut rises

The Donut rises

Of course this can be nested

Website Documentation

.manual

Text

Component from Website
as image

Text

Website Documentation

.manual
 

Text

Component from Website
@scope (.component)

Text

Website Documentation

.manual
@scope (.manual) to (.component)

Text

Component from Website
@scope (.component)

Text

Better example: Color themed components

Some text within .theme-light

Some text within .theme-dark

Without scope

Nested Color themed components

Some text within .theme-light

Some text within .theme-dark

Some text within .theme-dark

Some text within .theme-light

With scope

Result with scope

Some text within .theme-light

Some text within .theme-dark

Some text within .theme-dark

Some text within .theme-light

Note: Scoping proximity overrules source order but is itself overridden by other, higher-priority criteria such as importance, layers, and specificity.

See mdn.

Scope with varied specificity

Result with bad scoping

Some text within .theme-light

Some text within .theme-dark

Some text within .theme-dark

Some text within .theme-light

CSS @scope

Limited availability

  • Chrome
    since Oct 23

  • Edge
    since Oct 23

  • Opera
    since Dec 23

  • Firefox
    not supported

  • Safari
    since Mar 24

See caniuse.com

CSS Cascade Concept

Find a value

  1. Relevance:
    Find all the declaration blocks with a selector match for each element.
  2. Importance:
    Sort rules based on whether they are normal or important.
  3. Origin:
    Sort rules by author, user, or user-agent origin.
  4. NEW Cascade layers:
    Sort by cascade @layer.
  5. Specificity:
    ID (#example) > Class (.example) > Type (p) > No value (*).
  6. NEW Scoping proximity:
    Sort by @scope.
  7. Order of appearance:
    Last declared selector wins.

CSS Logical Properties

Widely available

Logical properties and values provide control of layout through logical, rather than physical, direction and dimension mappings.

Useful for multilingual sites.

Old property names

Old properties

New property names

writing-mode relative new properties
– here corresponding to western languages

The position depends on the language.

Auf Be’eris Mauern schrieb ich ihre Geschichte
Aus den von Kälte zerrissenen Ursprüngen und Tiefen
Nun lest das Geschehene im Schmerz und in ihrem Lichte
Fallt in den Nebel und in die Dunkelheit der Nacht und in den Urschrei

עַל קִירוֹת בְּאֵרִי כָּתַבְתִּי קוֹרוֹתֶיהָ
מִמְּקוֹרוֹת וּמַעֲמַקִּים קְרוּעֵי קֹר
עֵת קָרְאוּ אֶת הַקּוֹרֶה בַּכְּאֵב וְאוֹרוֹתֶיהָ
נָפְלוּ לַעֲרָפֶל וַאֲפִלַּת לַיְלָה וִילָלָה כְּמָקוֹר

Taken from the Jewish Museum Berlin

HTML

Current solution (actually from 2020)

Alternative without reset

But here you need to know all possible languages.

Better solution

CSS Logical Properties

Widely available

(worked before Baseline came along)

  • Chrome
    since Mar 21 (partial before)

  • Edge
    since Mar 21 (partial before)

  • Opera
    since Apr 21 (partial before)

  • Firefox
    since Mar 19 (partial before)

  • Safari
    since Sep 21 (partial before)

See caniuse.com

It might be a good idea to adopt this syntax in every project as there are more features that are using block and inline values.

For western languages you only need to know: block works vertically, inline works horizontally.

Scroll- driven Animations

Limited availability

Animate stuff based on the scroll position of a scroll container.

Note: Scroll-driven, not scroll-triggered!

Heart Icon

time-based animation

Scroll Progress Timelines with scroll()

Scroll Progress Timelines

 

Heart Icon

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

Here the heart is tied to the scrollbar. That’s not useful.

Heart Icon

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

View Progress Timelines

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

Heart Icon

Now the heart is tied to its own visibility inside the scroller, based on entering and leaving the current viewport. In Firefox the heart is visible, but static.

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

Scroll- driven Animations

See some better examples here:
scroll-driven-animations.style

Limited availability

  • Chrome
    since Jul 23

  • Edge
    since Jul 23

  • Opera
    since Jul 23

  • Firefox
    not supported

  • Safari
    not supported

See caniuse.com

CSS Feature detection
& user preferences

transition-behavior @starting-style aka
Transitions with display: none

Limited availability

Are we there yet?
Are we there yet?
Are we there yet?

transition-behavior @starting-style aka
Transitions with display: none

Limited availability

caniuse.com is a bit confusing right now, as there are many interacting items with different support.

:user-valid :user-invalid

Baseline 2023 Newly available

Better versions for :valid and :invalid.



:user-valid :user-invalid

Baseline 2023 Newly available

  • Chrome
    since Oct 23

  • Edge
    since Nov 23

  • Opera
    since Nov 23

  • Firefox
    since Apr 21 (partial before)

  • Safari
    since May 23

See caniuse.com

@supports selector() is supported by all browsers since Apr 2021.

new @media queries

Old @media syntax

Level 4 syntax

Baseline 2023 Newly available (caniuse)

Old @media syntax

Level 4 syntax

Baseline 2023 Newly available (caniuse)

Check for JavaScript

Baseline 2023 Newly available (caniuse)

Checks user preferences on device

Limited availability (caniuse)

Less data

Limited availability (can be enabled in Chromium, since 2020, caniuse)

Masonry Grid Layout

I had planned to show the plans for Masonry layout (extension to Grid Layout). But don't bother. This is a few years old, but it is going nowhere. See mdn.

(I am just mentioning this, because it was in the teaser text.)

Update 03.07.24: I’ve been wrong about the state of Masonry. Watch this talk from Rachel Andrew: Layout and Reading Order | CSS Day 2024

Link Icon

textformer.de/ddd24