prefer-container-queries

Enforce using Tailwind container queries (@container) instead of viewport breakpoints (e.g., sm:/md:/lg:) for responsive components. Intended for writing or reviewing responsive Tailwind code, especially when a component must adapt to its own available space (for reused cards, sidebars, lists, panels across layouts) or when migrating sm:/md:/lg: classes to @container variants.

Last repository push
GitHub Stars
117
Forks
7
Issues / PRs
0

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "prefer-container-queries" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-af3847dc8c2491b0aa67174c3b31a5f0b656966c90952a2c25d9cd11a0912251. Verify the upstream source and version against https://github.com/flornkm/skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Enforce using Tailwind container queries (@container) instead of viewport breakpoints (e.g., sm:/md:/lg:) for responsive components. Intended for writing or reviewing responsive Tailwind code, especially when a component must adapt to its own available space (for reused cards, sidebars, lists, panels across layouts) or when migrating sm:/md:/lg: classes to @container variants.

0 Downloads

Introduction source: third_party · flornkm · 0.0.1 Reference

SkillPi interpretation

Tasks
Enforce Tailwind container queries over viewport breakpoints for responsive components. Use when writing or reviewing responsive Tailwind code, when a component needs to adapt to its available space (cards, sidebars, lists, panels, anything reused in different layouts), or when migrating sm:/md:/lg: classes to @container variants.
Audience
Not specified in the source documentation.
Inputs and outputs
Not specified in the source documentation.
Software, accounts and paid services
Not specified in the source documentation.
Limits and differences
Not specified in the source documentation.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: prefer-container-queries
description: "Enforce Tailwind container queries over viewport breakpoints for responsive components. Use when writing or reviewing responsive Tailwind code, when a component needs to adapt to its available space (cards, sidebars, lists, panels, anything reused in different layouts), or when migrating sm:/md:/lg: classes to @container variants."

Prefer Container Queries

Components should respond to the space they are in, not to the viewport. A card that lives in a sidebar has maybe 300px of width even on a huge screen, and a viewport breakpoint like md:flex-row will get that wrong every time. Container queries fix this: the component asks "how wide am I?" instead of "how wide is the window?".

When writing responsive Tailwind, default to container queries. Viewport breakpoints are the exception, not the rule.

How it works

Mark the parent as a container, then use @-prefixed variants on its children:

<div class="@container">
  <div class="flex flex-col @md:flex-row @md:gap-6">
    <img class="w-full @md:w-48" />
    <div class="@md:flex-1">...</div>
  </div>
</div>

@md: here means "when the container is at least 28rem wide", regardless of viewport size. This card works in a sidebar, a modal, and a full-width grid without changing a single class.

Two rules that trip people up:

  1. The @container class goes on the parent. The @md: variants go on descendants. An element cannot query its own size.
  2. Container variants respond to the nearest ancestor with @container. If styles are not applying, check which container you are actually querying.

Variants

Tailwind v4 ships container queries in core. The sizes:

Variant Min width
@3xs 16rem (256px)
@2xs 18rem (288px)
@xs 20rem (320px)
@sm 24rem (384px)
@md 28rem (448px)
@lg 32rem (512px)
@xl 36rem (576px)
@2xl 42rem (672px)
@3xl 48rem (768px)
@4xl 56rem (896px)
@5xl 64rem (1024px)
@6xl 72rem (1152px)
@7xl 80rem (1280px)

Also available:

  • @max-md: styles below a container size.
  • @min-[475px]: arbitrary values when the scale does not fit.
  • @container/sidebar plus @md/sidebar:flex-row to name a container and query it from deeper in the tree, past other containers.

The full docs for this can be found here.

On Tailwind v3, the same syntax needs the @tailwindcss/container-queries plugin. Check the Tailwind version before writing classes.

When viewport breakpoints are still right

Do not convert these:

  • Page-level layout. The overall grid, whether the sidebar exists at all, header and navigation behavior. These genuinely depend on the viewport.
  • Fixed or sticky elements positioned relative to the viewport, like a bottom bar that becomes a side rail.
  • Global typography scale tied to screen size.

Everything inside those layout regions, meaning cards, forms, media objects, stat blocks, table-to-list switches, should use container queries.

Migrating existing code

  1. Find the component's responsive classes (sm:, md:, lg:).
  2. Add @container to the component's root or the wrapper that owns the available space.
  3. Replace viewport variants with the container variant that matches the actual width where the layout should change. Do not map md: to @md: blindly; md is 768px of viewport, @md is 448px of container. Resize the container, not the window, to find the real breakpoint.
  4. Test the component in its narrowest real context (sidebar, drawer, small grid cell), not just at mobile viewport widths.

Mistakes to catch in review

  • md:flex-row on a component that is rendered inside a sidebar or modal. It will stay stacked or break depending on the viewport, not its actual space.
  • @md: variants used with no @container ancestor. They silently never apply.
  • @container and a @md: variant on the same element. The element cannot query itself; move the variant to a child or the container class to the parent.
  • A component that only looks right at the exact spot it was built for. If moving it to a different column breaks it, it is viewport-coupled.

Current listing version

0.0.1

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value78/100

Highlights

  • 针对 Tailwind CSS 容器查询的实用指南,解决响应式组件的实际痛点
  • 面向前端开发者,提供具体使用场景和迁移方法
Trigger Precision92/100

Highlights

  • description 清晰描述了使用场景和适用组件类型
  • 覆盖了从传统断点迁移到容器查询的完整场景
Structure and Standards95/100

Highlights

  • 结构清晰,包含工作原理、变体说明、迁移指南和常见错误
  • 提供完整的代码示例和尺寸对照表
Execution Reliability88/100

Highlights

  • 信息准确,包含 Tailwind v4 官方语法和版本兼容性说明
  • 指出了常见错误和检查方法,提高执行成功率
Evidence Verifiability (mean of the first four)88/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

Domains or addresses referenced in the document

These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.

  • tailwindcss.com

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Not specified in the source documentation.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.