(AKA things you may have missed
in the last 5+ years)
display:flex;
display:grid;
var(--custom-property);
@container
@layer
:has()
<select>
<select>
body {
color: #000000;
background-color: #ffffff;
}
.invert {
color: #ffffff;
background-color: #000000;
}
// _vars.scss
$color-ink: #000000;
$color-paper: #ffffff;
// _style.scss
body{
color: $color-ink;
background-color: $color-paper;
}
.invert{
color: $color-paper;
background-color: $color-ink;
}
:root{
--color-ink: #000000;
--color-paper: #ffffff;
}
body{
color: var(--color-ink);
background-color: var(--color-paper);
}
.invert{
color: var(--color-paper);
background-color: var(--color-ink);
}
Bonus round?
(Bonus Round)
@property --my-color{
syntax: "<color>";
inherits: true;
initial-value: black;
}
p{
color: var(--my-color);
}
Support:
(Credit: Miriam Suzanne)
(Credit: Jen Simmons)
/* before.... */
.wrapper .title{
/* styles */
}
.wrapper .content{
/* styles */
}
.wrapper .actions{
/* styles */
}
/* after.... */
.wrapper {
.title{
/* styles */
}
.content{
/* styles */
}
.actions{
/* styles */
}
}
A Common Problem
.input-wrapper:has(input:invalid)
<div class="input-wrapper">
<input type="email" value="alex" />
</div>
:has()
This:has(a.solution)
.blue-box{
display:grid;
grid-template-columns: 1fr;
}
@media screen and (min-width: 450px) and (max-width: 1023px){
.blue-box{
grid-template-columns: 1fr 1fr;
}
}
@media screen and (min-width: 1024px) and (max-width: 1439px){
.blue-box{
grid-template-columns: 1fr;
}
}
@media screen and (min-width: 1440px){
.blue-box{
grid-template-columns: 1fr 1fr;
}
}
.blue-box-wrapper{
container-type: inline-size;
container-name: blue-box;
}
.blue-box{
display:grid;
grid-template-columns: 1fr;
}
@container blue-box (min-width: 450px) {
.blue-box {
grid-template-columns: 1fr 1fr;
}
}
.text-red{
color:red;
}
.my-class{
color:blue;
}
.text-red{
color:red !important;
}
.my-class{
color:blue;
}
.my-class{
color:blue;
}
.text-red{
color:red;
}
.my-wrapper .my-class{
color:blue;
}
.text-red{
color:red;
}
@layer style, utility;
@layer style {
.my-wrapper .my-class{
color:blue;
}
}
@layer utility{
.text-red{
color:red;
}
}
@layer style, utility;
@layer utility{
.text-red{
color:red;
}
}
@layer style {
.my-wrapper .my-class{
color:blue;
}
}
@layer framework, style, utility;
@import url('framework.css') layer(framework);
@layer utility{
.text-red{
color:red;
}
}
@layer style {
.my-wrapper .my-class{
color:blue;
}
}
Yay! It was finally resolved by CSSWG to add strong custom cascade layers in #CSS, using a ^ symbol at the beginning, like
— Roma Komarov (@kizu.front-end.social.ap.brid.gy) February 12, 2025 at 12:16 PM@layer ^top
, which will make it possible to put things over the default layer: https://github.com/w3c/csswg-drafts/issues/6323#issuecomment-2654364266
/* in scss */
$primary: #639;
$primary-hover: lighten($primary, 25%);
body{
background-color: $primary;
}
body:hover{
background-color: $primary-hover;
}
/* compiled CSS */
body {
background-color: #639;
}
body:hover {
background-color: #a679d2;
}
:root{
--c-primary: #639;
--c-primary-hover: hsl(from var(--c-primary) h s calc(l + 25));
}
body{
background-color: var(--c-primary);
}
body:hover{
background-color: var(--c-primary-hover);
}
<select>
Element<select>
do this:A Basic Select with some style
appearance: base-select
::picker(select)
<selectedcontent>
Baseline Support
Jon Neal - For making an app that says the date when features were added to the browser
Alex Riviere
CodePens:
<button
type="button"
class="tooltip-button">
?
</button>
A Common Problem
Look at me, I'm a tooltip!
<button
type="button"
class="tooltip-button">
?
</button>
<p class="tooltip">
Look at me, I'm a tooltip!
</p>
A Common Problem
Look at me, I'm a tooltip!
<button
type="button"
class="tooltip-button">
?
</button>
<p class="tooltip">
Look at me, I'm a tooltip!
</p>
A Common Problem
Look at me, I'm a tooltip!
<button
type="button"
class="tooltip-button">
?
<p class="tooltip">
Look at me, I'm a tooltip!
</p>
</button>
A Common Problem
Look at me, I'm a tooltip!
<button
type="button"
class="tooltip-button relative">
?
<p class="tooltip absolute">
Look at me, I'm a tooltip!
</p>
</button>
A Common Problem
Data | Data | Data |
---|---|---|
Data | Data | Data |
Data | Data | Data |
Look at me, I'm a tooltip!
Header 1
Header 2
Header 3
A Common Problem
A simple example
.tooltip-button {
anchor-name: --tooltip-button;
}
.tooltip {
position: absolute;
position-anchor: --tooltip-button;
left: anchor(right);
align-self: anchor-center;
}
A simple example (forked from web.dev)
A different way
.tooltip-button {
anchor-name: --tooltip-button;
}
.tooltip {
position: absolute;
position-anchor: --tooltip-button;
left: anchor(right);
align-self: anchor-center;
}
A different way
.tooltip-button {
anchor-name: --tooltip-button;
}
.tooltip {
position: absolute;
position-anchor: --tooltip-button;
position-area: right center;
}
A different way
Baseline Support
Basic Popover
Manual Popover Options
Baseline Support
Basic Popover
Popover with Anchor Positioning
Alex Riviere
CodePens:
<style>
p{
color:red;
}
</style>
<p>This is red text!</p>
<style>
p{ color:red; }
</style>
<p>This is red text!</p>
<div>
<style>
@scope{
p{ color: blue; }
}
</style>
<p>
This text is blue!
</p>
</div>
* Full support planned in Interop 2025
Alex Riviere
CodePens:
min() Example
max() Example
clamp() Example
Alex Riviere
CodePens:
sin()
cos()
tan()
asin()
acos()
atan()
atan2()
Alex Riviere
CodePens: