CSS Containers, What Do They Know?

Introduction and The AI Button

Miriam Suzanne opens her talk with a humorous anecdote about creating an AI-powered button to match her outfit, setting a lighthearted tone for the discussion on container queries.

Container Queries: Unveiling Their Secrets

Miriam introduces the core topic: container queries. She highlights the long-standing developer desire for this feature and its eventual arrival after years of anticipation.

Container Queries in Action: A Simple Example

A concise demonstration of how container queries work in practice, emphasizing their simplicity and ease of implementation in most cases.

The History and Evolution of Container Queries

Miriam delves into the historical context of container queries, explaining why they were initially deemed impossible due to the risk of infinite layout loops. She traces the evolution of web design principles, from the early days of the web to the emergence of responsive and intrinsic web design.

Intrinsic vs. Extrinsic Sizing and the Challenge of Container Queries

An explanation of the interplay between intrinsic and extrinsic sizing in CSS and how this dynamic presented a challenge for implementing container queries without causing infinite loops.

Containment: The Key to Enabling Container Queries

Miriam discusses the crucial role of containment in making container queries possible. She explains different types of containment (size, inline-size, layout, style) and their impact on layout calculations.

Container Types and Naming Conventions

Practical advice on using container types (inline size, size) and naming containers for easier querying and management.

Querying Containers: Syntax and Strategies

A guide to the syntax of container queries, including how to specify container names and query containers further up the DOM tree. Nesting containers and practical examples are also covered.

Container Queries and Element Measurement

Miriam explains how container queries measure elements, which differs from media queries measuring the viewport. This difference allows for referencing element-specific properties like font size.

Calculations and Container Relative Units

Using `calc()` within container queries and the introduction of container relative units (CQI, CQH, etc.) are discussed, along with examples of their practical applications.

Turtle Components: Addressing Grid and Flexbox Measurement

The concept of "turtle components" is introduced as a solution for measuring grid tracks and flex items accurately. This technique involves wrapping elements in an extra container.

More Demos and Advanced Use Cases

Showcasing additional demos, including responsive weather components, web components leveraging container queries, and animation techniques using container units.

Style Queries: Querying Custom Properties

Introduction to style queries, allowing querying of custom properties within containers. The limitations and potential use cases of style queries are explored.

State Queries and Responsive Images

A brief overview of upcoming state queries (e.g., scroll state) and how responsive images can be handled in the context of container queries, including the `sizes` attribute and the `auto` value.

Conclusion: Containers Do Know Stuff

Miriam concludes by summarizing the key takeaways about container queries and their capabilities, encouraging developers to utilize this powerful feature.

It's nice to be here.

I've never been to Australia before.

It's hot here compared to Denver.

We're in the middle of a snowstorm, I think.

Also more sunlight.

I like that.

Yesterday, the trend was to have slides that match your outfit.

So I made myself this little button.

It's AI.

You can tell because it's got the little sparkles.

I'm going to get really confused by this all day.

I'm going to be walking back and forth pointing it.

All day.

I'm on here for, yeah.

Oh, that extracts all your private data in real time, and then matches my outfit.

That's how it works.

I only applied it to one slide, because I like colors.

We're gonna talk about containers.

What do they know?

What aren't they telling us?

What are they hiding in there?

It worked!

Yes!

I got one in the middle.

This is the new trend for today.

Please, all speakers.

Get a, get slides in the middle.

All right.

Off to a good start.

So as long as I can remember working in CSS, developers have been asking, what do containers know?

Do containers know stuff?

In 2010, we got media queries, they finally rolled out in all the browsers, and Ethan Marcotte coined the term responsive web design, and that term has lasted for over a decade, and it was very cool that we could do a lot with that, and immediately, so we can, let's see, let's just look at this, so we can measure the viewport, and we can adapt based on the size of the viewport.

So we can have these cards that have a small layout, and then a larger layout, and then we can, add a sidebar and it all breaks.

That's really powerful, but right away we wanted to know, could we do the same thing with containers?

Measure something smaller, not the entire viewport.

Right away, you can't see this, but this is a polyfill that came out in 2011, to implement container queries.

People wanted this immediately, and over the years it's gone by many names, selector queries, element queries, container queries.

And it became, the most requested feature on all the surveys.

Everybody wants it.

And the browsers were there and they heard us asking and they said, No.

Not ever.

Stop asking.

It's just not gonna happen.

Please do not query the containers.

It's not even gonna be possible.

Because, it would cause infinite layout loops.

The end.

That was the past.

And, we live in the future.

Sorry, not this future, we get rising authoritarianism.

I had a joke here about flying cars and spicy autocomplete and it felt wrong.

Yeah, I don't know.

I'm, really struggling to be in an industry where we get really excited about new toys, without always thinking about how they're used in the world and the damage that they can cause.

That's a different talk, but I want us to think carefully.

About the direction we want to be heading and what direction the web is going and how it impacts real people's lives.

So hopefully you'll take that away.

I'll move on.

I don't remember what I was talking about, but I made another little AI here that will tell me, this is inspired by Phil's, that asks, let's see, what was Miriam talking about?

Okay.

Danger of hypotheticals, no, the other thing.

Should be talking about container queries.

Okay, great.

Let's do that.

So large language models know nothing.

I think Phil said that.

But containers actually do no stuff.

Now, I want you to know that I had this slide before.

Phil, or, before, I, sorry, I missed the slide you actually had, so I replaced it here.

It was something like that.

And then, Chivay had John Snow, and I was like, they're, just stealing my work.

Did I get, yes!

Yeah, so container queries have been available in all browsers for almost two years now.

Still considered newly supported, but, they've been around for a while.

And, yeah, let's just see.

So here we're still getting the media query, effect here, where we're getting the large card in both the sidebar, and the main area.

And what we're gonna do is just change where it says media.

Is that large enough for people to see?

We're going to say in container, if we can type and that's not going to work, but we just have to create some containers, container type inline size.

And now, we know that those two are separate containers and they can move separately.

That's it.

Yeah, there's container queries.

In the browser.

Working great.

We have to create containers, and then we query them.

Any questions?

It really is that easy, 95 percent of the time.

I'm gonna spend the rest of my time talking about all the weird edge cases and complexities.

And you're just gonna have to ignore all that and not think container queries are complicated.

They're not.

That was it.

That's the whole thing.

Now I'm gonna waste the next half hour.

You, so you might be, it'd be fair to ask how, if this was impossible two years ago, or three years ago, because I guess it rolled out two years ago.

How did we get here?

What about those infinite layout loops?

And in order to understand why container queries work now, and how they work, we have to understand why they shouldn't work.

Because the browsers were right, they shouldn't work.

And we have to go back in time a little bit for that.

When the web was first rolled out, Sir Tim and the team at CERN, released the first browser, the Hypermedia www browser and editor, wish browsers were still editors, but they made it for the next machine, which has this fancy graphic interface, but you can't make a web this worldwide by saying it works on my machine and everyone else is an edge case.

So they rolled out a second browser, which you can't see, called the line mode browser.

It's text only.

Loads on any terminal.

You don't even need to install it on your machine.

You telnet into their servers and you can start surfing the web.

You don't need graphics at all.

Really powerful.

This is the powerful, feature of the web.

Is that it can do a worse device.

That's the whole point.

That's what we're here for.

This becomes the mission statement of the W The W3C, the World Wide Web Consortium, Web for All, Web on Everything.

And everything is a whole lot of things.

All of these mobile devices, and then devices without any screen at all.

This was planned for from the beginning.

And then screen readers, which have a screen, and then Read it, which is an interesting combination.

This is also a braille, device there.

Yeah, the web is sticky and getting on everything.

It's just everywhere.

And this is fundamentally different from print, where we can go into InDesign or something and we can, choose the size of the page and we lay it out and we can send it to the printer.

And we can tell them what paper we want it on and, what inks to use.

And we get back something and then you can click on it all you want and it just sits there.

It doesn't do anything.

The fact that we control the paper page is a limitation of that medium.

This is an unknown.

John something.

If you ever meet him, tell him thank you.

This is a fantastic article from 2000 that's still relevant.

We're not alone here.

This project that we're doing, this web, we're not in control of it.

We have to share this space, with the browsers, who are, intermediaries, to the users, who all have these tool belts, all of them, super cute, I love it, and they bring their own devices, with their own preferences, all sorts of different interfaces, and probably aliens, who knows?

Web designs need to adapt in a way that print design doesn't get to.

And not only to the width of the viewport, but, user preferences, device interfaces, browser compatibilities changing over time.

New standards, all sorts of things.

We're trying to do graphic design of unknown content with unknown collaborators on an infinite and unknowable canvas across operating systems, languages, interfaces, writing modes.

This is fucking absurd!

But it's worth it!

Because this is the mission!

This is what we're trying to do, a web for everyone on everything.

It's a political vision, and it's worth fighting for.

Everything that we build is political, and worth fighting for.

And then we get more and more content, right?

And we're shoving it onto smaller and smaller screens, and we gotta figure out how to make it all fit.

How are we gonna get it in there?

We got this context pushing in.

And we've got our content pushing out and everything in CSS is based on this back and forth between extrinsic sizes, anything coming from outside.

And intrinsic sizes, the size that the content wants to be on its own.

And we get that push and pull, that back and forth.

Extrinsic sizes come from the viewport and, boxes getting smaller inside of it.

But they also come from, widths or heights that we apply, right?

We can apply, we can be the outside force.

We can provide context, pixels or percentages or ems or whatever.

It doesn't matter whether they're relative or fixed or fluid.

Those are all extrinsic.

They came from us.

And then we've got the intrinsic sizes that we can now use keywords to access and do some things with, min-content, max-content, fit-content, and often auto.

Auto does everything.

And this all comes together in normal flow, which is so normal in the web.

It predates CSS and we often don't even refer to it by any sort of name.

It's just the default, but it's super powerful.

Look, I can change the size of the box and things just move around.

They just resize to fit.

I can change the size of this box, and everything pushes down.

InDesign can't do that.

That's, powerful.

We can add more text.

And, it'll make that box bigger, and it'll overflow this box.

All sorts of things that are happening to make this negotiation between intrinsic and extrinsic sizes possible.

Flow is really very cool, actually.

It makes the web responsive.

Ho!

I hope you saw a flash of that before it disappeared.

Yeah, CSS really is awesome.

And at this point, I'm just going to fix that the easy way.

And then over the years, we got more ways of flowing content.

So Flexbox or grid.

And Jen Simmons has started to call this intrinsic web design, this new era, an evolution of responsive web design.

But with responsive web design, we had to force everything to be percentages, which means removing the intrinsic sizes.

We always just ripped out the intrinsic size and replace it with a percentage.

And that's forceful and extractive in a way.

And with intrinsic web design, we can start to combine these things.

We can use percentages sometimes, we can use fractions sometimes, pixels.

We can mix and match because Grid and Flexbox are able to do that.

We get truly two dimensional layouts combining fluid and fixed, values.

We get different stages of squishiness.

If you want to understand squishiness, come to my workshop tomorrow.

Nested context that expand and contract with the content and then media queries as needed.

Less necessary because we've got all these other sorts of ways of working with intrinsic sizes, but there's a problem here, right?

Nested context that expand and contract with the content.

Aren't we going to want to measure those?

We're going to want to know the size of those boxes.

But there's, this is, the issue.

We've got forces pushing in, we've got forces pushing out, and we want to measure one of them to change the other one that's going to change the size of the box.

That's going to change the size of the content.

That's going to change the size of the box.

Which is going to change the size of the content.

Which will change the size of the box.

We're going to do this for the next time.

There's your infinite loop.

That's the one.

That's it.

Our queries, if we want container queries, they cannot change the container that they're querying.

That's fundamental.

If the query can change the container, we've failed.

Directly or indirectly.

And there's a lot of indirect things in, in layout.

Because of this sort of back and forth negotiation, a lot of things happen indirectly.

We make something taller, it gets a scroll bar, that makes it narrower.

There's all sorts of these interactions, that we have to stop.

We have to turn them off if we want to query something.

So for size queries, which is the main thing that people were looking for, we have to just turn off intrinsic sizing completely.

That has to go away, which, as you can imagine, is invasive.

But over the years, while browsers were telling us no, they were working on other features that would form the foundation of this.

They had an idea that it might work if we do all these other steps, and they found other ways that these are useful.

Containment was sold as a performance.

A performance enhancer?

Is that the way you say it it was sold for performance, but it's, it will also help us get container queries.

Let's just look at this again, because, so size containment does what we want.

It turns off intrinsic sizes.

But that might not do exactly what you want.

Let's say, contain size.

Nailed it!

It's gonna be perfect!

So it's dangerous to turn off intrinsic sizes for everything.

Boxes just collapse.

But there's a little bit of nuance here.

Okay, I've got this h1, and I have it set to display inline, just so that, we can see that when, it's an inline box, and I add, content, it expands on the inline axis.

If I go to another line, it actually creates a new box, it fragments, fragmenting across pages when we print.

The line box fragments, and we get a new box below.

So the height of an inline box is not impacted by the content.

Only the width is impacted by the content.

The inline size is impacted by the content.

But if we change this back to display block, like an h1 usually is, we see the opposite.

Look, it's full width.

It doesn't care what content's inside of it.

It's always going to be full width.

It only changes on the block axis.

Inline elements only change on the inline axis.

With the content, block boxes change on the block axis depending on the content.

That gives us some possibilities here.

Because only the block size is intrinsic, and we generally want to measure the inline size, and the inline size is already extrinsic, what if we just had inline size containment?

And this stalled the project for, a couple years.

Because of those things where I think, content getting taller can add side scroll bars, which make it narrower.

Like all those sorts of interactions stalled the project.

And Chrome at one point had a working demo, and we still thought the project might fail.

Which was a super weird place to be.

Like I had, I was showing people on stage working demos and saying, we might never ship this.

And then I had panic attacks.

It was great.

So we can see this working.

We'll just, so it's just a box with some content in it.

If we contain size, we saw what happens.

It collapses because it's, pretending it doesn't have content for the sizing.

But if we just, contain the inline size.

We're back to normal.

It's fine.

The inline size was extrinsic anyway.

It will stay that way.

There's certain cases where that becomes an issue if we're doing something where it's going to shrink wrap.

I guess like floats, you know how floats shrink wrap to the content?

So there's times when that won't work for us.

And we might need to provide an extrinsic size.

But generally, that's safe.

I already told you about the dragons.

So we got inline size containment.

We made this work, we made it work across browsers.

I didn't.

I was just there being like, here's all the problems.

Hey browser engineers, can you fix it?

And they did.

We did not get block size containment.

There's too many situations, where changing the content on the inline size impacts the block size.

There were too many loops that we couldn't, leaks, of information between the two axes that we couldn't shut them all down.

Most of the time we're going to use inline size containment, we got that.

We can also sometimes use size containment.

It's there, if we want it.

We also need to contain, we thought layout.

And we found that we don't need full layout containment and we're rolling that back a little bit.

This is a difference that you'll see right now.

Chrome has rolled that back and the other browsers haven't yet.

And I'll show you the differences there.

So let's see what all of these, yeah, I'm sorry.

She is so disappointed in you.

I don't know what you did, but she is not impressed.

All right.

We've got, this is the container down here that we're dealing with, and I contain size and it collapses.

I've got a figure inside of each one, and they're using, numbering, counters to do the numbering on the figures.

And then we've got a position, a fixed positioned element there that's fixed to the viewport, right?

If we change this to be layout containment, We see, oh, we wrapped the float.

We did basically a clear fix on the float, but we also contained the fixed position element.

And that's what we didn't want.

That's why we're rolling back layout containment now.

That shouldn't happen.

It still happens in some browsers when we use container queries, but it will stop happening.

And then, if we did style containment, we see that the number changes on this figure.

This is one of the weirdest loops to me.

You could change the numbers inside of a container, and that could, you could do that based on a container query, and that could change the numbers outside of a container, and then the whole page could reflow based on the, based on that number being larger.

And yeah, using counters, you could cause a layout loop in container queries.

So we had to add style containment.

Counter, it's basically just counters.

Counters don't work across the boundary of, of a container.

But we don't want to write this all out, right?

We don't want to write contain, inline size, layout, and style.

And we didn't want to be like stuck to it, right?

We wanted to be able to make adjustments and say, actually, what do container queries actually need?

What do different types of containers need?

Let's just apply the containment that's needed.

And then it's a little bit more flexible.

So instead of contain inline size layout style, you just say, what container type do I want in the browser figures out.

What containments are needed for that.

So container type inline size.

We've now gotten back to where I was five minutes in.

Container type inline size.

That's what you're gonna want.

We can only measure the axis we contain.

So at this point we can only measure the inline axis.

But that's fine.

Whatever.

We didn't even want the block axis.

Leave us alone.

Usually that's all we want.

So we're going to use inline size for most containers.

But we can use size, especially, I mean there's maybe other places, but especially scrolling containers.

If we're adding scroll to a container, then it's already ignoring its content and sizing to something else, right?

It has to have an extrinsic size because the content is overflowing it.

So it's not getting its size from that.

So when we've got containers that scroll, we can apply size containment.

I'll, let you trust me on this one.

I applied size containment to all those things.

They're getting their sizing from the grid, which is based on the viewport.

And, it's fine.

They can overflow.

The content has somewhere to go.

So there are times that we can use size containment and query both axes.

For various reasons, there's no default container.

We need to add containers explicitly.

I have a whole article about the problems with root containment and what it would do, and it breaks everything.

Often this is the sort of thing that I do at the beginning of my project.

I just say, all of these main areas, that are inside my body, they're all containers.

The header, nav, main, aside, footer, whatever I've got there, give me some, low level containers, and then I'll add other containers as I need them.

It's also recommended, but not required, that you name containers.

This can be powerful, so you can say, I think of these both like IDs and like classes, so sometimes I'll be like, it's the main thing.

Call it main, and there's only going to be one of those.

But it's also one of my layout containers.

And I'm gonna have a bunch of those.

So I can give it some names, and I can give it as many names as I want, name it anything I want.

And I can use a shorthand.

The shorthand names are required, so if you're gonna If you're not using names, you've got to use the longhands.

But you can say whatever names you want, and then a slash, and then the type of container.

And then we can start querying those containers.

Anything inside of them we'll look to see.

And it's, oh, and we can add names there in our query.

So we can say, this is because by default, we're just looking at the one directly above.

But sometimes we want to look at like a container farther up the tree, right?

So this lets us do that.

We can say, Oh, actually, go to the main container and tell me what size it is.

There's also, we've decided that you can leave the query out and just.

Say the name of a container, which is a little bit like nesting.

You can just say, am I in a layout container?

Am I in the main container?

And you don't even need to put a size query there.

I don't think this has rolled out in any browsers yet.

But this is coming.

So for finding a container, first we match each element inside of a container query.

We look at those selectors, we match all the elements, and then we find the nearest ancestor that has both.

The container names you asked for and the container types that you are trying to query.

So we'll look for, if you're querying the width of something or the inline size of something, we'll look for an inline size container with the names that you wanted.

Elements can't query themselves.

They're always querying another element farther up.

But we can nest those.

Containers can query other containers farther up the tree.

And, Eric Portis made this demo to try and crash my browser.

It didn't work, but I love it as a demo.

36 chambers of container queries.

There's just each container getting its color from the size of the container above.

Most of the rest of this is just, different demos.

This one from Una Kravitz I like because, container queries aren't just for, big level layout stuff.

We can use them for all sorts of small things and nested things.

She's got a container query here on the button.

And then also on the SVG inside of the button, so all sorts of nested container queries dealing with different parts of that, little button.

We're always measuring an element, which changes some things about what we can do.

With media queries, we're measuring the viewport, which is not an element.

It's like above the root, but it doesn't have, we, it doesn't have a font size that we set or anything like that.

So we get some bonus things here.

In this case, we've got a media query toggling at 20 ems and a container query on the root toggling at 20 ems.

And, the root and the viewport are roughly the same size at this point.

So that's fine.

How come these are changing at different sizes?

They're both 20 ems, and it's because we've got this font size 2 ems.

We're looking at the actual font size of the root element with a container query, whereas they would go together if they're the same size.

If we've got the default size from the viewport on the root, then 20ems is the same.

But now we're looking at the actual size of an em on the root element, and we can adjust to what 20ems actually means for the container query.

So there's a lot of other stuff that we can do with that to, yeah, take advantage of knowing the actual sizes of things on the container because we're measuring an actual element.

We can also do some, interesting stuff by throwing calculations into queries.

I think this works on media queries too.

You're allowed to use calc in there.

So we can say I've got, I want it to go when there's space for three columns that are 30 characters each.

And here I'm doing some weird math to add in space for gutters, too.

We could probably simplify it to just say 32 ems, or 32 characters times 3 or whatever.

But it works.

It doesn't switch until we've got space for three of them.

Use calc.

It's a great little tool.

There's a little bit of a problem here by the fact that we're measuring actual elements, because with a grid track or flex sizing, that's not really what we want to measure.

The element is like a big box around the outside of our grid, and then we got all these grid tracks inside of it.

And we really, we're going to put things into those tracks, and we want to know the size of the track, not the size of the element.

So that's the downside of this.

And the solution is what I call turtle components.

They carry their container with them.

So I use that here for some flexbox cards that change to a different layout.

And it just means it means a little bit of extra HTML, right?

I just added an extra div.

It's not lovely, but it solves the problem.

So then I can set up the card wrapper as a container and the article can query that card container.

So a little bit of extra nesting, but it gets us where we want to be.

If you use web components, they give you that extra container by default.

It's the host element.

This demo by Max Bach I really love.

These are all just web components, that when you drag them into different spaces, they take different layouts based on the size that they have available.

And it's all using container queries on the host, as the container.

Treating that as the extra wrapper div, that we get for free.

This one, I have nothing to show you about it except that Martin Van Hoof did just some lovely work, making this very responsive, weather thing.

We also get container relative units, like viewport units.

We have VI, VW, etc.

Here we've got CQI, CQH.

Did you know there's a Q unit?

We couldn't use As our base, we had to use CQ, because there's already a Q unit.

It's a quarter of a millimeter.

I don't remember.

It's useful.

It probably is useful in print.

I don't know.

Scott Kellum has a great demo of adjusting sizes of, of fonts in these different boxes based on the size of the box available.

Val Head has used this for animations to say, take me from just before the container to just after the container, or either inside or outside.

So she has clouds moving across in an animation, and she's using container queries to make that work with this sort of little calculations using CQI and 100 percent .

With these, there is a default while container queries don't have a default

container that they look to as a fallback.

The units, it was too risky not to have some fallback.

So we use the small viewport.

If you didn't know there's multiple viewports, there is.

You can reference the large viewport or the small viewport or just use viewport or say dynamic viewport.

The, DVW, DVI, there's lots of units here for accessing different viewports.

Brahmus has a whole article about it, but it's basically is the Chrome there or is it gone, on a mobile browser?

So we use the small viewport, figuring that's the most reliable as a container fallback.

If there's no container there to look at, eventually, we're also going to get all the rest of these units, CQM, CQCH, what is the size of the font?

What is the size of a character on the container?

All these sorts of things will be able to reference and then maybe even a functional version where you pass in a container name and you can say, what is the size?

What is the CQI of a specific container?

That's probably coming to yes.

When we shipped this, we thought, what else, what other questions do we have for these containers?

And, OMG, we had so many questions for containers, not just the size.

Oh, look at this, what are we, yeah, alright.

So style queries were one of the things that came up.

What if we could query the style of the container?

This has also shipped.

In fewer browsers.

But we can query specifically the value of custom properties.

So we can say, does the container have the colors custom property set to invert or something?

And then we can do all sorts of things based on that.

We can only query custom properties for now, maybe forever.

Browsers haven't fully defined equality for all 596 properties, and they don't really want to, spend the year just solving equality.

But it's easy for them to do with custom properties, so we have it for custom properties now, maybe forever.

This is, this has limited support.

Firefox still hasn't rolled this out, but hopefully that's coming soon.

I know that somebody's working on it there.

For these, no containments required.

We can just use them.

And, we always query the direct parent, unless we provide a name, and then we can query something else.

But we're just querying if I'm in the context, that has, I don't know, my color's value set to something.

So all elements are style containers by default.

And we're always querying the direct parent.

We can play with this.

Yeah, here I'm using a style query.

Based on the set button theme.

So if I take away the button theme, those styles go away, or if I change the button theme to Mia plus, I get the.

Yeah, I used to be a designer.

All sorts of things we can do with style queries.

It can make light, dark schemes easier, because we could toggle one value and then query that value.

And we could toggle that property, based on both the media query for prefers-color-scheme and then also based on our settings.

We can use this to pass sort of, high level values into, custom elements, web components, and then change the whole design of the web component based on these high level values that we pass in instead of having to pass in low level values every time.

An important thing to remember is that the before and after elements are descendants of the box.

So we can put container, if we, if the box is a container.

We can have, this little arrow be a before element, and it can query the box.

So we can do all sorts of, styling that based on like arrow position, I just have that, arrow position value, and then I'm just doing a bunch of queries to see what that value is on the parent and apply it to, the after pseudo element.

Yeah, we could see how much space is available in a box.

And then change other values.

Where this is particularly useful is, changing other values than the one that we're querying.

So we want one property to change a bunch of properties, and we can do that here.

This is also Okay.

Yeah, lots we can do there.

This is, I'll let you come back to this.

This is just, you turn on test and it puts red outlines on everything.

Tab Atkins at one point tweeted back on Twitter, that this is valid CSS.

And it's true, this is entirely valid syntax in CSS, it doesn't do anything unless you make it do something, and so I have a demo using...

it's useful, You should please ship this in production tomorrow.

And then we thought, what about state queries?

What if we could see if the scroll state of the container is stuck or snapped or overflowing?

And Chromium in particular has been working on these, and, has some demos.

So here is scroll state.

You can see there's still some bugs.

There's a reason it hasn't shipped.

But there's just a scroll state query, for when the sticky header is stuck.

Mandy talked yesterday about, responsive images using the sizes attribute.

This isn't technically container queries, but, when we shipped container queries, everybody asked, what about images?

Can I, get image sizes, responsive images, based on the size of the container instead of the size of the viewport?

And container queries can't really help with that.

But we did get something out of that.

We got sizes auto.

Instead of specifying all the sizes, if we apply lazy loading.

So we can't use this on, say, header images.

But if we apply lazy loading, we can now also apply, auto as the sizes.

And I think back there somewhere I have, the browser support again isn't perfect.

Far from perfect.

The auto value here, supported in Chromium, supported a few places, but not Firefox or Safari yet.

Hopefully that will come.

Do containers know stuff?

Yes.

Containers do know stuff.

Feel free to ask them anything.

They won't always give you an answer.

But it will be determinative.

Is that the word I was looking for?

Anyway.

Things containers know.

Their size, if they're contained.

Their custom property values.

Their relative values, like ems, the size of the font.

Maybe some states, TBD, those are coming, hopefully.

So please do actually go out and query the containers.

Actually, thank you.

match my outfit

Background with a gradient spanning from red to blue.

✨ match my outfit

the same gradient background but in greyscale.
Aerial view of a busy shipping container yard with various colored containers organized in rows, intersected by pathways and labeled with identifiers such as P6, P7, and stop signs.
A fluffy cat sitting inside an open cardboard box against a plain background.

Please ignore this gap

Image of two cats sitting in cardboard boxes on either side of a pink squiggly line with the text 'Please ignore this gap' and a slide number footer.

Do containers Know Stuff?!

Image of Rodin's The Thinker with a red-drawn thought bubble containing the text "Do containers Know Stuff?!"

Responsive Web Design

by Ethan Marcotte · May 25, 2010

Issue Nº 306
Illustration of a group of people posing for a photograph with a photographer taking the picture.

Media vs Container

Screenshot of a webpage displaying two side-by-side sections labeled "media > 30em" with an image of a person and lorem ipsum text. The webpage has editing options like sidebar and containers.

Media vs Container

.root {
  display: grid;
  gap: 1em;
  margin: 1em;
}
header {
  grid-column: 1 / -1;
}
header,
aside,
main {
  background: gainsboro;
  padding: 1em;
}
.card {
  --media: "small";
  font-family: "Redacted";
  display: grid;
  grid-template-columns:;
  grid-template:
}
Side-by-side comparison of media vs container layouts showing images and formatted text blocks.

Media vs Container

Screenshot of a web page showing two examples of media versus container layout with images and text. The page includes options to edit on CodePen and buttons labeled "sidebar" and "containers".
Screenshot of a GitHub repository page titled "ahume/selector-queries". Shows a commit "Initial demo." on master branch by ahume on Jul 14, 2011, with 3 changed files: demo.html, readme.md, and responsive-containers.js, plus code changes preview for demo.html.

2011 - 2022

Selector Queries
Element Queries
Container Queries

A decade of media questions

Missing Features

What do developers feel is currently missing from CSS?

CSS 2019
Bar chart showing features developers feel are missing in CSS, including Container Queries, Parent Selectors, Nesting, Browser Support, Functions, Scoping, Mixins, Subgrid, and others, with respective percentages.

Do containers Know Stuff?

Image of "The Thinker" statue with browser logos (Chrome, Edge, Firefox, Safari) and a thought bubble containing the text "Do containers Know Stuff?".

" Not Ever."

– The Browsers

Please

Query Don't Containers Feed The Containers Animals

Container queries will never be possible on the web. They would cause infinite layout loops.

— The Browsers

Scene from a movie showing a gorilla-like creature holding a bone above a pile of bones under a cloudy sky.
Image of a spaceship in outer space with red and blue lights against a backdrop of stars.
fsi.stanford.edu/news/understanding-global-rise-authoritarianism

Understanding the Global Rise of Authoritarianism

Screenshot of a webpage at Stanford's Freeman Spogli Institute for International Studies. The headline reads 'Understanding the Global Rise of Authoritarianism'. Below the headline is a description of a discussion involving Ben Rhodes and Michael McFaul about nationalism and authoritarianism.

Web Directions

Ask SparkleBot (really a bot, I promise) ✨

Screenshot of a terminal interface with a text field labeled "Ask SparkleBot" and a button labeled "Fake Intelligence".

Ask SparkleBot (really a bot, I promise)

Miriam Suzanne is talking about the danger of tech hype cycles, that ignore the real-world harms caused by our fancy new toys.

No, the other thing.

Ask SparkleBot (really a bot, I promise) ✨

Miriam Suzanne is talking about the danger of tech hype cycles, that ignore the real-world harms caused by our fancy new toys.

No, the other thing.

Miriam should be talking about CSS Container Queries, which shipped across browsers in 2023.

Large Language Models

KNOW NOTHING
Image of Game of Throne's John Snow with long, dark hair and a fur coat, partly obscured by a text box.

ACTUALLY, I KNOW STUFF

Image of the top of a yellow shipping container under a blue sky. A thought bubble containing the text "ACTUALLY, I KNOW STUFF" is drawn in red next to the container.

Chain of thought

Slide showing a presenter next to a screen with text on it.

LLMs DON'T KNOW ANYTHING

Slide 29/170
Photo of two presenters on stage with a projected slide that includes a handwritten-style message, "LLMs DON'T KNOW ANYTHING," and an image of a character resembling John Snow from Game of Thrones.

LLMs DON'T KNOW ANYTHING

WTF? 30/170
The slide contains handwritten text "LLMs don't know anything" surrounded by several images: three faces and two people standing near a podium. There is also an image of a John Snow in the center.

Container Queries

February 2023 – newly supported

Slide with browser icons indicating support status, and a progress bar at the bottom.

Media vs Container (Live Demo)

Screenshot of a web-based interactive demo comparing "Media" and "Container" elements, featuring two side-by-side panels with placeholders for text and other elements.

Media vs Container (Live Demo)

.card { --media: "large"; border-color: darkslateblue; grid-template: "i t" auto "i c" 1fr "f f" auto / clamp(5em, 20%, 15em) 1fr; }
© CodePen
Image of a live demo comparing media queries vs container queries with code and two layout examples.
main,
aside {
    container-type: inline-size;
}

@container (width > 30em) {
    .card {
        --media: "large";
        border-color: darkslateblue;
        grid-template:
            "i t" auto
            "i c" 1fr
            "f f" auto
            / clamp(5em, 20%, 15em) 1fr;
    }
}

@layer setup {
    * {
        box-sizing: border-box;
    }
}

html {
Screenshot of a code editor displaying CSS code next to a live demo pane titled "Media vs Container (Live Demo)" with placeholders and design elements.
/* create some containers */
header, nav, main, aside, footer, section {
    container-type: inline-size;
}

Thanks.

Any Questions?
A sculpture resembling 'The Thinker' by Auguste Rodin is gazing thoughtfully. A red, cloud-like illustration contains the word "How?" with a question mark.

What about those Infinite Layout Loops??!

Screenshot of an early web browser interface displaying a text document on the left and a map of Geneva and surrounding areas on the right.
Screenshot of a WorldWideWeb browser interface from the NEXT machine, with an illustration showing a section of a map, and red arrows pointing towards icons including a cube labeled 'NeXT'.
An IBM computer with a monochrome monitor displaying system information in green text.
Screenshot of a text-based display of the early World Wide Web project with green text on a black background.

" Web for all. Web on everything."

W3C Mission Statement

A collection of multiple laptops, tablets, and smartphones arranged on a surface, showcasing a variety of sizes and forms.
Image of three smart speakers placed side by side, including Google Home, Amazon Echo, and Apple HomePod.
Person wearing headphones using a laptop with a braille display.
Illustration of a superhero in a crouched position, encased in elaborate cobwebs with a determined expression.
Screenshot of Adobe InDesign 2020 showing a document setup dialog and a magazine-style cover design with various illustrated characters and the title "GODS ON THE LAM" by CHRISTOPHER DAVID ROSALES.
A colorful book cover with retro-style illustrations including a man with a surprised expression, a laughing face, and a person holding a mask. The spine reads "GODS ON THE LAM CHRISTOPHER DA" and includes various vibrant, abstract doodles and designs.
"The fact we can control a paper page is really a limitation of that medium."
– John Allsopp, 2000

WE'RE NOT ALONE

Image of bold text 'WE'RE NOT ALONE' in 3D style against a starry space background.

WE'RE NOT ALONE

An illustration with text 'WE'RE NOT ALONE' in a space-themed background, featuring logos of Chrome, Firefox, Edge, and Safari browsers.
A person using a laptop wearing a tool utility belt with browser logos like Chrome, Edge, Firefox, and Safari in the foreground. The background displays large text reading "WE'RE NOT DONE".

WE'RE NOT

Collage with a person using a laptop, various browser logos, and an alien character against a starry background with text "WE'RE NOT".

Web Designs
Need to Adapt...

@supports
container-type: inline-size
Browser capabilities over time
Graphic design of unknown content with unknown collaborators, on an infinite and unknowable canvas, across operating systems, interfaces, languages, and writing modes...
– me
" Web for all. Web on everything."

W3C Mission Statement↗

Technology is Political

Background is the colors of the trans flag

CONTEXT (pushing in)

CONTENT (pushing out)

Diagram showing a central rectangular area labeled 'CONTENT (pushing out)' with arrows originating outward from it. Outside, a surrounding area is labeled 'CONTEXT (pushing in)' with arrows pointing inward towards the central area.

EXTRINSIC size

(imposed from outside)

INTRINSIC size

(from the content)
Diagram comparing extrinsic size (imposed from outside) and intrinsic size (from the content).

Extrinsic Sizing

  • Context sizes (available space)
  • Width or height set in px, %, em, etc.

Intrinsic Sizing

  • auto
  • min-content
  • max-content
  • fit-content

"Normal" Flow

Defines the default layout system on the web – a document-like flow of responsive block and inline elements.

While inline elements flow in the direction of text, and are able to wrap around line-breaksblock elements generate a solid box that stacks on the cross-axis.

Edit this text

AKA “Block Layout”
Screencast of flow changing wqith content changing, Miriam describes the effect.

Flow is

Very Cool, Actually

Makes The Web Responsive

.rad {
    font-size: 2em;
    max-width: 2.5em;
    max-height: 2.5em;
}

/* min-width: min-content; */
/* overflow-wrap: break-word; */
/* overflow: clip; */
}

@layer setup {
    .rad {
        border: medium solid;
        margin: 0 auto;
        padding: 0.25em;
        text-transform: uppercase;
        line-height: 0.9;
        /* contain: layout size style; */
    }
    .rad [contenteditable] {
        color: rebeccapurple;
    }

    /* chrome uses break-word for */
Screenshot showing CSS code on the left with stylized "CSS IS AWESOME" text on the right.
Browser developer tool screenshot showing an HTML/CSS code playground with three sections: HTML, CSS, and Result. The layout displays flexbox properties being applied.

Jen Simmons

Intrinsic Web Design

Everything You Know About Web Design Just Changed

Photograph of a woman with glasses, smiling, with long hair.

Responsive Web Design

Force Everything Fluid

2010s – only extrinsic sizing

Intrinsic Web Design

Combines Fluid & Fixed

2020s – Use intrinsic size as well!

  1. Truly Two-Dimensional Layouts
  2. Combine Fluid & Fixed
  3. Stages of Squishiness
  4. Nested Contexts
  5. Expand & Contract Content
  6. Media Queries, As Needed
  1. Nested Contexts ???
  2. Expand & Contract Content ???
Diagram of a webpage layout with sections labeled '.sidebar', 'main', and '.grid-item'. The sidebar contains a large question mark. The main area is divided into three '.grid-item' regions, each containing a question mark, with arrows pointing left and right.

CONTEXT (pushing in)

CONTENT (pushing out)

Diagram illustrating the interaction between context and content, with arrows indicating context pushing inwards and content pushing outwards.

CONTEXT

CONTENT

Illustration of a diagram that says "Content pushing out" and "Context pushing in," surrounded by red scribbles and arrows indicating dynamic interactions.

Well there’s your Infinite Layout Loop

Our queries can't change

The Container Being Queried

Directly or Indirectly

For Size-Related Queries...

CONTEXT (pushing in)

CONTENT pushing out

Diagram showing context pushing inwards and content pushing outwards, with arrows indicating pressure from and towards the center. Red scrawl covers interior of the box.

CSS Containment

contain: size | layout | style | paint

(people have been working on it for years)
CSS
IS
AWESOME
Screenshot of a presentation slide with the text "CSS IS AWESOME" centered in a square. The word "AWESOME" is in purple and extends beyond a containing rectangle
.rad {
     font-size: 2em;
     max-width: 2.5em;
     max-height: 2.5em;
}
 @layer setup {
     .rad {
         border: medium solid;
         margin: 0 auto;
         padding: 0.25em;
         text-transform: uppercase;
         line-height: 0.9;
    }
     .rad [contenteditable] {
         color: rebeccapurple;
    }
    
Screenshot of a CodePen interface displaying CSS code on the left and a styled box with text "CSS IS AWESOME" on the right.
.rad {
    contain: size;
    font-size: 2em;
    max-width: 2.5em;
    max-height: 2.5em;
    /* min-width: min-content; */
    /* overflow-wrap: break-word; */
    /* overflow: clip; */
}

@layer setup {
    .rad {
        border: medium solid;
        margin: 0 auto;
        padding: 0.25em;
        text-transform: uppercase;
        line-height: 0.9;
        /* contain: layout size style; */
    }

    .rad [contenteditable] {
        color: rebeccapurple;
    }
}
Screenshot showing a code editor with CSS code on the left and a display area on the right with the text "CSS IS AWESOME" styled differently.

Hello CSS...

h1 {
		display: inline;
		outline: thick dashed;
	}
Screenshot of a coding environment with an example of CSS styling applied to an h1 tag, illustrating text with a dashed outline.

Hello CSS... klkldfsk

h1 {
	display: block; 
	outline: thick dashed; 
}
Screenshot of a code editor showing CSS code with styling for h1 element and control buttons for HTML, CSS, and result on the top.

For Block Boxes...

Only The block-size is Intrinsic

(from content)

For Block Boxes...

The inline-size is Already Extrinsic

(from context)

!? Inline-Size Containment !?

p {
  background: linear-gradient(powderblue 0 100%), pink;
  background-clip: content-box, border-box;
  padding: 1em;
  border: thick dotted;
  /* contain: size; */
}

@layer reset, base;

@layer base {
  html {
    --pink: #B6236C;
    --blue: #205769;
  }
}
Screenshot of a code editor displaying CSS code with a live preview of a styled paragraph featuring a linear gradient background and dotted border.
A medieval map with red scrawl and 'Dragons' written on it

Inline-Size Containment

Block-Size Containment

(too many side effects)

An emoji of a thumbs-down is shown next to the text.

Inline-Size Containment

Size Containment

(both axis)

Slide with thumbs-up emojis and text about "Inline-Size Containment" and "Size Containment".

Also need to

Contain Layout* & Style

HTML CSS position: fixed (top left) Fig. 1 - kid is disappointed (in us)

What does containment do?

For container queries we'll need to contain layout, size, and style. Understanding containment [present, debug]
Image of a young girl with a disappointed expression, featured to illustrate the concept of 'containment' in CSS.
.contain {
     contain: size;
}
 .contain figure {
     float: left;
     width: 40%;
}
 aside {
     position: fixed;
     inset: -1.5em auto auto 0.5em;
     z-index: 3;
}
 figure {
     position: relative;
     z-index: 2;
}
Screenshot of a code editor displaying CSS code on the left and a webpage with two images of a child looking displeased on the right. The webpage explains containment in layout design.
.contain {
    contain: layout;
    /* container-type: inline-size;*/
}
.contain figure {
    float: left;
    width: 40%;
}
aside {
    position: fixed;
    inset: -1.5em auto auto 0.5em;
    z-index: 3;
}
figure {
    position: relative;
    z-index: 2;
}
@layer setup {
Screenshot of two images of a child with accompanying captions. The top image caption reads "Fig. 1 - kid is disappointed (in us)". The bottom image caption reads "Fig. 2 - same kid (still unhappy)".
.contain {
  contain: style;
/*   container-type: inline-size;
 */
}

.contain figure {
  float: left;
  width: 40%;
}

aside {
  position: fixed;
  inset: -1.5em auto auto 0.5em;
  z-index: 3;
}

figure {
  position: relative;
  z-index: 2;
}

What does containment do?

For container queries we'll need to contain layout, size, and style.

Fig. 1 - kid is disappointed (in us)
Fig. 1 - same kid (still unhappy)
Image of a child looking disappointed, next to another smaller image of the same child, with the caption 'Fig. 1 - kid is disappointed (in us)' and 'Fig. 1 - same kid (still unhappy)'.
contain: inline-size layout style;
container-type: inline-size;

We usually only

Measure The Inline Axis

(anyway. so there. we don’t even care about your silly block axis, you nerd-faced nerd. leave us alone.)

Use inline-size For Most Containers

Screenshot of a webpage design layout. It features a navigation bar with multiple options on the left and a main content area displaying four identical images of a child with captions below each.

For reasons...

No Default Containers
(we shouldn't rely on body style propagation)

Root containment tests

There should be a fixed-position arrow in the top right, and it should stay in the top right, attached to the viewport as you scroll down to see the rainbow. But no browser allows it.

Screenshot of a code editing interface with an orange to red gradient background and a download button in the top right.
body > :is(header, nav, main, aside, footer) {
    container-type: inline-size;
}

Also Recommended...

Name Your Containers
main {
    container: layout main / inline-size;
}
@container layout (min-width: 40em) {
  .conditional { /* … */ }
}

@container main (min-width: 40em) {
  .conditional { /* … */ }
}
@container layout {
  .conditional { /* … */ }
}

@container main {
  .conditional { /* … */ }
}

Coming soon!

Finding Containers

  1. For each matched element...
  2. Find the nearest ancestor element with...
    • Required container name
    • Required container type(s)

No self-query

Measuring an Ancestor

(can’t change what you measure!)

Containers can Query Other Containers

Eric Portis (failed to crash the browser)
Illustration of a large hall with rows of people or figures seated at long tables, viewed through a series of colored concentric rectangles, giving a tunnel-like effect.
Screenshot of a web page showing a button labeled "Add to Cart" with an icon of a shopping cart and a terms segment mentioning "Una Kravets" with options presented as links.
<div class="warning"><strong>Warning:</strong> Your browser does not support CSS container queries. Please open this demo in Chrome Canary with the experimental <i>#enable-container-queries</i> flag turned on.</div>
<!-- Button Component Start -->
<div class="cart-button-container">
  <button class="cart-button">
    <svg class="cart-icon"
       viewBox="0 0 320 173">
      <g class="plus-group">
        <line x1="278" y1="36" x2="278" y2="124" />
        <line x1="322" y1="80" x2="234" y2="80" />
      </g>
      <g class="cart-lines-group">
        <line x1="38" y1="68" x2="200" y2="68" />
        <line x1="83.54" y1="36.2" x2="95.69" y2="99.84" />
        <line x1="156.23" y1="36.2" x2="144.7" y2="99.84" />
      </g>
    </svg>
Screenshot showing HTML code on the left side with a warning about CSS container queries, and a button design labeled "ADD TO CART" on the right side.

Always

Measuring an Element

Bonus! Container Queries

Measure Actual Styles
Computed values on the container element
.html {
   container: root layout / size;
   font-size: 2em;
}
@media (min-width: 20em) {
   p {
      border: thick solid mediumvioletred;
   }
}
@container root (min-width: 20em) {
   p {
      background: teal;
      color: white;
   }
}
@layer setup {
   html {
      height: 100%;
   }
}
Screenshot of a CSS code editor on the left and a preview panel on the right. The editor shows CSS related to media and container queries, while the preview panel displays styled text.
Open https://codepen.io/mirisuzanne/pen/VwRGbVe?editors=1100&layout=left in Peek
Screenshot of a code editor interface with sections for HTML, CSS, and result, displaying placeholder text and a link to a presentation on CodePen.
.main {
  container: layout / inline-size;
}

section {
  display: grid;
  gap: 1em;
}

/* 3 columns @ 30ch min, and 2 gutters @ 1em each */
/* calc(32ch * 3) is simpler, if you don't need to be exact */
@container (inline-size > calc((30ch * 3) + (1em * 2))) {
  grid-template-columns: repeat(
    3,
    minmax(min-content, 1fr)
  );
}
Screenshot of CSS code editor with a webpage preview on the right showing placeholder text in a grid layout.

Grid Tracks & Flex Sizing?

No element to measure...

A dark-colored grid displayed on screen, designed with pink dashed borders at the top and bottom.
Three turtles lined up on a mossy rock in the water, reflecting their images on the surface.
.card {
/* a container for every card */
   container-type: inline-size;
   flex: 1 1 min(100%, 20em);
}

/* the card can't query itself */
/* so we add an element directly inside */
article {
   flex: 1;
   display: grid;
   grid-template: "img" 8em
                  "content" auto / 100%;
   gap: 1em;
   padding: 1em;
}

/* change the grid template when the card is larger */
@container (min-width: 30em) {
Screenshot of a code editor on a webpage showing CSS code for card layouts using flex and grid. The code editor is embedded within a larger interface that includes HTML and CSS tabs.
Screenshot of a code editing tool with sections for HTML and CSS, showing code for a card layout and a preview of resource cards with headings and placeholder text.

Container Query Bookstore

Container Query Bookstore [present , debug ]
Screenshot of a webpage displaying a virtual bookstore with categories such as "Featured" and "Bestsellers," showing several book covers including "The Wizard of Oz" by L. Frank Baum.
Weather Widget by Maarten Van Hoof (see dev tools)
132 / 170
Illustration of a climate widget showing a temperature of 2.4°C, a stylized landscape with hills and a sun, and daily temperatures from Wednesday (22.6) to Tuesday (15.9).

also...

Container Query Units

cqw | cqh | cqi | cqb | cqmin | cqmax

Image showing a selection of Nike shoes including Free Metcon 4, Space Hippie 04, and ZoomX on display with prices.
Using the translate transform...
Diagram showing two horizontal bidirectional arrows, each labeled with "0cqi" and "100cqi", illustrating the concept of a range or movement from one end to the other.

Default unit container

The Small Viewport

bram.us

A rather geeky/technical weblog, est. 2001, by Bramus

The CSS Podcast

Bramus!
June 9, 2021
Leave a comment

Two smartphones displaying the website bram.us, showing the difference between 100lvh (left) and 100svh (right) layouts.

Eventually...

5cqem, 5cqch, etc...

Questions for this damn Box.

OMG. So many Questions.

Image of two cats partially inside a cardboard box. Both have humorous expressions as if pondering the questions written in red text on the image.

Yellow shipping container with a red hand-written speech bubble: I know other stuff too (split and duplicated for two screens)

Style Queries

@container style(--colors: invert) { … }

Style Queries...

Only Custom Properties

Style Queries...

Only Custom Properties *

* for now **

** but maybe forever?

Container Style Queries

limited support
Icons depicting browser support: Chrome, Edge, and Safari show support; Firefox shows no support.

No Containment Required

Always Queries Direct Parent

Unless you query a specific container-name

Theme Styles!

Style query button themes
Illustration of a rectangular button with rounded edges, featuring a pink and cyan striped background and the text "Theme Styles!" in bold.
html {
  --button-theme: mia;
  /* --button-theme: mia-plus; */
}

/*
  This works in Chrome/Edge Canary
  go to: about://flags
  and enable: Experimental Web Platform Features
*/

@container style(--button-theme: mia) or 
style(--button-theme: mia-plus) {
  button {
    background: var(--flag);
    border: thick solid mediumvioletred;
    border-radius: 1em 0;
    box-shadow: var(--4-shadows);
    font-weight: bold;
    padding: 0.5em 1em;
    --shadow-offset: 4px;
  }
}
Screenshot of a code editor on the left with HTML/CSS code, and a styled button with 'Theme Styles!' text on the right.

Color Scheme Style Queries

color scheme: auto

Container Style Queries can be used to combine contextual information from multiple sources (css, html, media) into a single variable that controls output style.

This is only supported in Chromium/Blink browsers (as of 2023-08-31). The demo also uses CSS nesting and the :has() selector, since those are also supported in Chromium/Blink.

Light Section

This section will always be dark on light.

Screenshot of a web-based editor showing a CSS demo with dark mode interface, including options to present and debug.

Web Component Style Parameter Queries

A Demo

Screenshot showing a web component style parameter query interface with a demo card and profile of Miriam Suzanne, including placeholder images and text descriptions.
Screenshot of a CodePen environment showing HTML/CSS tabs and a Lorem Ipsum text block within a styled box on a presentation slide.
<div class="bubble">
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati quibusdam recusandae earum doloribus fugiat similique nesciunt temporibus, aliquam quae beatae dolore modi laborum impedit velit porro sint eos. Neque, ducimus?</p>
</div>

.bubble {
    --arrow-position: start start;
    container: bubble;
    border: medium solid green;
    border-radius: 0.5em;
    max-width: 50ch;
    margin: 1em;
    padding: 1em;
    position: relative;
}

.bubble::after {
    content: "";
    border: 1em solid transparent;
    position: absolute;
Screenshot of a code editor showing HTML and CSS code for a speech bubble design, alongside a rendered example of the speech bubble on the right.

A demo of style queries on non-inherited properties

  • a list
  • that we want
  • to outdent
  • when there is space
  • available
  • in the padding around the list
Screenshot of a presentation slide on CodePen, demonstrating style queries on a list with non-inherited properties. Includes an illustration of a list using pink heart icons as bullets.

Screenshot of a webpage displaying HTML Ipsum dummy text and a CSS styling panel, including headers, lists, and form elements for demonstration purposes.

.ಠ_ಠ { -- ノ(°ω°ノ) ; ┻━┻; } is valid CSS.

Data about the planets of our solar system

(Source: Nasa's Planetary Fact Sheet - Metric).

Screenshot of a webpage displaying a table of planetary data from our solar system with various metrics like diameter, density, gravity, length of day, distance from Sun, mean temperature, and number of moons.

State Queries (???)

CSSWG issue for state queries

???

@container scroll-state(stuck) { … }
@container scroll-state(snapped) { … }
@container scroll-state(overflowing) { … }

Sticky Header State Query!

Screenshot of a webpage displaying lorem ipsum text and a sticky header demonstration within a web development environment.

Responsive images with sizes

<img
    src="jello-1000.jpg"
    srcset="jello-1000.jpg 1000w, jello-2000.jpg 2000w,"
    sizes="(min-width: 1000px) 1000px, 400px"
    alt="Jello rolling over"
/>
Slide featuring a presentation about responsive images, showing code example and speaker on stage.

Sizes auto

Yes.

I'm contained. AMA

A thought bubble drawn in red chalk above a yellow shipping container beneath a blue sky with clouds.

Things Containers Know:

  1. Their Size (if contained)
  2. Custom Property Values
  3. Relative Values (like em)
  4. Maybe Some States?? (tbd)
  • media queries
  • polyfill
  • container queries
  • container type
  • Hypermedia www browser
  • editor
  • contain
  • container type inline size
  • calc
  • use calc
  • web components
  • viewport units
  • CQI
  • CQH
  • web components
  • custom properties
  • pseudo element
  • state queries
  • lazy loading