Prefer Container Queries logo

Prefer Container Queries

Community
flornkm
prefer-container-queries

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.

Overview

Publisherflornkm
Repositoryskills
Skill nameprefer-container-queries
Stars
115
Forks
7
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by flornkm on GitHub. Read the source before you install it.

Installation

Install the Prefer Container Queries AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/flornkm/skills/tree/main/skills/prefer-container-queries
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/flornkm/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/skills/prefer-container-queries .claude/skills/prefer-container-queries
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Prefer Container Queries in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Prefer Container Queries on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Prefer Container Queries is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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:

html
<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:

VariantMin width
@3xs16rem (256px)
@2xs18rem (288px)
@xs20rem (320px)
@sm24rem (384px)
@md28rem (448px)
@lg32rem (512px)
@xl36rem (576px)
@2xl42rem (672px)
@3xl48rem (768px)
@4xl56rem (896px)
@5xl64rem (1024px)
@6xl72rem (1152px)
@7xl80rem (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.

Frequently asked questions

What does the Prefer Container Queries AI skill do?

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.

Why use Prefer Container Queries on TypingMind?

Because you install it once and use it with any model. Prefer Container Queries is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Prefer Container Queries in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/flornkm/skills/tree/main/skills/prefer-container-queries. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Prefer Container Queries?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Prefer Container Queries?

As many as you like. As long as a model supports skills, you can use Prefer Container Queries with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Prefer Container Queries AI skill free?

Yes. It is published on GitHub by flornkm under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇