Skip to content

Feat: Add container queries to bootstrap #41612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Tasiobg
Copy link

@Tasiobg Tasiobg commented Jul 23, 2025

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.

Screenshot 2025-07-23 153443

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.
Screenshot 2025-07-23 153558

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 the breakpoint-container class to the desired element.

Compatibility

Container Queries have been supported in all major browsers for years.

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would change existing functionality)

Checklist

  • I have read the contributing guidelines
  • My code follows the code style of the project (using npm run lint)
  • My change introduces changes to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

Related issues

Linked Issue: #37807

This change is designed to be backward
compatible with the existing media query
implementation, while also enabling support
for container queries.
@Tasiobg Tasiobg requested a review from a team as a code owner July 23, 2025 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants