{"id":282,"date":"2023-12-21T15:41:02","date_gmt":"2023-12-21T15:41:02","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=282"},"modified":"2023-12-21T15:41:02","modified_gmt":"2023-12-21T15:41:02","slug":"container-queries-and-units","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/container-queries-and-units\/","title":{"rendered":"Container Queries and Units"},"content":{"rendered":"\n<p>Container queries are similar to media queries but allow you set styles based on a particular element\u2019s current size, typically the width. This is super handy because you can write CSS in a way that gives flexibility to the layout!<\/p>\n\n\n\n<p>With <code>@media<\/code> queries, there\u2019s a tight coupling of the styling of a component\u2019s content and the size of the browser window. This means that the styles within a given component depend on the layout.<\/p>\n\n\n\n<p>With <code>@container<\/code> queries, we can instead tightly couple the styling of a component\u2019s content with <em>the size of the component itself<\/em>, regardless of how that component fits into the larger layout. In short, you can set up components to respond to the container size without having to know the breakpoints of the overall page layout. Yay for increased isolation!<\/p>\n\n\n\n<p>Let&#8217;s think through an example to illustrate this. Pulling from <a href=\"https:\/\/developer.mozilla.org\/en-US\/blog\/getting-started-with-css-container-queries\/\">Michelle Barker&#8217;s helpful MDN article about container queries<\/a>, here&#8217;s a mockup:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"731\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2023\/12\/layout-desktop-01.webp?resize=1024%2C731&#038;ssl=1\" alt=\"\" class=\"wp-image-283\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2023\/12\/layout-desktop-01.webp?resize=1024%2C731&amp;ssl=1 1024w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2023\/12\/layout-desktop-01.webp?resize=300%2C214&amp;ssl=1 300w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2023\/12\/layout-desktop-01.webp?resize=768%2C548&amp;ssl=1 768w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2023\/12\/layout-desktop-01.webp?resize=1536%2C1096&amp;ssl=1 1536w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2023\/12\/layout-desktop-01.webp?w=1600&amp;ssl=1 1600w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<p>When there&#8217;s more width available, each article preview has the image on the left and copy on the right. When there&#8217;s less room available, it stacks the image on top of the content.<\/p>\n\n\n\n<p>Without container queries, we&#8217;d have to specify which cards we want to have the vertical layout, which ones should have the horizontal layout, and which should have a bigger image explicitly. When you then consider all possible screen sizes and container layouts, this quickly becomes quite complicated.<\/p>\n\n\n\n<p>Additionally, if there&#8217;s a possibility for the sidebar to be collapsed or if you sometimes need to show additional content (like ads) alongside this content, it gets even more complex! Not to mention when the layout gets changed to something else, like switching from 4 columns to 3, you have to go back and adjust everything.<\/p>\n\n\n\n<p>Container queries can help us more easily address this sort of situation in a much more manageable way!<\/p>\n\n\n\n<p class=\"learn-more\">Container queries are separate from, but can be in used in combination with, <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/contain\">the <code>contain<\/code> property<\/a> The <code>contain<\/code> property is useful for performance and preventing re-renders and, crucially, the thing that made <code>@container<\/code> queries possible under the hood.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"block-and-inline-sizing\"><strong>Block and inline sizing<\/strong><\/h2>\n\n\n\n<p>Before diving further into container queries, it&#8217;s important to make sure we have a good understanding of block and inline sizing as it has a large impact on the <code>container-type<\/code> and the container unit(s) we use.<\/p>\n\n\n\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/inline-size\">Inline size<\/a> is equivalent to width for horizontal <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/writing-mode\">writing mode<\/a> and equivalent to the height for vertical writing modes. The <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/block-size\">block size<\/a> is the respective opposite. <\/p>\n\n\n\n<p>Make sure you keep this in mind! The terms &#8220;block&#8221; and &#8220;inline&#8221; are from the concept of <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/CSS_logical_properties_and_values\">&#8220;logical properties&#8221;<\/a> and the direction CSS has been heading for a while.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to use container queries<\/h2>\n\n\n\n<p>To use container queries, you must first define a <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/container-type\">container-type<\/a><\/code> and optionally a <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/container-name\">container-name<\/a><\/code>.<\/p>\n\n\n\n<p>The <code>container-type<\/code> can have a value of <code>size<\/code>, <code>inline-size<\/code>, or <code>normal<\/code>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>size<\/code> establishes a query container for the inline and block dimensions as well as for style (which we cover at the end of this article).&nbsp;<\/li>\n\n\n\n<li><code>inline-size<\/code> establishes a query container for the inline dimensions as well as for style.&nbsp;You&#8217;ll likely use this 99% of the time.<\/li>\n\n\n\n<li><code>normal<\/code> establishes a query container only for style.<\/li>\n<\/ul>\n\n\n\n<p>One potential gotcha is that if you use <code>container-type: size<\/code> you need to add an explicit height. It will ignore the height of children elements. This is <a href=\"https:\/\/drafts.csswg.org\/css-contain-2\/#containment-size\">how it is specced<\/a> to behave.<\/p>\n\n\n\n<p>Most often, using <code>container-type: inline-size<\/code> probably makes the most sense.<\/p>\n\n\n\n<p>The <code>container-name<\/code> is a value of the <code><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/custom-ident\">&lt;custom-indent&gt;<\/a><\/code> type (essentially some name you make up). <\/p>\n\n\n\n<p>You can also use the <code>container<\/code> shorthand to define both properties. Such as:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-class\">.my-component<\/span> {\n\u00a0 <span class=\"hljs-attribute\">container<\/span>: my-component \/ inline-size;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>When using a container query or container query unit (which we will cover more in later sections), it will reference the nearest container in its ancestry tree unless you specify a particular container by including the <code>container-name<\/code>.<\/p>\n\n\n\n<p>Once you&#8217;ve defined a container, you can use a <code>@container<\/code> query and select any descendant elements inside of it. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-keyword\">@container<\/span> (<span class=\"hljs-attribute\">min-width:<\/span> <span class=\"hljs-number\">500px<\/span>) {\n\u00a0 <span class=\"hljs-selector-class\">.my-component<\/span> <span class=\"hljs-selector-tag\">p<\/span> {\n\u00a0 \u00a0 <span class=\"hljs-attribute\">font-size<\/span>: <span class=\"hljs-number\">1.5rem<\/span>;\n\u00a0 }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Or, if you want to use the container name in the query:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-keyword\">@container<\/span> my-component (<span class=\"hljs-attribute\">min-width:<\/span> <span class=\"hljs-number\">500px<\/span>) {\n\u00a0 <span class=\"hljs-selector-class\">.my-component<\/span> <span class=\"hljs-selector-tag\">p<\/span> {\n\u00a0 \u00a0 <span class=\"hljs-attribute\">font-size<\/span>: <span class=\"hljs-number\">1.5rem<\/span>;\n\u00a0 }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Note that you <em>cannot<\/em> style the element that is being queried inside of the container query itself (like <code>.my-component {}<\/code> in this case). But you <em>can<\/em> use it as a part of a more complex selector as seen above.<\/p>\n\n\n\n<p>But you don&#8217;t <em>have to<\/em> refer to the container element in the selector, meaning this is also valid:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-keyword\">@container<\/span> my-component (<span class=\"hljs-attribute\">min-width:<\/span> <span class=\"hljs-number\">500px<\/span>) {\n\u00a0 <span class=\"hljs-selector-tag\">p<\/span> {\n\u00a0 \u00a0 <span class=\"hljs-attribute\">font-size<\/span>: <span class=\"hljs-number\">1.5rem<\/span>;\n\u00a0 }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>You can also use <a href=\"https:\/\/caniuse.com\/css-nesting\">nesting<\/a>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-class\">.my-component<\/span> {\n  @container (<span class=\"hljs-attribute\">min-width<\/span>: <span class=\"hljs-number\">500px<\/span>) {\n    p {\n      font-size: <span class=\"hljs-number\">1.5rem<\/span>;\n    }\n  }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\"><strong><code>orientation<\/code> and <code>aspect-ratio<\/code><\/strong><\/h2>\n\n\n\n<p>Instead of using explicit container sizes for container queries, we can also make use of <code>orientation<\/code> and its more generic form, <code>aspect-ratio<\/code>.<\/p>\n\n\n\n<p>For example, here&#8217;s <a href=\"https:\/\/codepen.io\/ZachSaucier\/pen\/JjxeEyG?editors=1100\">a Pen<\/a> where we have the image on the left for larger screens and on top for smaller screens (a non-aspect ratio version of this sort of thing is in the section below).<\/p>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_JjxeEyG\" src=\"\/\/codepen.io\/anon\/embed\/JjxeEyG?height=550&amp;theme-id=47434&amp;slug-hash=JjxeEyG&amp;default-tab=result\" height=\"550\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed JjxeEyG\" title=\"CodePen Embed JjxeEyG\" class=\"cp_embed_iframe\" style=\"width:100%;overflow:hidden\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n\n<p>When using <code>aspect-ratio<\/code>, remember that it&#8217;s width divided by the height, so <code>aspect-ratio &lt; 1\/1<\/code> would be when the width is larger than the height (this example is equivalent to <code>orientation: landscape<\/code>). You can also use <code>min-aspect-ratio<\/code> or <code>max-aspect-ratio<\/code> instead of plain <code>aspect-ratio<\/code> and a comparison symbol.<\/p>\n\n\n\n<p>Note that <code>orientation<\/code> and <code>aspect-ratio<\/code> can only be used with a <code>container-type<\/code> of <code>size<\/code> because it uses the container&#8217;s width <em>and<\/em> height. Setting a <code>height<\/code> is not typically a great idea for any template-based design where content can change.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are container query <em>units<\/em>?<\/h2>\n\n\n\n<p>Container query units are an addition to the container query specification that provides units <em>based on the container&#8217;s dimensions<\/em>. This is handy for sizing pieces of a component based on the component&#8217;s container size.<\/p>\n\n\n\n<p>What&#8217;s more, you&#8217;re not restricted to using container query units inside of container queries. You can use them anywhere a container is specified! That means that in some cases you can get away with just setting a property&#8217;s value to something that uses a container query unit and just leave it at that.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">A shortened name for container query units?<\/h3>\n\n\n\n<p>&#8220;Container query units&#8221; is kind of a mouthful to say. Given that they can be used outside of container queries (so long as a container is defined), I think we can refer to these as &#8220;container units&#8221; <a href=\"https:\/\/css-tricks.com\/container-units-should-be-pretty-handy\/\">like Chris Coyier did<\/a> when he wrote about them a while back. I&#8217;m going to call them that for the rest of this article.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Available container units<\/h3>\n\n\n\n<p>Here&#8217;s the list of container units we currently have access to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>cqw<\/code>: 1% of a query container&#8217;s width<\/li>\n\n\n\n<li><code>cqh<\/code>: 1% of a query container&#8217;s height<\/li>\n\n\n\n<li><code>cqi<\/code>: 1% of a query container&#8217;s inline size<\/li>\n\n\n\n<li><code>cqb<\/code>: 1% of a query container&#8217;s block size<\/li>\n\n\n\n<li><code>cqmin<\/code>: The smaller value of either <code>cqi<\/code> or <code>cqb<\/code><\/li>\n\n\n\n<li><code>cqmax<\/code>: The larger value of either <code>cqi<\/code> or <code>cqb<\/code><\/li>\n<\/ul>\n\n\n\n<p>The width and height values are pretty straightforward to use. However, keep in mind that <code>cqh<\/code> will only use a container height if the container has a <code>container-type<\/code> of <code>size<\/code>. If <code>inline-size<\/code> is used, it will base its height on the nearest container with <code>container-type: size<\/code>, which might be the viewport.<\/p>\n\n\n\n<p>Of these units, <code>cqi<\/code> will probably be the most commonly used unit for those who want to build websites for international audiences. For horizontal languages, it is equivalent to <code>cqw<\/code>. But it automatically switches to use <code>cqh<\/code> for vertical languages.<\/p>\n\n\n\n<p>If you&#8217;re still not sure what inline means vs block here, maybe spend more time in <a href=\"#block-and-inline-sizing\">the section above<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Use cases for container queries and container units<\/h2>\n\n\n\n<p>Let&#8217;s take a quick look at some use cases for container queries and container units!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Changing a component&#8217;s layout based on how much space is available<\/h3>\n\n\n\n<p>Perhaps the most common use case for container queries is to change the layout of a component&#8217;s contents based on the container&#8217;s size. Paired with ways of doing layouts like flex and grid, it can make creating pages that respond to different viewport sizes even easier.<\/p>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_MWLzJGM\" src=\"\/\/codepen.io\/anon\/embed\/MWLzJGM?height=450&amp;theme-id=47434&amp;slug-hash=MWLzJGM&amp;default-tab=result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed MWLzJGM\" title=\"CodePen Embed MWLzJGM\" class=\"cp_embed_iframe\" style=\"width:100%;overflow:hidden\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n\n<p>Accessibility note: It&#8217;s best to <a href=\"https:\/\/devyarns.com\/logical-focus-order\/\">keep the logical order<\/a> of elements in the markup.<\/p>\n\n\n\n<p>Taken to an extreme, you can make HTML and CSS components function kinda like an SVG like Dan Christofi did:<\/p>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_QWxameQ\" src=\"\/\/codepen.io\/anon\/embed\/preview\/QWxameQ?height=450&amp;theme-id=47434&amp;slug-hash=QWxameQ&amp;default-tab=result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed QWxameQ\" title=\"CodePen Embed QWxameQ\" class=\"cp_embed_iframe\" style=\"width:100%;overflow:hidden\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Adding non-vital detail when there&#8217;s more space available<\/h3>\n\n\n\n<p>In addition to changing the layout, sometimes it makes sense to hide some of the less important information or decorative elements when a component is smaller.<\/p>\n\n\n\n<p>A great example of this is Chris Coyier&#8217;s calendar layout demo, where the vital parts of the calendar are kept for the smallest size but the rest is hidden:<\/p>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_jOeBzNN\" src=\"\/\/codepen.io\/anon\/embed\/jOeBzNN?height=450&amp;theme-id=47434&amp;slug-hash=jOeBzNN&amp;default-tab=result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed jOeBzNN\" title=\"CodePen Embed jOeBzNN\" class=\"cp_embed_iframe\" style=\"width:100%;overflow:hidden\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n\n<p>(You may want to open <a href=\"https:\/\/codepen.io\/chriscoyier\/full\/jOeBzNN\">this one full screen<\/a> to have play.)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Fluid typography<\/h3>\n\n\n\n<p>Fluid typography is the concept of defining font sizes in a way where the type automatically scales based on some dimension between pre-defined bounds. In the past this has been based on the viewport width, but container query units make this concept a lot more powerful!<\/p>\n\n\n\n<p>Check out this demo by Chris Coyier where you can drag to divvy up width between two elements, both with responsive type sizes:<\/p>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_GREQGQY\" src=\"\/\/codepen.io\/anon\/embed\/GREQGQY?height=750&amp;theme-id=47434&amp;slug-hash=GREQGQY&amp;default-tab=result\" height=\"750\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed GREQGQY\" title=\"CodePen Embed GREQGQY\" class=\"cp_embed_iframe\" style=\"width:100%;overflow:hidden\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n\n<p>Stephanie Eckles wrote a more in-depth article about <a href=\"https:\/\/moderncss.dev\/container-query-units-and-fluid-typography\/\">using container query units for typography<\/a> that I highly recommend!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">When to use media queries instead<\/h2>\n\n\n\n<p>Content queries and units free us up from having to always use breakpoints that are tied to the layout. However, there are cases where you want content to update based on the layout! That&#8217;s when you should still use media queries\u2014so content can be updated across multiple components at the same time.<\/p>\n\n\n\n<p>Another time to use media queries is when you&#8217;re wanting to check certain device features, such as <code>@media (not(hover)) { ... }<\/code> or <code>@media (not (color)) { ... }<\/code> (which checks if the display is monochrome).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Browser support and style queries<\/h2>\n\n\n\n<p>Container queries for sizing <a href=\"https:\/\/caniuse.com\/css-container-queries\">have pretty solid browser support<\/a> these days, as do <a href=\"https:\/\/caniuse.com\/css-container-query-units\">container units<\/a>.<\/p>\n\n\n\n<p>There&#8217;s also discussion around creating <em>style<\/em> container queries. This would make certain things easier, like alternating between nested italic and normal text. Since the values of CSS variables can also be used in style queries, they could also be used as a more legitimate alternative to <a href=\"https:\/\/css-tricks.com\/the-css-custom-property-toggle-trick\/\">the CSS variable\/custom property toggle hack<\/a>. But at the moment they are only partially supported <a href=\"https:\/\/caniuse.com\/css-container-queries-style\">in WebKit-based browsers<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Container queries and container units enable us to create more isolated components. This makes it easier for components to be used across multiple pages, layouts, and systems. They&#8217;re prime for use in design systems!<\/p>\n\n\n\n<p>If you&#8217;re interested in what other new CSS features I used when recreating my blog, <a href=\"https:\/\/zachsaucier.com\/blog\/blog-refresh-2023\">check out my blog post about the process<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Bonus demo<\/h3>\n\n\n\n<p>This demo by SitePoint shows responsive layout paired with container queries to inspire you further!<\/p>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_mdzJJaX\" src=\"\/\/codepen.io\/anon\/embed\/mdzJJaX?height=760&amp;theme-id=47434&amp;slug-hash=mdzJJaX&amp;default-tab=result\" height=\"760\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed mdzJJaX\" title=\"CodePen Embed mdzJJaX\" class=\"cp_embed_iframe\" style=\"width:100%;overflow:hidden\">CodePen Embed Fallback<\/iframe><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Container queries are similar to media queries but allow you set styles based on a particular element\u2019s current size, typically the width. This is super handy because you can write CSS in a way that gives flexibility to the layout! With @media queries, there\u2019s a tight coupling of the styling of a component\u2019s content and [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":287,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[47,48,7],"class_list":["post-282","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-post","tag-container-queries","tag-container-units","tag-css"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2023\/12\/container-query-thumb.jpg?fit=1000%2C500&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/282","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/comments?post=282"}],"version-history":[{"count":8,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/282\/revisions"}],"predecessor-version":[{"id":312,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/282\/revisions\/312"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/287"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}