Feat: Add container queries to bootstrap #41612
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Container queries implementation for Bootstrap.
This change is designed to be backward compatible with the existing media query implementation, while also enabling support for container queries.
Motivation & Context
Bootstrap uses media queries for responsive design, which are based on the browser's viewport. However, this approach has limitations. For example, if a component is initially designed for the main content area and later reused inside a smaller container, the media queries still respond only to the overall viewport size, not the size of the component’s parent container. This means the layout may not adapt correctly in different contexts. See the image below for a visual example.
If I display the course overview in a side panel. Instead of adapting to the narrower space and showing just one item per line, it still uses the browser viewport width and continues to display multiple items, which can break the layout.

With Container Queries, this limitation is eliminated because breakpoints can now be applied relative to the size of a specific container, rather than the entire browser viewport.
Expectations
This is my first time opening a PR in Bootstrap and I'm not sure if submitting a PR is the best approach. That said, I believe the lack of Container Query support is a challenge many developers are currently facing and before turning to custom CSS solutions or maintaining a personal fork of Bootstrap, I wanted to ask whether this approach could be considered for inclusion or if there are any existing plans to support Container Queries soon. I'd also appreciate any feedback or guidance.
Technical details
The linked issue includes several comments and alternative suggestions for addressing this problem. The approach in this PR closely follows @Joniras's approach, the idea is to literally replace media queries with content queries and add
container-type: inline-size
to the root element, this way and unless the size of the<html>
element is modified, Bootstrap will behave just like it does with media queries because the<html>
width should match the viewport width. This ensures backward compatibility for existing sites while enabling developers to opt in to container-based breakpoints by simply adding thebreakpoint-container
class to the desired element.Compatibility
Container Queries have been supported in all major browsers for years.
Type of changes
Checklist
npm run lint
)Related issues
Linked Issue: #37807