Patch Bandit

The story / The lab

Waffle fry · 2026-11-22

CSS container query and style queries

A CSS container query lets a component respond to the width of its own box instead of the whole browser screen, so one card works cleanly in a narrow sidebar or a wide grid. Pair size rules with CSS style queries and a single custom property can switch layouts and themes with zero JavaScript.

Stop rewriting viewport breakpoints every time a card moves into a sidebar.

Snick the raccoon testing a resizing card

Resize the container and switch its style variant

Pick a preset width below (or drag the bottom-right corner on desktop) and toggle --variant to test container size queries and container style queries together — zero JavaScript.

Container width
Style query (--variant)
Bandit CodesLayout: badge (< 340px)Layout: stacked (340–539px)Layout: split (>= 540px)

Free browser QR studio, zero login

Generates sharp SVG and PNG codes right inside your browser tab. No account wall, no redirect links, and no monthly fee for plain squares.

Type scales with cqiMatches @container

Desktop tip: drag the coral corner handle on the box above to scrub smoothly across every breakpoint.

Why a CSS container beats viewport media queries

Traditional @media rules only know how wide the whole browser window is. Drop the same product card into a wide hero and a tight sidebar on the same desktop page, and a media query cannot tell them apart.

With CSS container queries, you mark a parent wrapper with container-type: inline-size. Every child inside can then query that wrapper's width, scale text smoothly with cqw and cqi container query units, and read custom properties with @container style(--variant: featured).

Three rules running in the demo

  • < 340px · compact badge

    Hides the decorative square graphic and tightens padding so the card fits inside tight rails and phone columns.

  • 340px–539px · stacked card

    Reveals the emblem strip above the text and opens up spacing while fluid cqi type grows smoothly.

  • >= 540px · horizontal split

    Switches to a two-column grid with the graphic anchored on the left beside full copy and metadata.

  • style(--variant: ...)

    Reads one custom property on the container to swap into the gold featured look or dashed compact mode.

Copy the CSS container query and style query code

Container size queries and cqi units (CSS)
/* 1. Turn the wrapper into a named inline-size container */
.card-slot {
  container-type: inline-size;
  container-name: card;
}

/* 2. Adapt the card to its own box width, plus fluid cqi type */
.item-card {
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
}
.item-card h3 {
  font-size: clamp(1.05rem, 4.5cqi, 1.55rem);
}

@container card (min-width: 340px) {
  .item-card { padding: 1.25rem; }
  .item-card .meta { display: flex; gap: 0.6rem; }
}

@container card (min-width: 540px) {
  .item-card {
    grid-template-columns: 11rem 1fr;
    align-items: center;
    gap: 1.35rem;
  }
}

Component wrapper markup (HTML)
<div class="card-slot is-featured">
  <article class="item-card">
    <div class="thumb" aria-hidden="true">QR</div>
    <div class="body">
      <span class="badge">Browser tool</span>
      <h3>Bandit Codes</h3>
      <p class="blurb">Build SVG and PNG codes locally with no login.</p>
      <p class="meta">Zero uploads · MIT code</p>
    </div>
  </article>
</div>

CSS style queries on custom properties (CSS)
/* 3. Flip inner card looks with CSS style queries (Baseline 2026) */
.card-slot.is-featured {
  --variant: featured;
}
.card-slot.is-compact {
  --variant: compact;
}

@container card style(--variant: featured) {
  .item-card {
    border-color: #ffc857;
    background: #2b1840;
  }
  .item-card .badge {
    background: #ffc857;
    color: #170c26;
  }
}

@container card style(--variant: compact) {
  .item-card {
    padding: 0.85rem 1rem;
    border-style: dashed;
  }
  .item-card .blurb { display: none; }
}

Browser support (checked 2026-11-22): Container size queries (container-type: inline-size, @container, and cqw/cqi units) are Baseline Widely Available across Chrome 105+, Edge 105+, Safari 16+, and Firefox 110+ (Web Platform Dashboard: container-queries). Custom-property container style queries (@container style(--prop: val)) became Baseline Newly Available in May 2026 across Chrome 111+, Edge 111+, Safari 18+, and Firefox 151+ (Web Platform Dashboard: container-style-queries). Older browsers ignore the style query rules and keep the default card look. Tested in Chromium only.

The fine print, in plain words

Why this is free

We're raccoons who think simple things shouldn't cost a monthly fee. We take techniques apart, explain them in plain words, and give them away. The code on this page is MIT licensed: copy it, change it, and share it.

This is one of twelve experiments so far. Our first browser tool (Bandit Codes) is live now, and the rest sit as ideas in the stash.