{"id":72453,"date":"2024-07-31T21:00:15","date_gmt":"2024-07-31T13:00:15","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=72453"},"modified":"2024-08-07T19:29:42","modified_gmt":"2024-08-07T11:29:42","slug":"css-container-queries","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/css-container-queries\/","title":{"rendered":"CSS Container Queries"},"content":{"rendered":"<p>In traditional responsive design, we rely on media queries to change styles based on the overall viewport size. This works well for adjusting layouts for different screen sizes, but it falls short when you need components to adapt based on their container\u2019s size.<\/p>\n<p>To solve this situation, <a href=\"https:\/\/www.w3.org\/TR\/css-contain-3\/\" target=\"_blank\" rel=\"noopener nofollow\">Container Queries<\/a> were introduced in CSS. They allow you to apply styles to elements based on the dimensions of their containing block, giving you more granular control over responsive design.<\/p>\n<p>Let\u2019s say we have a Card component, containing an <em>image<\/em>, <em>title<\/em>, and a few <em>paragraphs<\/em>. The Card has two layout modes: <em>horizontal<\/em> for large screens and <em>vertical<\/em> for smaller screens.<\/p>\n<p>In the <em>horizontal mode<\/em>, the image will be on the left, and the title and paragraphs are on the right.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/css-container-queries\/card-horizontal.jpg\" alt=\"Card horizontal layout\" width=\"750\" height=\"260\"><\/figure>\n<div class=\"sue-icon-text su-image-caption\" data-url=\"\" data-target=\"self\" style=\"min-height:34px;padding-left:36px;color:#333333\">\n<div class=\"sue-icon-text-icon\" style=\"color:#333333;font-size:24px;width:24px;height:24px\"><i class=\"sui sui-photo\" style=\"font-size:24px;color:#333333\"><\/i><\/div>\n<div class=\"sue-icon-text-content su-u-trim\" style=\"color:#333333\">Card in horizontal layout<\/div>\n<div style=\"clear:both;height:0\"><\/div>\n<\/div>\n<p>In the <em>vertical mode<\/em>, the image is on top, and the title and paragraphs are below it.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/css-container-queries\/card-vertical.jpg\" alt=\"Card vertical layout\" width=\"750\" height=\"480\"><\/figure>\n<div class=\"sue-icon-text su-image-caption\" data-url=\"\" data-target=\"self\" style=\"min-height:34px;padding-left:36px;color:#333333\">\n<div class=\"sue-icon-text-icon\" style=\"color:#333333;font-size:24px;width:24px;height:24px\"><i class=\"sui sui-photo\" style=\"font-size:24px;color:#333333\"><\/i><\/div>\n<div class=\"sue-icon-text-content su-u-trim\" style=\"color:#333333\">Card in vertical layout<\/div>\n<div style=\"clear:both;height:0\"><\/div>\n<\/div>\n<p>We want this Card to switch between these two modes. Traditionally, we would wrap the styles around the <code>@media<\/code> query, for example:<\/p>\n<pre>\r\n.card {\r\n    display: flex;\r\n    gap: 4rem;\r\n}\r\n.card .featured-img {\r\n    width: 40%;  \r\n}\r\n.card .content {\r\n    width: 60%;  \r\n}\r\n\r\n@media screen and (width <= 720px) {\r\n    .card {\r\n      flex-direction: column;\r\n    }\r\n    \r\n    .card .featured-img {\r\n      width: 100%;  \r\n    }\r\n  \r\n    .card .content {\r\n      width: 100%;  \r\n    }\r\n}\r\n<\/pre>\n<p>The problem here is that Media Queries only account for the viewport size, not the container size. If the Card is placed inside a container with a width of 500px, the Card will still be in the horizontal mode, even though it's not suitable for the container size. We may end up with the content and the image being squished, or the image overflowing the container.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/css-container-queries\/with-media-query-example.jpg\" alt=\"Card with media query\" width=\"750\" height=\"480\"><\/figure>\n<div class=\"sue-icon-text su-image-caption\" data-url=\"\" data-target=\"self\" style=\"min-height:34px;padding-left:36px;color:#333333\">\n<div class=\"sue-icon-text-icon\" style=\"color:#333333;font-size:24px;width:24px;height:24px\"><i class=\"sui sui-photo\" style=\"font-size:24px;color:#333333\"><\/i><\/div>\n<div class=\"sue-icon-text-content su-u-trim\" style=\"color:#333333\"><a href=\"https:\/\/codepen.io\/hkdc\/pen\/PorbKyN\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">Card with Media Query<\/a><\/div>\n<div style=\"clear:both;height:0\"><\/div>\n<\/div>\n<p>This is one example where Container Queries can be useful. With Container Queries, we can apply styles based on the container's size, instead of just the viewport size.<\/p>\n<p>To use them, we will need to wrap our <code>.card<\/code> with a new container. In this example, we will name it <code>.card-container<\/code>. Then we can add it with the <code>container-type: inline-size<\/code> declaration.<\/p>\n<pre>\r\n.card-container {\r\n    container-type: inline-size;\r\n    width: 100%;\r\n}\r\n<\/pre>\n<p>The <code>inline-size<\/code> value specifically enables querying the inline dimension, usually the width in horizontal writing modes of a container.<\/p>\n<p>When we set <code>container-type: inline-size<\/code> on an element, we're essentially telling the browser to treat that element as a container whose width can be queried using Container Queries. This is required for applying styles based on the size of the container, rather than the viewport. The <code>width<\/code> is also important to ensure the container takes up the full width of its parent.<\/p>\n<p>Now, we can apply the styles based on the container's size in addition to the Media Queries:<\/p>\n<pre>\r\n@container (max-width: 720px) {\r\n    .card {\r\n        flex-direction: column;\r\n    }\r\n    \r\n    .card .featured-img {\r\n        width: 100%;  \r\n    }\r\n    \r\n    .card .content {\r\n        width: 100%;  \r\n    }\r\n}\r\n<\/pre>\n<p>The two cards from our example should now switch to the vertical layout when the container's width is less than 720px, regardless of the current viewport size.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/css-container-queries\/with-container-query-example.jpg\" alt=\"Card with container query\" width=\"750\" height=\"596\"><\/figure>\n<div class=\"sue-icon-text su-image-caption\" data-url=\"\" data-target=\"self\" style=\"min-height:34px;padding-left:36px;color:#333333\">\n<div class=\"sue-icon-text-icon\" style=\"color:#333333;font-size:24px;width:24px;height:24px\"><i class=\"sui sui-photo\" style=\"font-size:24px;color:#333333\"><\/i><\/div>\n<div class=\"sue-icon-text-content su-u-trim\" style=\"color:#333333\"><a href=\"https:\/\/codepen.io\/hkdc\/full\/BagQJQy\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">Card with Container Queries<\/a><\/div>\n<div style=\"clear:both;height:0\"><\/div>\n<\/div>\n<h2>Browser Compatibility<\/h2>\n<table>\n<thead>\n<tr>\n<th>Browser<\/th>\n<th>Desktop Version<\/th>\n<th>Mobile Version<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Google Chrome<\/td>\n<td>105 and later<\/td>\n<td>105 and later<\/td>\n<\/tr>\n<tr>\n<td>Mozilla Firefox<\/td>\n<td>109 and later<\/td>\n<td>109 and later<\/td>\n<\/tr>\n<tr>\n<td>Safari<\/td>\n<td>16.4 and later<\/td>\n<td>16.4 and later<\/td>\n<\/tr>\n<tr>\n<td>Microsoft Edge<\/td>\n<td>105 and later<\/td>\n<td>105 and later<\/td>\n<\/tr>\n<tr>\n<td>Opera<\/td>\n<td>91 and later<\/td>\n<td>91 and later<\/td>\n<\/tr>\n<tr>\n<td>Internet Explorer<\/td>\n<td>Not supported<\/td>\n<td>Not supported<\/td>\n<\/tr>\n<tr>\n<td>Samsung Internet<\/td>\n<td>N\/A<\/td>\n<td>20.0 and later<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Inspirations<\/h2>\n<p>We've walked through a very common use case of using Container Queries. We can actually do so much more with them to create more innovative features on our website, such as combining them with animations, interactive elements, and more. Here are some demos of using Container Queries for your inspiration.<\/p>\n<h3>CSS Container Query House<\/h3>\n<p>You can resize the container size vertically or horizontally and see the house expand with more rooms and windows.<\/p>\n<p class=\"codepen\" data-height=\"480\" data-default-tab=\"result\" data-slug-hash=\"QWVVpqY\" data-pen-title=\"CSS Container Query House\" data-user=\"Lumocra\" style=\"height: 480px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;\"><span>See the Pen <a href=\"https:\/\/codepen.io\/Lumocra\/pen\/QWVVpqY\" rel=\"nofollow\">CSS Container Query House<\/a> by Arco (<a href=\"https:\/\/codepen.io\/Lumocra\" rel=\"nofollow\">@Lumocra<\/a>) on <a href=\"https:\/\/codepen.io\" rel=\"nofollow\">CodePen<\/a>.<\/span><\/p>\n<p class=\"codepen\" data-height=\"480\" data-default-tab=\"result\" data-slug-hash=\"yLqjVWb\" data-pen-title=\"Responsive House with CSS Container Query\" data-user=\"gayane-gasparyan\" style=\"height: 480px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;\"><span>See the Pen <a href=\"https:\/\/codepen.io\/gayane-gasparyan\/pen\/yLqjVWb\" rel=\"nofollow\">Responsive House with CSS Container Query<\/a> by Gayane Gasparyan (<a href=\"https:\/\/codepen.io\/gayane-gasparyan\" rel=\"nofollow\">@gayane-gasparyan<\/a>) on <a href=\"https:\/\/codepen.io\" rel=\"nofollow\">CodePen<\/a>.<\/span><\/p>\n<h3>Squish CSS Container Queries<\/h3>\n<p>Click the button <strong>Add Squishy<\/strong> to add more squishies inside the block and see how their reaction changes the more you add as there isn't enough room inside.<\/p>\n<p class=\"codepen\" data-height=\"480\" data-default-tab=\"result\" data-slug-hash=\"zYLZGZz\" data-pen-title=\"CSS Container Queries\" data-user=\"maxcswann\" style=\"height: 480px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;\"> <span>See the Pen <a href=\"https:\/\/codepen.io\/maxcswann\/pen\/zYLZGZz\" rel=\"nofollow\">CSS Container Queries<\/a> by Max Swann (<a href=\"https:\/\/codepen.io\/maxcswann\" rel=\"nofollow\">@maxcswann<\/a>) on <a href=\"https:\/\/codepen.io\" rel=\"nofollow\">CodePen<\/a>.<\/span><\/p>\n<p><script async src=\"https:\/\/cpwebassets.codepen.io\/assets\/embed\/ei.js\"><\/script> <\/p>","protected":false},"excerpt":{"rendered":"<p>In traditional responsive design, we rely on media queries to change styles based on the overall viewport size. This works well for adjusting layouts for different screen sizes, but it falls short when you need components to adapt based on their container\u2019s size. To solve this situation, Container Queries were introduced in CSS. They allow&hellip;<\/p>\n","protected":false},"author":113,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3392],"tags":[507],"topic":[],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.6) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>CSS Container Queries - Hongkiat<\/title>\n<meta name=\"description\" content=\"In traditional responsive design, we rely on media queries to change styles based on the overall viewport size. This works well for adjusting layouts for\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/css-container-queries\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"CSS Container Queries\" \/>\n<meta property=\"og:description\" content=\"In traditional responsive design, we rely on media queries to change styles based on the overall viewport size. This works well for adjusting layouts for\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/css-container-queries\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2024-07-31T13:00:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-07T11:29:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/assets.hongkiat.com\/uploads\/css-container-queries\/card-horizontal.jpg\" \/>\n<meta name=\"author\" content=\"Thoriq Firdaus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@tfirdaus\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Thoriq Firdaus\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-container-queries\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-container-queries\\\/\"},\"author\":{\"name\":\"Thoriq Firdaus\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e7948c7a175d211496331e4b6ce55807\"},\"headline\":\"CSS Container Queries\",\"datePublished\":\"2024-07-31T13:00:15+00:00\",\"dateModified\":\"2024-08-07T11:29:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-container-queries\\\/\"},\"wordCount\":672,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-container-queries\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/css-container-queries\\\/card-horizontal.jpg\",\"keywords\":[\"CSS\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-container-queries\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-container-queries\\\/\",\"name\":\"CSS Container Queries - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-container-queries\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-container-queries\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/css-container-queries\\\/card-horizontal.jpg\",\"datePublished\":\"2024-07-31T13:00:15+00:00\",\"dateModified\":\"2024-08-07T11:29:42+00:00\",\"description\":\"In traditional responsive design, we rely on media queries to change styles based on the overall viewport size. This works well for adjusting layouts for\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-container-queries\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-container-queries\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-container-queries\\\/#primaryimage\",\"url\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/css-container-queries\\\/card-horizontal.jpg\",\"contentUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/css-container-queries\\\/card-horizontal.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-container-queries\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CSS Container Queries\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e7948c7a175d211496331e4b6ce55807\",\"name\":\"Thoriq Firdaus\",\"description\":\"Thoriq is a writer for Hongkiat.com with a passion for web design and development. He is the author of Responsive Web Design by Examples, where he covered his best approaches in developing responsive websites quickly with a framework.\",\"sameAs\":[\"https:\\\/\\\/thoriq.com\",\"https:\\\/\\\/x.com\\\/tfirdaus\"],\"jobTitle\":\"Web Developer\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/thoriq\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"CSS Container Queries - Hongkiat","description":"In traditional responsive design, we rely on media queries to change styles based on the overall viewport size. This works well for adjusting layouts for","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hongkiat.com\/blog\/css-container-queries\/","og_locale":"en_US","og_type":"article","og_title":"CSS Container Queries","og_description":"In traditional responsive design, we rely on media queries to change styles based on the overall viewport size. This works well for adjusting layouts for","og_url":"https:\/\/www.hongkiat.com\/blog\/css-container-queries\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2024-07-31T13:00:15+00:00","article_modified_time":"2024-08-07T11:29:42+00:00","og_image":[{"url":"https:\/\/assets.hongkiat.com\/uploads\/css-container-queries\/card-horizontal.jpg","type":"","width":"","height":""}],"author":"Thoriq Firdaus","twitter_card":"summary_large_image","twitter_creator":"@tfirdaus","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Thoriq Firdaus","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/css-container-queries\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-container-queries\/"},"author":{"name":"Thoriq Firdaus","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e7948c7a175d211496331e4b6ce55807"},"headline":"CSS Container Queries","datePublished":"2024-07-31T13:00:15+00:00","dateModified":"2024-08-07T11:29:42+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-container-queries\/"},"wordCount":672,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-container-queries\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/css-container-queries\/card-horizontal.jpg","keywords":["CSS"],"articleSection":["Coding"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/css-container-queries\/","url":"https:\/\/www.hongkiat.com\/blog\/css-container-queries\/","name":"CSS Container Queries - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-container-queries\/#primaryimage"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-container-queries\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/css-container-queries\/card-horizontal.jpg","datePublished":"2024-07-31T13:00:15+00:00","dateModified":"2024-08-07T11:29:42+00:00","description":"In traditional responsive design, we rely on media queries to change styles based on the overall viewport size. This works well for adjusting layouts for","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-container-queries\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/css-container-queries\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/css-container-queries\/#primaryimage","url":"https:\/\/assets.hongkiat.com\/uploads\/css-container-queries\/card-horizontal.jpg","contentUrl":"https:\/\/assets.hongkiat.com\/uploads\/css-container-queries\/card-horizontal.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/css-container-queries\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"CSS Container Queries"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e7948c7a175d211496331e4b6ce55807","name":"Thoriq Firdaus","description":"Thoriq is a writer for Hongkiat.com with a passion for web design and development. He is the author of Responsive Web Design by Examples, where he covered his best approaches in developing responsive websites quickly with a framework.","sameAs":["https:\/\/thoriq.com","https:\/\/x.com\/tfirdaus"],"jobTitle":"Web Developer","url":"https:\/\/www.hongkiat.com\/blog\/author\/thoriq\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-iQB","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/72453","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/113"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=72453"}],"version-history":[{"count":3,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/72453\/revisions"}],"predecessor-version":[{"id":72523,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/72453\/revisions\/72523"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=72453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=72453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=72453"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=72453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}