-
Notifications
You must be signed in to change notification settings - Fork 551
New article "Inspect and debug CSS container queries" #3860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mikehoffms
wants to merge
23
commits into
main
Choose a base branch
from
user/mikehoffms/debug-container-query
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a8425a7
the text
mikehoffms 4e90642
task-oriented headings
mikehoffms a1cfa75
text for new Demos/devtools-container-queries/
mikehoffms 236eaef
3 h4s
mikehoffms 39fca62
local toc
mikehoffms 54d3635
2 of 3 pngs
mikehoffms 00fd346
flatten outline
mikehoffms 2a3f86d
3 lead-ins from demo
mikehoffms 2a1bc99
png 3/3
mikehoffms 8c529dd
del old
mikehoffms fb608dd
start update bottom 2 sections
mikehoffms 6a488ba
temp upstream links
mikehoffms 76e7bab
topmost procedure & pngs
mikehoffms 1cb109c
toggle badge
mikehoffms 19d52b8
badge next to in dom
mikehoffms 7cec082
relate/concat
mikehoffms 734eaf3
superfl next to
mikehoffms 0478c3c
finish pngs
mikehoffms c8fc4ff
inc review's 4 cmts
mikehoffms 98ed750
highlight / select, h2 wording
mikehoffms fde3c20
dotted-line boxes are hidden
mikehoffms 8bbc5fa
4 badge cases
mikehoffms 28fe656
clarif intro definition
mikehoffms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+82.2 KB
microsoft-edge/devtools/css/container-queries-images/container-element.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+126 KB
microsoft-edge/devtools/css/container-queries-images/dashed-border.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+137 KB
microsoft-edge/devtools/css/container-queries-images/dom-inline-size-badge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+80.8 KB
...edge/devtools/css/container-queries-images/dom-tree-card-in-named-container.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+84.7 KB
microsoft-edge/devtools/css/container-queries-images/dotted-line-box.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+912 Bytes
microsoft-edge/devtools/css/container-queries-images/inline-size-badge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+114 KB
...soft-edge/devtools/css/container-queries-images/inline-size-container-query.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+72.7 KB
microsoft-edge/devtools/css/container-queries-images/name-only-container-query.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+108 KB
microsoft-edge/devtools/css/container-queries-images/style-container-query.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,243 @@ | ||
| --- | ||
| title: Inspect and debug CSS container queries | ||
| description: How to inspect and debug CSS container queries in the Elements tool in DevTools. | ||
| author: MSEdgeTeam | ||
| ms.author: msedgedevrel | ||
| ms.topic: article | ||
| ms.service: microsoft-edge | ||
| ms.subservice: devtools | ||
| ms.date: 07/17/2026 | ||
| --- | ||
| # Inspect and debug CSS container queries | ||
| <!-- https://developer.chrome.com/docs/devtools/css/container-queries --> | ||
|
|
||
| <!-- https://developer.chrome.com/docs/devtools/css/grid/ --> | ||
| <!-- Copyright Sofia Emelianova and Jecelyn Yeen | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| https://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. --> | ||
|
|
||
| You can inspect and debug CSS container queries in the **Elements** tool in DevTools. | ||
|
|
||
| CSS container queries allow you to manipulate an element's styles based on its parent container's CSS properties. This capability shifts the concept of responsive web design from page-based to container-based. | ||
|
|
||
| See also: | ||
| * [Responsive web design](https://developer.mozilla.org/docs/Learn_web_development/Core/CSS_layout/Responsive_Design) at MDN. | ||
| * [CSS container queries](https://developer.mozilla.org/docs/Web/CSS/Guides/Containment/Container_queries) at MDN. | ||
| * [Debug CSS container queries](https://microsoftedge.github.io/Demos/devtools-container-queries/) demo. | ||
|
|
||
|
|
||
| <!-- ====================================================================== --> | ||
| ## Discover a container and its descendants | ||
| <!-- Discover containers and their descendants https://developer.chrome.com/docs/devtools/css/container-queries#discover-descendants --> | ||
|
|
||
| An element that's defined as a CSS container query can have no badge, or either of the following badges, next to it in the DOM tree in the **Elements** tool: | ||
| * The **inline-size** container badge  (`container-type: inline-size`). | ||
| * The **size** container badge  (`container-type: size`). | ||
|
|
||
| Clicking the **inline-size** badge or **size** badge displays (or hides) a dotted-line overlay of the container and its descendants. | ||
|
|
||
| To display the dotted-line overlay of the container and its descendants: | ||
|
|
||
| 1. Go to the [Debug CSS container queries](https://microsoftedge.github.io/Demos/devtools-container-queries/) demo in a new window or tab. | ||
|
|
||
| 1. In the **Inline size container** section, right-click to the left of the **Card** element, within the black box, and then select **Inspect**. | ||
|
|
||
| DevTools opens, with the **Elements** tool selected: | ||
|
|
||
|  | ||
|
|
||
| In the DOM tree, the element `<div id-"inline-size-container">` is selected, and has an **inline-size** container badge:  | ||
|
|
||
| In the **Styles** tab, the CSS rule `div#inline-size-container` is displayed. Within that CSS rule, the CSS property `container-type: inline-size` defines the container element. A contained descendant element can query this container's `inline-size` dimension (horizontal axis) and change the contained descendant element's styles based on the width of the container. | ||
|
|
||
| 1. In the DOM tree, click the **inline-size** badge : | ||
|
|
||
|  | ||
|
|
||
| A dotted-line box is displayed around the contained element, and the **inline-size** badge has inverted foreground text color and background color. | ||
|
|
||
| 1. Click the **inline-size** badge again. | ||
|
|
||
| The dotted-line box is hidden, and the **inline-size** badge has its original foreground text color and background color. | ||
|
|
||
|
|
||
| <!-- ------------------------------ --> | ||
| #### Find a container element | ||
| <!-- Find container elements https://developer.chrome.com/docs/devtools/css/container-queries#find-containers --> | ||
|
|
||
| todo: merge w/ above section? | ||
|
|
||
| To find and select the container element that caused the CSS container query to take effect: | ||
|
|
||
| 1. Go to the [Debug CSS container queries](https://microsoftedge.github.io/Demos/devtools-container-queries/) demo in a new window or tab. | ||
|
|
||
| 1. In the **Name-only container** section, right-click the **Card** element, and then select **Inspect**. | ||
|
|
||
| DevTools opens, with the **Elements** tool selected: | ||
|
|
||
|  | ||
|
|
||
| In the DOM tree, the `<div class="card">` element is selected, within the `<div id="name=only-container">` element. | ||
|
|
||
| In the **Styles** tab, the `@container named-container-a` CSS rule is displayed, defining the `background` color for a `card`. | ||
|
|
||
| 1. In the **Styles** tab, at the top of the `@container named-container-a` CSS rule, click the **→named-container-a** link. | ||
|
|
||
| DevTools finds and selects the container element that caused the CSS container query to take effect: | ||
|
|
||
|  | ||
|
|
||
| In the DOM tree, the `<div id="name=only-container">` element is selected. | ||
|
|
||
| In the **Styles** tab, the `div#name-only-container` CSS rule is displayed, defining the CSS property `container-name: named-container-a;`. | ||
|
|
||
|
|
||
| <!-- ====================================================================== --> | ||
| ## Inspect a CSS container query | ||
| <!-- Inspect container queries https://developer.chrome.com/docs/devtools/css/container-queries#inspect-container-queries --> | ||
|
|
||
| The **Elements** tool shows the CSS properties that apply to the descendent element and that are defined inside of an `@container` query. | ||
|
|
||
|
|
||
| <!-- ====================================================================== --> | ||
| ## Inspect a name-only CSS container query | ||
|
|
||
| In this section of the demo, the `<div id="name-only-container">` element with a black border is a CSS container that uses the `container-name: named-container-a;` CSS property. | ||
|
|
||
| The `<div class="card">` element that's within that CSS named-container uses a `@container` query to change its background to green when it's inside a container named `named-container-a`. | ||
|
|
||
| To inspect a name-only CSS container query in DevTools: | ||
|
|
||
| 1. Go to the [Debug CSS container queries](https://microsoftedge.github.io/Demos/devtools-container-queries/) demo in a new window or tab. | ||
|
|
||
| 1. In the **Name-only container** section, right-click the **Card** element, and then select **Inspect**. | ||
|
|
||
| DevTools opens, with the **Elements** tool selected: | ||
|
|
||
|  | ||
|
|
||
| In the DOM tree, the `<div class="card">` element is selected, within `<div id="name-only-container">`. | ||
|
|
||
| In the **Styles** tab, the `@container` query `named-container-a` shows the CSS rule that's applying the green background. | ||
|
|
||
| At the top of the CSS rule is a link to the container element: `→named-container-a`. | ||
|
|
||
| 1. Click the `→named-container-a` link. | ||
|
|
||
| In the DOM tree, the element `<div id="name-only-container">` is selected. | ||
|
|
||
|
|
||
| <!-- ====================================================================== --> | ||
| ## Inspect an inline-size CSS container query | ||
|
|
||
| In this section of the demo, the `<div id="inline-size-container">` element with a black border is a CSS container of type inline-size, because it uses the `container-type: inline-size;` CSS property. | ||
|
|
||
| The `<div class="card">` element that's within the inline-size CSS container uses a `@container` query to change its background to different colors depending on the size of its container. You can resize the container by using the handle in the bottom-right corner of the container, and observe the card's background color change. | ||
|
|
||
| To inspect an inline-size CSS container query in DevTools: | ||
|
|
||
| 1. Go to the [Debug CSS container queries](https://microsoftedge.github.io/Demos/devtools-container-queries/) demo in a new window or tab. | ||
|
|
||
| 1. In the **Inline size container** section, right-click the **Card** element, and then select **Inspect**. | ||
|
|
||
| DevTools opens, with the **Elements** tool selected: | ||
|
|
||
|  | ||
|
|
||
| In the DOM tree, the `<div class="card">` element is selected, within `<div id="inline-size-container">`. | ||
|
|
||
| In the **Styles** tab, the `@container` query `named-container-a` shows the CSS rule that's applying the green background. | ||
|
|
||
| At the top of the CSS rule is a link to the container element: `→div#inline-size-container`. | ||
|
|
||
| 1. Click the `→div#inline-size-container` link. | ||
|
|
||
| In the DOM tree, the element `<div id="inline-size-container">` is selected, and an **inline-size** container badge is displayed next to it. | ||
|
|
||
| 1. Click the **inline-size** container badge . | ||
|
|
||
| In the demo page, a dashed border is added around the content area of the container: | ||
|
|
||
|  | ||
|
|
||
| The **inline-size** container badge has inverted foreground text color and background color. | ||
|
|
||
| A dashed border is also displayed around all children elements which use the container's inline-size to apply different styles. In this case, that's the `<div class="card">` element (the inner dashed border). | ||
|
|
||
| 1. Click the **inline-size** container badge  again. | ||
|
|
||
| In the demo page, the dashed border is removed. | ||
|
|
||
| 1. In the demo page, in the **Inline size container** section, resize the **Card** container by dragging the handle that's in the bottom-right corner of the container. | ||
|
|
||
| The card's background color changes. | ||
|
|
||
|
|
||
| <!-- ====================================================================== --> | ||
| ## Inspect a style CSS container query | ||
|
|
||
| In this section of the demo, the `<div id="style-container">` element with a black border is a CSS container that uses the `container-name: named-container-b;` CSS property. | ||
|
|
||
| The `<div class="card">` element that's within that CSS container uses a `@container style()` query to change its background to a different color, depending on the value of its container's `--foo` custom CSS property. | ||
|
|
||
| The container changes the value of `--foo` over time by using a CSS animation. Observe the card's background change over time. | ||
|
|
||
| To inspect a style CSS container query in DevTools: | ||
|
|
||
| 1. Go to the [Debug CSS container queries](https://microsoftedge.github.io/Demos/devtools-container-queries/) demo in a new window or tab. | ||
|
|
||
| 1. In the **Style container** section, right-click the **Card** element, and then select **Inspect**. | ||
|
|
||
| DevTools opens, with the **Elements** tool selected: | ||
|
|
||
|  | ||
|
|
||
| In the DOM tree, the `<div class="card">` element is selected, within `<div id="style-container">`. | ||
|
|
||
| In the **Styles** tab, the `@container style()` query shows the CSS rule that's applying the current background color. | ||
|
|
||
|
|
||
| <!-- ====================================================================== --> | ||
| ## Modify a CSS container query | ||
| <!-- Modify container queries https://developer.chrome.com/docs/devtools/css/container-queries#modify --> | ||
|
|
||
| To debug a CSS container query, you can modify the CSS container query in the same way as modifying any other CSS property in the **Styles** tab, as described in [Get started viewing and changing CSS](./index.md). | ||
|
|
||
| To modify a CSS container query: | ||
|
|
||
| 1. Go to the [Debug CSS container queries](https://microsoftedge.github.io/Demos/devtools-container-queries/) demo in a new window or tab. | ||
|
|
||
| 1. In the **Inline size container** section, right-click the **Card** element, which is initially blue, and then select **Inspect**. | ||
|
|
||
| DevTools opens, with the **Elements** tool selected: | ||
|
|
||
|  | ||
|
|
||
| In the DOM tree, the `<div class="card">` element is selected, within the `<div id="inline-size-container">` element, which has an **inline-size** container badge  next to it. | ||
|
|
||
| In the **Styles** tab, the `@container (inline size > 100px)` CSS rule is displayed, defining the `background` color for a `card`. | ||
|
|
||
| 1. In the **Styles** tab, click `(inline size > 100px)`, edit the value to `200px`, and then press **Enter**. | ||
|
|
||
| The card turns red, because the container is smaller than 200px (it's 150px by default): | ||
|
|
||
|  | ||
|
|
||
|
|
||
| <!-- ====================================================================== --> | ||
| > [!NOTE] | ||
| > Portions of this page are modifications based on work created and [shared by Google](https://developers.google.com/terms/site-policies) and used according to terms described in the [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0). | ||
| > The original page is found [here](https://developer.chrome.com/docs/devtools/css/container-queries) and is authored by Sofia Emelianova and Jecelyn Yeen. | ||
|
|
||
| [](https://creativecommons.org/licenses/by/4.0) | ||
| This work is licensed under a [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.