Responsive design

Choose what drives the layout: window width, container width or component behaviour. Below are four configurable examples.

Choosing a condition

  • Start with a narrow screen: one column, wrapping buttons and the original DOM order. Add columns when there is enough space.
  • Media queries describe the viewport. Auto-fit and container queries suit cards that may appear in a sidebar or a wide area.
  • Use JavaScript when behaviour changes, not just element placement. CSS and matchMedia must use the same numeric boundary.
  • Keep required fields, error messages and primary actions visible. Check long text, zoom and keyboard use.

Import legato-ui/styles/primitives.css after base.css. The example and copyable code use the same SFC.

Legato UI breakpoints

NameWidthUse in the example
sm640 pxTwo columns
md900 pxThree columns and expanded filter mode
lg1200 pxFour columns

wlBreakpoints is the exported numeric catalogue for the application. Values are stored in packages/ui-kit/tokens/source.json; the generator updates the TypeScript catalogue. Values are not tied to device models and do not rewrite existing media queries.

Media queries use a numeric boundary. var() works in property values, not size conditions @media or @container. CSS custom properties — MDN.

Mobile-first: window width

One column by default; two from sm, three from md and four from lg. CSS also controls the current breakpoint label, with no resize listener.

The number of columns depends on the viewport width, even when the example is in a narrow documentation column.

01

Research

Cards preserve reading order when the layout changes.

02

Prototype

Cards preserve reading order when the layout changes.

03

Development

Cards preserve reading order when the layout changes.

04

Review

Cards preserve reading order when the layout changes.

Current breakpoint: below 640 px · 1 columnsm · from 640 px · 2 columnsmd · from 900 px · 3 columnslg · from 1200 px · 4 columns

Vue SFC · application example
<script setup lang="ts">
const steps = ["Research", "Prototype", "Development", "Review"];
</script>

<template>
  <section class="wl-stack" data-space="lg">
    <p class="wl-text-small wl-text-muted">{{ "The number of columns depends on the viewport width, even when the example is in a narrow documentation column." }}</p>
    <div class="viewport-layout-example wl-grid" data-space="md">
      <article
        v-for="(step, index) in steps"
        :key="step"
        class="wl-surface wl-stack"
        data-space="sm"
      >
        <span class="wl-text-code wl-text-muted">0{{ index + 1 }}</span>
        <h3 class="wl-text-subheading">{{ step }}</h3>
        <p class="wl-text-small">{{ "Cards preserve reading order when the layout changes." }}</p>
      </article>
    </div>
    <p class="wl-text-small" role="status">{{ "Current breakpoint:" }}
      <span class="viewport-tier viewport-tier--base">{{ "below 640 px · 1 column" }}</span>
      <span class="viewport-tier viewport-tier--sm">{{ "sm · from 640 px · 2 columns" }}</span>
      <span class="viewport-tier viewport-tier--md">{{ "md · from 900 px · 3 columns" }}</span>
      <span class="viewport-tier viewport-tier--lg">{{ "lg · from 1200 px · 4 columns" }}</span>
    </p>
  </section>
</template>

<style scoped>
.viewport-layout-example { grid-template-columns: minmax(0, 1fr); }
.viewport-tier { display: none; }
.viewport-tier--base { display: inline; }
/* Numeric values follow wlBreakpoints; CSS cannot read that TypeScript object. */
@media (min-width: 640px) {
  .viewport-layout-example { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .viewport-tier--base { display: none; }
  .viewport-tier--sm { display: inline; }
}
@media (min-width: 900px) {
  .viewport-layout-example { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .viewport-tier--sm { display: none; }
  .viewport-tier--md { display: inline; }
}
@media (min-width: 1200px) {
  .viewport-layout-example { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .viewport-tier--md { display: none; }
  .viewport-tier--lg { display: inline; }
}
</style>

Auto-fit and local tokens

Change the minimum column width, gap and gutter. The grid follows its parent's width. Application breakpoints stay the same.

Card 1

Auto-fit chooses the number of columns from this grid's width.

Card 2

Auto-fit chooses the number of columns from this grid's width.

Card 3

Auto-fit chooses the number of columns from this grid's width.

Card 4

Auto-fit chooses the number of columns from this grid's width.

Minimum: 240px · gap: 20px · gutter: 24px. These values apply only inside the example.

Vue SFC · application example
<script setup lang="ts">
import { WlSelect } from "legato-ui";
import { ref } from "vue";
const minimum = ref("240px");
const gap = ref("20px");
const gutter = ref("24px");
const minimumOptions = ["180px", "240px", "320px"];
const gapOptions = ["12px", "20px", "32px"];
const gutterOptions = ["8px", "24px", "40px"];
</script>

<template>
  <section class="wl-stack" data-space="lg">
    <div class="fluid-grid-controls wl-grid" data-space="md">
      <div class="wl-stack" data-space="xs">
        <label for="responsive-minimum" class="wl-text-label">{{ "Minimum column width" }}</label>
        <WlSelect
          id="responsive-minimum"
          v-model="minimum"
          aria-label="Minimum column width"
          :options="minimumOptions"
        />
      </div>
      <div class="wl-stack" data-space="xs">
        <label for="responsive-gap" class="wl-text-label">{{ "Grid gap" }}</label>
        <WlSelect
          id="responsive-gap"
          v-model="gap"
          aria-label="Grid gap"
          :options="gapOptions"
        />
      </div>
      <div class="wl-stack" data-space="xs">
        <label for="responsive-gutter" class="wl-text-label">{{ "Side gutter" }}</label>
        <WlSelect
          id="responsive-gutter"
          v-model="gutter"
          aria-label="Side gutter"
          :options="gutterOptions"
        />
      </div>
    </div>
    <div
      class="fluid-grid-container wl-container wl-container--fluid"
      :style="{ '--wl-layout-grid-min': minimum, '--wl-layout-grid-gap': gap, '--wl-layout-page-gutter': gutter }"
    >
      <!-- No data-space: this grid uses --wl-layout-grid-gap instead. -->
      <div class="wl-grid">
        <article
          v-for="index in 4"
          :key="index"
          class="wl-surface wl-stack"
          data-space="sm"
        >
          <h3 class="wl-text-subheading">{{ "Card" }} {{ index }}</h3>
          <p class="wl-text-small">{{ "Auto-fit chooses the number of columns from this grid's width." }}</p>
        </article>
      </div>
    </div>
    <p class="wl-text-small wl-text-muted" role="status">
      {{ "Minimum:" }} {{ minimum }} · gap: {{ gap }} · gutter: {{ gutter }}{{
        ". These values apply only inside the example."
      }}
    </p>
  </section>
</template>

<style scoped>
.fluid-grid-controls { grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }
.fluid-grid-container { padding-block: var(--wl-space-md); background: var(--wl-bg-soft); border-radius: var(--wl-corner-surface); }
</style>

Container queries: card space

Choose container width. The child card structure changes from 420 px and its heading from 560 px; window size stays the same.

Card in a narrow and wide container

The card uses one column in a narrow sidebar and two in a wide area. The viewport width stays the same.

Requested: 420px. The parent limits the container width; two columns appear at an actual width of 420 px or more.

Vue SFC · application example
<script setup lang="ts">
import { WlIcon, WlSelect } from "legato-ui";
import { ref } from "vue";
const width = ref("420px");
const widthOptions = ["280px", "420px", "640px"];
</script>

<template>
  <section class="wl-stack" data-space="lg">
    <div class="container-card-control wl-stack" data-space="xs">
      <label for="responsive-container-width" class="wl-text-label">{{ "Container width" }}</label>
      <WlSelect
        id="responsive-container-width"
        v-model="width"
        aria-label="Container width"
        :options="widthOptions"
      />
    </div>
    <div class="container-card-host" :style="{ width: 'min(100%, ' + width + ')' }">
      <article class="container-card-body wl-surface">
        <div class="container-card-illustration" aria-hidden="true"><WlIcon name="grid" :size="36" /></div>
        <div class="wl-stack" data-space="sm">
          <h3 class="container-card-heading wl-text-subheading">
            {{ "Card in a narrow and wide container" }}
          </h3>
          <p class="wl-text-body">{{ "The card uses one column in a narrow sidebar and two in a wide area. The viewport width stays the same." }}</p>
        </div>
      </article>
    </div>
    <p class="wl-text-small wl-text-muted" role="status">
      {{ "Requested:" }} {{ width }}{{
        ". The parent limits the container width; two columns appear at an actual width of 420 px or more."
      }}
    </p>
  </section>
</template>

<style scoped>
.container-card-control { max-width: 240px; }
.container-card-host { container-type: inline-size; container-name: gavia-card; max-width: 100%; }
.container-card-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--wl-space-lg); }
.container-card-illustration {
  display: grid;
  place-items: center;
  min-height: 96px;
  border-radius: var(--wl-corner-surface);
  color: var(--wl-text-accent);
  background: var(--wl-accent-soft);
}
@container gavia-card (min-width: 420px) {
  .container-card-body { grid-template-columns: 96px minmax(0, 1fr); align-items: center; }
}
@container gavia-card (min-width: 560px) {
  .container-card-heading { font-size: var(--wl-type-heading-size); }
}
</style>

MatchMedia: behaviour changes

From md the filter is visible; below md a button expands it. The model persists, the subscription updates when the condition changes and is removed on unmount.

Wide mode: the filter is immediately visible

Typed text survives the layout change. Its model is outside the conditional markup.

Current value: empty. CSS handles placement; matchMedia changes only the filter's behavior.

Vue SFC · application example
<script setup lang="ts">
import { wlBreakpoints, WlButton, WlInput } from "legato-ui";
import { computed, nextTick, onBeforeUnmount, onMounted, ref } from "vue";
const wide = ref<boolean | null>(null);
const filtersOpen = ref(false);
const search = ref("");
const filter = ref<HTMLElement | null>(null);
const toggle = ref<HTMLElement | null>(null);
let media: MediaQueryList | undefined;
let mounted = false;
let revision = 0;
const mode = computed(() => wide.value === null ? "The width is determined after mounting" : wide.value ? "Wide mode: the filter is immediately visible" : "Narrow mode: a button opens the filter");
function updateMode(): void {
  const nextWide = media?.matches ?? null;
  const active = document.activeElement;
  // Keep the filter visible if narrowing would otherwise remove its focused field.
  if (nextWide === false && active && filter.value?.contains(active)) filtersOpen.value = true;
  const moveFocus = nextWide === true && active && toggle.value?.contains(active);
  wide.value = nextWide;
  const current = ++revision;
  if (moveFocus) void nextTick(() => {
    if (mounted && current === revision && wide.value === true) filter.value?.querySelector<HTMLInputElement>("input")?.focus();
  });
}
onMounted(() => {
  mounted = true;
  // Browser APIs are read only after mounting; importing and SSR stay safe.
  media = window.matchMedia("(min-width: " + wlBreakpoints.md + "px)");
  updateMode();
  media.addEventListener("change", updateMode);
});
onBeforeUnmount(() => {
  mounted = false;
  revision++;
  media?.removeEventListener("change", updateMode);
});
</script>

<template>
  <section class="wl-stack" data-space="lg">
    <p class="wl-text-small" role="status">{{ mode }}</p>
    <div v-if="wide === false" ref="toggle">
      <WlButton
        aria-controls="responsive-behavior-filter"
        :aria-expanded="filtersOpen"
        @click="filtersOpen = !filtersOpen"
      >{{ filtersOpen ? "Hide filter" : "Show filter" }}</WlButton>
    </div>
    <div
      v-if="wide || filtersOpen"
      id="responsive-behavior-filter"
      ref="filter"
      class="media-behavior-filter wl-surface wl-stack"
      data-space="sm"
    >
      <label for="responsive-behavior-search" class="wl-text-label">{{ "Search in the example" }}</label>
      <WlInput id="responsive-behavior-search" v-model="search" placeholder="For example, card" />
      <p class="wl-text-small wl-text-muted">{{ "Typed text survives the layout change. Its model is outside the conditional markup." }}</p>
    </div>
    <p class="wl-text-small wl-text-muted">
      {{ "Current value:" }} {{ search || "empty" }}{{
        ". CSS handles placement; matchMedia changes only the filter's behavior."
      }}
    </p>
  </section>
</template>

<style scoped>
.media-behavior-filter { min-width: 0; }
@media (min-width: 900px) { .media-behavior-filter { max-width: 480px; } }
</style>

Overriding defaults

For an individual page, set tokens on its root: container width, gutter, minimum column width and gap. wl-grid with data-space uses the gap from the selected role; without it, from --wl-layout-grid-gap. These values inherit locally and do not change media query conditions.

CSS · local page settings
/* A local application layout; no global token mutation. */
.project-page {
  --wl-layout-page-max: 1440px;
  --wl-layout-page-gutter: clamp(12px, 3vw, 32px);
  --wl-layout-grid-min: 280px;
  --wl-layout-grid-gap: var(--wl-space-lg);
}
.project-layout { display: grid; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 820px) {
  .project-layout { grid-template-columns: 240px minmax(0, 1fr); }
}

If the page needs to rearrange at 820 px, use a regular local condition as above. When changing behaviour, pass the same number to matchMedia. For the block's own width, set container-type: inline-size, name the container and apply @container to its descendants. Container queries — MDN.

In the Legato UI source, edit the catalogue in tokens/source.json → breakpoints and run pnpm tokens:sync, then pnpm tokens:check. The generator updates the catalogue; manual @media in CSS and components must be aligned separately. The library has no global runtime breakpoint switch.

Built-in component breakpoints

ElementCurrent boundaryWhat to consider
WlPageHeaderBelow 720 pxCSS rearranges the layout.
WlFilterBarBelow 720 pxCSS and matchMedia jointly control the mobile panel, inert/aria-hidden and scroll locking.
WlSidebarBelow 900 pxCSS defines the mobile layout; the application controls mobileOpen/pinned/collapsible.

There is currently no public prop for changing these boundaries. Sidebar/drawer width tokens set panel size, not the switch point. For WlFilterBar, changing the boundary only in CSS is insufficient: behaviour, accessibility and scroll locking must switch together.

This playground's header and Docs have their own navigation-space conditions. These conditions suit site navigation; library components have their own boundaries. Dialogs are constrained by viewport width, and long action groups can scroll within their region.

The JavaScript example subscribes only after onMounted, removes its listener in onBeforeUnmount, and does not read window on import or during SSR. When narrowing, the focused filter remains; when widening, focus moves from the disappearing button to the field. matchMedia and change event — MDN.

What to check

  • Check narrow screens, the condition boundary and widths immediately before/after it; also check a card in a narrow parent.
  • Long labels, localisation, zoom and wrapping buttons must not cause page-level horizontal scrolling.
  • Tab order follows DOM order. After rearrangement, focus stays accessible and entered data persists.
  • Overlays, masks, inert/aria-hidden and scroll locking switch together with behaviour; check Escape and focus restoration.
  • CSS handles layout without JavaScript. Dynamic listeners are needed only for behaviour and are removed when the page closes.