To use container queries, you need to declare a containment context on an element so that the browser knows you might want to query the dimensions of this container later. To do this, use the container-type property with a value of size, inline-size, or normal.
These values have the following effects:
size
The query will be based on the inline and block dimensions of the container. Applies layout, style, and size containment to the container.
inline-size
The query will be based on the inline dimensions of the container. Applies layout, style, and inline-size containment to the element.
normal
The element is not a query container for any container size queries, but remains a query container for container style queries.
Volutpat consequat mauris nunc congue nisi. Augue eget arcu dictum varius duis at consectetu…
Next, use the @container at-rule to define a container query. The query in the following example will apply styles to elements based on the size of the nearest ancestor with a containment context. Specifically, this query will apply a larger font size for the card title if the container is wider than 700px:
CSSCopy to Clipboard
/* Default heading styles for the card title */
.card h2 {
font-size: 1em;
}
Using container queries, the card can be reused in multiple areas of a page without needing to know specifically where it will be placed each time. If the container with the card is narrower than 700px, the font of the card title will be small, and if the card is in a container that's wider than 700px, the font of the card title will be bigger.
/* If the container is larger than 700px */
@container (min-width: 700px) {
.card h2 {
font-size: 2em;
}
}
Michael Trent Reznor (born May 17, 1965) is an American musician, singer, songwriter, record producer, and composer. He serves as the lead vocalist, multi-instrumentalist, and principal songwriter of the industrial rock band Nine Inch Nails,[1][2][3] which he founded in 1988 and of which he was the sole official member until 2016.[a] The first Nine Inch Nails album, Pretty Hate Machine (1989), was a commercial and critical success. Reznor has since released 11 more Nine Inch Nails studio albums.Reznor began his career in the mid-1980s as a member of synth-pop bands such as Option 30, The Innocent, and Exotic Birds.[4] He has contributed to the albums of artists such as Marilyn Manson, whom he mentored, rapper Saul Williams and Halsey. Alongside his wife Mariqueen Maandig and long-time Nine Inch Nails collaborators Atticus Ross and Rob Sheridan, he formed the post-industrial group How to Destroy Angels in 2009.[5][6][7][8]Beginning in 2010, Reznor, alongside Atticus Ross, began to work on film and television scores. The duo have scored many of David Fincher's films, including The Social Network (2010), The Girl with the Dragon Tattoo (2011), Gone Girl (2014), Mank (2020), and The Killer (2023). They won the Academy Award for Best Original Score and the Grammy Award for Best Score Soundtrack for Visual Media for both The Social Network (2010) and Soul (2020). The duo has also scored the films Patriots Day (2016), Mid90s, Bird Box (both 2018), Waves (2019), Bones and All, Empire of Light (both 2022), and Teenage Mutant Ninja Turtles: Mutant Mayhem (2023). They have scored the documentaries Before the Flood (2016) and The Vietnam War (2017), and the TV series Watchmen (2019), winning a Primetime Emmy Award for the lattermost.
Following the release of Year Zero, Reznor announced later that Nine Inch Nails had split from its contractual obligations with Interscope Records, and would distribute its next major albums independently.
For more information on the syntax of container queries, see the @container page.
In the previous section, a container query applied styles based on the nearest ancestor with a containment context. It's possible to give a containment context a name using the container-name property. Once named, the name can be used in a @container query so as to target a specific container. The following example creates a containment context with the name sidebar:
Planning a Yellowstone vacation? Be sure to download the official Yellowstone National Park map, below, or use our interactive maps to find restaurants, hotels, or activities along the route of your choosing in and around the park. Either way, don’t leave home without a map of Yellowstone. This free Yellowstone map shows park roads, attractions, and more.
More information on naming containment contexts is available on the container-name page.
When applying styles to a container using container queries, you can use container query length units. These units specify a length relative to the dimensions of a query container. Components that use units of length relative to their container are more flexible to use in different containers without having to recalculate concrete length values.
test
Å
Column 1
Column 2
The container query length units are:
cqw: 1% of a query container's width
cqh: 1% of a query container's height
cqi: 1% of a query container's inline size
cqb: 1% of a query container's block size
cqmin: The smaller value of either cqi or cqb
cqmax: The larger value of either cqi or cqb
The following example uses the cqi unit to set the font size of a heading based on the inline size of the container:
For browsers that don't yet support container queries, grid and flex can be used to create a similar effect for the card component used on this page. The following example uses a grid-template-columns declaration to create a two-column layout for the card component.
t Form Submit HandlerArticle Asset Test Form Submit HandlerArticle Asset Test Form Submit HandlerArticle Asset Test Form Submit HandlerArticle At Form Submit HandlerArticle Asset Test Form Submit HandlerArticle Asset Test Form Submit HandlerArticle Asset Test Form Submit HandlerArticle A
Keep it Clean. Please avoid obscene, vulgar, lewd,
racist or sexually-oriented language. PLEASE TURN OFF YOUR CAPS LOCK. Don't Threaten. Threats of harming another
person will not be tolerated. Be Truthful. Don't knowingly lie about anyone
or anything. Be Nice. No racism, sexism or any sort of -ism
that is degrading to another person. Be Proactive. Use the 'Report' link on
each comment to let us know of abusive posts. Share with Us. We'd love to hear eyewitness
accounts, the history behind an article.
(0) comments
Welcome to the discussion.
Log In
Keep it Clean. Please avoid obscene, vulgar, lewd, racist or sexually-oriented language.
PLEASE TURN OFF YOUR CAPS LOCK.
Don't Threaten. Threats of harming another person will not be tolerated.
Be Truthful. Don't knowingly lie about anyone or anything.
Be Nice. No racism, sexism or any sort of -ism that is degrading to another person.
Be Proactive. Use the 'Report' link on each comment to let us know of abusive posts.
Share with Us. We'd love to hear eyewitness accounts, the history behind an article.