Communitygithub.com

responsive-ui

Use whenever building or changing web UI that must work across screen sizes — layouts, navigation/menus, images, video, grids, breakpoints, embeds/ads. Modern best practice built on Ethan Marcotte's "Responsive Design: Patterns & Principles". Called by /new-ui; also invoked manually as /responsive-ui.

responsive-ui 是什麼?

responsive-ui is a Claude Code agent skill that use whenever building or changing web UI that must work across screen sizes — layouts, navigation/menus, images, video, grids, breakpoints, embeds/ads. Modern best practice built on Ethan Marcotte's "Responsive Design: Patterns & Principles". Called by /new-ui; also invoked manually as /responsive-ui.

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Cucuteanu-Tudor-912/UI-DESIGN-SKILLS/tree/HEAD/skills/responsive-ui

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件


name: responsive-ui description: Use whenever building or changing web UI that must work across screen sizes — layouts, navigation/menus, images, video, grids, breakpoints, embeds/ads. Modern best practice built on Ethan Marcotte's "Responsive Design: Patterns & Principles". Called by /new-ui; also invoked manually as /responsive-ui.

Responsive UI

The principles come from Ethan Marcotte, Responsive Design: Patterns & Principles. The techniques are current CSS and HTML. Use the platform features below instead of the JS workarounds and polyfills the book needed in 2015.

"Our media queries defend the integrity of the content." "What works is better than what looks good."

1. Components, not pages

  • Every component adapts to its own space, not to the viewport.
    • Use container queries: put container-type: inline-size on the wrapper, then use @container (min-width: …).
    • A card should look right in a sidebar and in a main column without page-level breakpoints.
  • Keep viewport media queries for page-level layout: the overall grid, nav, and the shift from a single column to columns.
  • Reuse the repo's existing components and design tokens. A responsive component makes whatever is placed in it responsive.

2. Intrinsic layout first, breakpoints second

  • Let the layout flex before adding breakpoints. Many layouts need no breakpoint at all.
    • Use grid-template-columns: repeat(auto-fit, minmax(min(16rem, 100%), 1fr)).
    • Use flex-wrap: wrap with flex-basis.
    • Use min(), max() and clamp().
  • CSS Grid for two-dimensional page layout. Flexbox for one-dimensional rows and stacks. Keep layout in CSS, not in column-class soup in the markup.
  • Breakpoints come from content, not devices. Widen from the smallest size until the seams show, and add a breakpoint there. Never use device presets such as 768 or 1024.
    • Write breakpoints in rem/em so they respect the user's font size.
    • Use the range syntax: @media (width >= 40rem).
  • At each breakpoint, check four things:
    • Width: layout, and type too, can change.
    • Hierarchy: decide what comes first in one column.
    • Interaction: the same information may need a different control.
    • Density: extras at wider widths are enhancements only.
  • Fluid type and spacing. Use font-size: clamp(1rem, 0.9rem + 0.5vw, 1.25rem). Always include a rem part so zoom still works. Keep the line length about 45–75ch (max-width: 65ch).
  • Use modern viewport units.
    • Use 100dvh/100svh, not 100vh, which breaks with mobile browser bars.
    • Respect notches with env(safe-area-inset-*) and viewport-fit=cover.
  • Use logical properties (margin-inline, padding-block, inset-inline-start) so the layout survives right-to-left languages and writing-mode changes.
  • Visual order follows DOM order. If you rearrange with grid areas or order, the tab and reading order must still make sense. Reorder in the source instead when you can.

3. Design for conditions, not "mobile/tablet/desktop"

  • Query capabilities, not assumed devices:
    • @media (hover: hover) and (pointer: fine) for hover effects;
    • (pointer: coarse) for bigger targets;
    • prefers-reduced-motion;
    • prefers-color-scheme;
    • prefers-contrast.
  • Never assume that wide means mouse, small means slow, or that the user is online.
  • Touch targets are at least 24×24 CSS px (WCAG 2.2). Aim for about 44px on primary actions.
  • Assume a slow network. Screen width says nothing about bandwidth. Test with "Slow 4G" throttling.

4. Same content everywhere

  • Every width reaches the same content and actions. The UI may present them differently.
  • Don't hide content with display: none just to make it fit. Rethink the layout first. Load heavy, non-critical extras only when needed, for example by lazy-loading or importing a component on demand.
  • Plan mobile-first:
    1. Find what's critical at small sizes.
    2. Everyone gets that, at every width.
    3. Anything extra at wider widths is an enhancement.

5. Navigation

  • Try changing the layout before hiding anything.

    • Short, focused nav can wrap or restack instead of collapsing.
    • Or reveal it gradually: show the links that fit and put the rest under "More", or use a horizontally scrollable strip with an "All sections" link.
  • If you collapse it, use native primitives:

    • a <button aria-expanded aria-controls>; or
    • <details>/<summary>; or
    • the Popover API (popover + popovertarget).

    These give keyboard support and Escape for free. Don't build a toggle from a fake <a> or <div>.

  • Off-canvas or drawer menus:

    • Trap or manage focus, and set inert on the background while open.
    • Close on Escape and return focus to the trigger.
    • Consider <dialog> for full-screen menus.
  • Show the full nav when there is room.

  • Curate drawers hard. Menus fill with junk. A drawer is not an excuse to avoid prioritizing.

  • Dropdowns open on click, tap and keyboard, never on hover only.

  • A visible "Menu" label beats a bare hamburger icon for most audiences. Make sure the icon has an accessible name either way.

6. Images and video

  • Prevent layout shift. Always set width and height attributes, or a CSS aspect-ratio, on images, video and iframes. The browser then reserves the space.
  • Fluid media: use img, video { max-width: 100%; height: auto }. Use aspect-ratio: 16 / 9; width: 100% for embeds. No JS resizing.
  • Responsive sources:
    • Fixed-size images get srcset with 1x/2x.
    • Fluid images get srcset with w descriptors plus an accurate sizes.
    • Always keep src.
    • If the framework has an image component (Next <Image>, Astro <Image>, etc.), use it.
  • Modern formats: AVIF or WebP through <picture><source type>, with a JPEG/PNG fallback <img>. Use SVG for logos and icons.
  • Art direction: use <picture><source media> when small screens need a different crop. Use object-fit: cover with object-position to keep the focal point.
  • Loading priority:
    • Below-the-fold images get loading="lazy" and decoding="async".
    • The LCP or hero image is never lazy. It gets fetchpriority="high".
  • Make sure the image still reads when small. Text inside images, dense charts and maps break when scaled down. Use real text, a different crop, or a text alternative. Every meaningful image needs alt.

7. Embeds, ads and third-party widgets

  • Reserve their space with a fixed min-height or aspect-ratio, so they don't shift the layout when they load.
  • Load them only where the layout can hold them. Lazy-load them when they're below the fold. Never use display: none while still loading them.
  • Flow content around fixed-size units. Don't clip or scale them.
  • Never use document.write() or synchronous third-party scripts. Use async/defer.

8. Process

  • Prototype early and decide in the browser. A static comp is for exploring the look, not the final spec.
  • Review live across real browsers, at least Chromium, WebKit/Safari and Firefox, and on real devices where possible.

Checklist before done

  • Drag the viewport from 320px to wide. There's no horizontal scroll, no clipping, and nothing breaks at the seams.
  • Zoom to 200%, and test text-only zoom as well. Nothing overlaps or gets cut off. This is WCAG reflow.
  • The same content and actions are reachable at every width, and nothing is hidden just to fit.
  • Nav works by touch, mouse and keyboard alone, with visible focus. Escape closes menus.
  • Touch targets are at least 24px.
  • Hover-only effects are gated by (hover: hover), and prefers-reduced-motion is respected.
  • Every image and embed has dimensions or aspect-ratio, so there's no layout shift.
  • The hero image is not lazy-loaded, and the others are.
  • srcset/sizes or the framework image component is used.
  • It's usable on throttled "Slow 4G". Check Lighthouse or Core Web Vitals in devtools: LCP, CLS and INP.

Individual skills in this repo

This repo contains 2 individual skills — each has its own dedicated page.

相關技能