Get the FREE Ultimate OpenClaw Setup Guide →

modern-css

Scanned
npx machina-cli add skill ccheney/robust-skills/modern-css --openclaw
Files (1)
SKILL.md
9.9 KB

Modern CSS

Pure native CSS for building interfaces — no preprocessors, no frameworks.

When to Use (and When NOT to)

Use Freely (Baseline)Feature-Detect First
CSS Grid, Subgrid, Flexbox@function, if() (Chrome-only)
Container Queries (size + style)Customizable <select> (Chrome-only)
:has(), :is(), :where()Scroll-state queries (Chrome-only)
CSS Nesting, @layer, @scopesibling-index(), sibling-count()
@property (typed custom props)::scroll-button(), ::scroll-marker
oklch(), color-mix(), light-dark()Typed attr() beyond content
Relative color syntaxfield-sizing: content
@starting-style, transition-behaviorinterpolate-size (Chrome-only)
Scroll-driven animationsGrid Lanes / masonry (experimental)
Anchor positioning, Popover APIrandom() (Safari TP only)
text-wrap: balance, linear() easing@mixin / @apply (no browser yet)
View Transitions, logical properties

CRITICAL: The Modern Cascade

Understanding how styles resolve is the single most important concept in CSS. The additions of @layer and @scope fundamentally changed the cascade algorithm.

Style Resolution Order (highest priority wins):
┌─────────────────────────────────────────────────┐
│ 1. Transitions (active transition wins)         │
│ 2. !important (user-agent > user > author)      │
│ 3. @layer order (later layer > earlier layer)   │
│ 4. Unlayered styles (beat ALL layers)           │
│ 5. Specificity (ID > class > element)           │
│ 6. @scope proximity (closer root wins)      NEW │
│ 7. Source order (later > earlier)               │
└─────────────────────────────────────────────────┘

Unlayered > Last layer > ... > First layer
           (utilities)        (reset)

Cascade layers (@layer) and scope proximity (@scope) are now more powerful than selector specificity. Define your layer order once (@layer reset, base, components, utilities;) and specificity wars disappear. Unlayered styles always beat layered styles — use this for overrides.

Quick Decision Trees

"How do I lay this out?"

Layout approach?
├─ 2D grid (rows + columns)         → CSS Grid
│  ├─ Children must align across    → Grid + Subgrid
│  └─ Waterfall / masonry           → grid-lanes (experimental)
├─ 1D row OR column                 → Flexbox
├─ Component adapts to container    → Container Query + Grid/Flex
├─ Viewport-based responsiveness    → @media range syntax
└─ Element sized to content         → fit-content / min-content / stretch

"How do I style this state?"

Style based on what?
├─ Child/descendant presence        → :has()
├─ Container size                   → @container (inline-size)
├─ Container custom property        → @container style()
├─ Scroll position (stuck/snapped)  → scroll-state() query
├─ Element's own custom property    → if(style(...))
├─ Browser feature support          → @supports
├─ User preference (motion/color)   → @media (prefers-*)
└─ Multiple selectors efficiently   → :is() / :where()

"How do I animate this?"

Animation type?
├─ Enter/appear on DOM              → @starting-style + transition
├─ Exit/disappear (display:none)    → transition-behavior: allow-discrete
├─ Animate to/from auto height      → interpolate-size: allow-keywords
├─ Scroll-linked (parallax/reveal)  → animation-timeline: scroll()/view()
├─ Page/view navigation             → View Transitions API
├─ Custom easing (bounce/spring)    → linear() function
└─ Always: respect user preference  → @media (prefers-reduced-motion)

What CSS Replaced JavaScript For

JavaScript PatternCSS Replacement
Scroll position listenersScroll-driven animations
IntersectionObserver for revealanimation-timeline: view()
Sticky header shadow togglescroll-state(stuck: top)
Floating UI / Popper.jsAnchor positioning
Carousel prev/next/dots::scroll-button(), ::scroll-marker
Auto-expanding textareafield-sizing: content
Staggered animation delayssibling-index()
max-height: 9999px hackinterpolate-size: allow-keywords
Parent element selection:has()
Theme toggle logiclight-dark() + color-scheme
Tooltip/popover show/hidePopover API + invoker commands
Color manipulation functionscolor-mix(), relative color syntax

For non-Baseline features, always feature-detect with @supports or use progressive enhancement. Check MDN or Baseline for current browser support.

Anti-Patterns (CRITICAL)

Anti-PatternProblemFix
Overusing !importantSpecificity arms raceUse @layer for cascade control
Deep nesting (.a .b .c .d)Fragile, DOM-coupledFlat selectors, @scope
IDs for styling (#header)Too specific to overrideClasses (.header)
@media for component layoutViewport-coupled, not reusableContainer queries
JS scroll listeners for effectsJanky, expensiveScroll-driven animations
JS for tooltip positioningFloating UI dependencyAnchor positioning
JS for carousel controlsFragile, a11y issues::scroll-button, ::scroll-marker
JS for auto-expanding textareaUnnecessary complexityfield-sizing: content
max-height: 9999px for animationWrong duration, jankyinterpolate-size: allow-keywords
margin-left / padding-rightBreaks in RTL/verticalLogical properties (margin-inline-start)
rgba() with commasLegacy syntaxrgb(r g b / a) space-separated
appearance: none on selectsRemoves ALL functionalityappearance: base-select
Preprocessor-only variablesCan't change at runtimeCSS custom properties
Preprocessor-only nestingExtra build step dependencyNative CSS nesting
Preprocessor color functionsCan't respond to contextcolor-mix(), relative colors
text-wrap: balance on paragraphsPerformance-heavyOnly headings/short text
content-visibility above foldDelays LCP renderingOnly off-screen sections
Overusing will-changeWastes GPU memoryApply only to animating elements

Reference Documentation

FilePurpose
references/CASCADE.mdNesting, @layer, @scope, cascade control, and CSS architecture
references/LAYOUT.mdGrid, Subgrid, Flexbox, Container Queries, and intrinsic sizing
references/SELECTORS.md:has(), :is(), :where(), pseudo-elements, and state-based selection
references/COLOR.mdOKLCH, color-mix(), relative colors, light-dark(), and theming
references/TOKENS.md@property, @function, if(), math functions, and design tokens
references/ANIMATION.md@starting-style, interpolate-size, linear(), view transitions
references/SCROLL.mdScroll-driven animations, scroll-state queries, native carousels
references/COMPONENTS.mdCustomizable <select>, popover, anchor positioning, field-sizing
references/PERFORMANCE.mdcontent-visibility, typography, logical properties, accessibility
references/CHEATSHEET.mdQuick reference: browser support, legacy→modern patterns, units

Sources

Official Specifications

Browser Vendor Blogs

Reference

Source

git clone https://github.com/ccheney/robust-skills/blob/main/skills/modern-css/SKILL.mdView on GitHub

Overview

Modern-css enables building design systems and component libraries using pure native CSS. It leverages grid, subgrid, container queries, :has(), cascade layers, and color tooling (oklch, color-mix) to create responsive, themed interfaces without preprocessors.

How This Skill Works

Styles are organized with cascade layers (@layer) and scope proximity (@scope) to control priority. It uses typed custom properties via @property, responsive layout with Grid/Flexbox and container queries, and color functions like oklch and color-mix to drive theming—all without a preprocessor.

When to Use It

  • Designing a design system or component library with CSS-only architecture
  • Implementing dark mode or theming using tokens, oklch, and color-mix
  • Building responsive components with CSS Grid, Subgrid, Flexbox, and container queries
  • Modernizing legacy stylesheets by applying @layer, @scope, cascade layers, and CSS architecture
  • Creating animations, transitions, and interactive UI (view transitions, scroll-driven animations, anchor positioning, popovers) with pure CSS

Quick Start

  1. Step 1: Define design tokens with @property and custom properties for colors, spacing, and typography
  2. Step 2: Structure layers using @layer reset, base, components, utilities and enable CSS nesting
  3. Step 3: Build components with Grid/Flexbox, container queries, and view transitions; test across browsers

Best Practices

  • Plan with cascade layers (reset, base, components, utilities) and define layer order once
  • Expose design tokens via @property for typed custom properties and better tooling
  • Prefer container queries and logical properties for robust, future-proof layouts
  • Use modern color functions (oklch, color-mix, light-dark) to enable accessible theming
  • Leverage CSS nesting and :has() where appropriate to simplify state-based styling

Example Use Cases

  • A design system built with @layer reset, base, components, utilities and token-driven theming
  • A responsive card grid that adapts using CSS Grid, Subgrid, and container queries
  • Dark mode implemented with oklch tokens and color-mix for smooth theming
  • A modal/popover wired with anchor positioning and :has() for interaction states
  • A customizable native select control styled with CSS nesting and modern properties

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers