Course contentsShow
← Web Development
Lesson 437 of 2,9827. Responsive DesignFree lesson

Size vs Inline-Size Containment

Understanding the difference between container-type: size and inline-size for query containment scope.

Size vs Inline-Size Containment

You'll learn the difference between size and inline-size container types and when to use each.

When you set up a container query context, you must choose what the container should track: its full dimensions or just its inline dimension (width in horizontal writing modes).

The Two Containment Options

container-type: size

This tracks both width and height of the container. You can query against both dimensions:

.card-container {
  container-type: size;
}

@container (min-width: 400px) and (min-height: 300px) {
  /* Styles when container is wide AND tall enough */
}

The catch: Using size prevents the container from expanding based on its content's height. The container needs a defined height (or will collapse).

container-type: inline-size

This tracks only the inline dimension (width in normal layouts). This is the most common choice:

.card-container {
  container-type: inline-size;
}

@container (min-width: 400px) {
  /* Styles based only on container width */
}

The benefit: The container can still grow naturally with its content vertically—no height restrictions.

When to Use Each

  • Use inline-size (default choice): For most responsive components where you care about available width but want natural content flow vertically.
  • Use size: Only when you need to query both dimensions and have explicit height control on your container.

Think of it like a window frame: inline-size lets you adjust to the width while the height stretches for your content. size locks both dimensions—useful but restrictive.

Key Takeaway: Use container-type: inline-size for most container queries—it tracks width while allowing natural height growth. Only use size when you need both-dimension queries and can control container height.