Container query units: cqi and cqb

A little gem from Kevin Powell’s “HTML & CSS Tip of the Week” website, reminding us that using container queries opens up container query units for sizing things based on the size of the queried container.


Container query units: cqi and cqb originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.


This content originally appeared on CSS-Tricks and was authored by Geoff Graham

A little gem from Kevin Powell’s “HTML & CSS Tip of the Week” website, reminding us that using container queries opens up container query units for sizing things based on the size of the queried container.

cqi and cqb are similar to vw and vh, but instead of caring about the viewport, they care about their containers size.

cqi is your inline-size unit (usually width in horizontal writing modes), while cqbhandles block-size (usually height).

So, 1cqi is equivalent to 1% of the container’s inline size, and 1cqb is equal to 1% of the container’s block size. I’d be remiss not to mention the cqmin and cqmax units, which evaluate either the container’s inline or block size. So, we could say 50cqmax and that equals 50% of the container’s size, but it will look at both the container’s inline and block size, determine which is greater, and use that to calculate the final computed value.

1200px by 500px rectangle showing that 50cqmax is equal to 50% of the larger size.

That’s a nice dash of conditional logic. It can help maintain proportions if you think the writing mode might change on you, such as moving from horizontal to vertical.


Container query units: cqi and cqb originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.


This content originally appeared on CSS-Tricks and was authored by Geoff Graham


Print Share Comment Cite Upload Translate Updates
APA

Geoff Graham | Sciencx (2025-02-06T15:29:35+00:00) Container query units: cqi and cqb. Retrieved from https://www.scien.cx/2025/02/06/container-query-units-cqi-and-cqb/

MLA
" » Container query units: cqi and cqb." Geoff Graham | Sciencx - Thursday February 6, 2025, https://www.scien.cx/2025/02/06/container-query-units-cqi-and-cqb/
HARVARD
Geoff Graham | Sciencx Thursday February 6, 2025 » Container query units: cqi and cqb., viewed ,<https://www.scien.cx/2025/02/06/container-query-units-cqi-and-cqb/>
VANCOUVER
Geoff Graham | Sciencx - » Container query units: cqi and cqb. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/02/06/container-query-units-cqi-and-cqb/
CHICAGO
" » Container query units: cqi and cqb." Geoff Graham | Sciencx - Accessed . https://www.scien.cx/2025/02/06/container-query-units-cqi-and-cqb/
IEEE
" » Container query units: cqi and cqb." Geoff Graham | Sciencx [Online]. Available: https://www.scien.cx/2025/02/06/container-query-units-cqi-and-cqb/. [Accessed: ]
rf:citation
» Container query units: cqi and cqb | Geoff Graham | Sciencx | https://www.scien.cx/2025/02/06/container-query-units-cqi-and-cqb/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.