Home > Designing, Others > Container query units: cqi and cqb

Container query units: cqi and cqb

February 6th, 2025 Leave a comment Go to comments
1200px by 500px rectangle showing that 50cqmax is equal to 50% of the larger size.

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.

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.

Categories: Designing, Others Tags:
  1. No comments yet.
You must be logged in to post a comment.