UB CSS
Overview
Apply modern CSS platform features with predictable cascade control, token-driven styling, and progressive enhancement. Treat design tokens as a system contract, keep selectors and specificity maintainable, and prefer native CSS features over legacy Sass-era workarounds.
Load References On Demand
- Read
../ub-authoring/references/authoring-conventions.md when adjusting routing
guidance or cross-skill authoring conventions.
- Read
references/modern-css-source.md for copy-ready patterns and framework bridges (Vue/Nuxt/Quasar/Tailwind).
- Read
references/browser-support-baseline.md when deciding fallback policy or feature gating.
When Not To Use
- Do not use this skill when Tailwind utility workflow, Tailwind setup, or
Tailwind migration is the primary change surface; co-load or defer to
ub-tailwind depending on whether CSS architecture remains a first-class
concern.
- Do not use this skill when the main problem is Nuxt runtime behavior, app
structure, or Nitro/server concerns; defer that to
ub-nuxt.
- Do not use this skill for general Vue component logic when CSS is secondary
to component architecture.
Core Workflow
- Confirm token source of truth (DTCG JSON or existing token registry).
- Map tokens to runtime CSS custom properties and semantic aliases.
- Define cascade order with
@layer and isolate vendor CSS in a vendor layer.
- Implement component styles with native nesting, modern selectors, and container queries.
- Add fluid sizing, logical properties, and modern color/theming primitives.
- Gate partial-support features with
@supports and explicit fallback behavior.
- Review accessibility, motion preferences, and performance-oriented CSS features.
Modern CSS Rules
1. Use Design Tokens As The Source Of Truth (DTCG-First)
- Prefer DTCG token format for canonical token data (
$value, $type, $description, alias references).
- Map canonical tokens to CSS custom properties in global and semantic scopes.
- Keep semantic token names stable; allow value churn behind them.
- Avoid hard-coded values in components unless a one-off value is intentional and documented.
{
"color": {
"brand": {
"primary": { "$type": "color", "$value": "oklch(62% 0.2 256)" }
},
"surface": {
"default": { "$type": "color", "$value": "#ffffff" }
}
}
}
:root {
--color-brand-primary : oklch(62% 0.2 256);
--color-surface-default : #ffffff;
--space-4 : 1rem;
--radius-md : 0.5rem;
}
2. Bridge Tokens Into Framework CSS Pipelines
- Vue/Nuxt/Quasar: consume CSS vars directly in SFC style blocks; use
v-bind() only for component-reactive values.
- Tailwind (latest stable): keep tokens in
@theme and align naming with CSS vars so utilities and raw CSS share the same source values.
- Keep token mapping deterministic so design, app CSS, and utility classes stay synchronized.
@theme {
--color-brand-primary : oklch(62% 0.2 256);
--spacing-4 : 1rem;
--radius-md : 0.5rem;
}
3. Control Cascade Predictably With @layer
- Declare global layer order once.
- Import third-party CSS into a dedicated vendor layer.
- Use layers to avoid specificity escalation.
@layer reset, vendor, tokens, base, components, utilities, overrides;
@import url("vendor.css") layer(vendor);
4. Use Native Nesting, But Keep It Shallow
- Use native nesting for state selectors, local descendants, and colocated queries.
- Keep depth at
<= 3 levels.
- Avoid deep DOM-coupled selectors.
5. Use Container Queries For Component Responsiveness
- Set
container: <name> / inline-size (or container-type + container-name) at component boundaries.
- Prefer container queries for component internals; keep viewport media queries for page shell layout.
- Use container query units (
cqw, cqh, cqi, cqmin, cqmax) when sizing should track container width/height.
6. Use Modern Selectors Deliberately
- Use
:has() for parent/state-driven styling where it simplifies markup/JS.
- Use
:is() to group selector variants with normal specificity.
- Use
:where() for zero-specificity defaults.
- Always include accessible keyboard focus states with
:focus-visible.
7. Prefer Modern Layout, Sizing, and Internationalization Primitives
- Use Grid/Flex with
gap instead of margin-based spacing hacks.
- Use
clamp(), min(), max(), and calc() for fluid sizing.
- Prefer logical properties (
padding-inline, border-inline-start, inset-block) over physical left/right properties.
- Use
aspect-ratio instead of padding-box ratio hacks.
8. Use Modern Color and Theming Primitives
- Prefer perceptual color spaces (
oklch) for token values.
- Derive variants with
color-mix() instead of manually duplicating palettes.
- Use
color-scheme and light-dark() when dual-theme behavior is needed.
- Treat
accent-color as enhancement, not correctness-critical styling.
9. Handle Motion, Interaction, and Performance Intentionally
- Respect user preferences (
prefers-reduced-motion, contrast and forced-color modes where relevant).
- Use
@starting-style, transition-behavior: allow-discrete, and popover hooks as enhancement patterns.
- Use
content-visibility and containment for long lists and heavy offscreen content.
- Use
scrollbar-gutter: stable to reduce layout shift during scrollbar appearance.
Progressive Enhancement Policy (Tiered Modern-First)
- Safe default: use broadly supported modern features by default.
- Enhancement tier: require
@supports guard plus acceptable fallback behavior.
- Limited/experimental tier: use only with explicit justification and easy rollback.
Documentation, Organization, And Formatting
Organization
- Split styles by role when codebase size justifies it:
styles/tokens.css
styles/base.css
styles/components/*.css
styles/utilities.css
- Keep component styles close to components when practical.
- Centralize global token definitions to reduce drift.
Documentation
- Add short comments for non-obvious intent, fallback rationale, or compatibility constraints.
- Document why partial-support features are used.
- Keep comments focused on
why, not what.
Formatting
- Keep property ordering logical:
- Layout (
display, position, grid/flex, z-index)
- Box model (
inline-size/block-size, margin, padding, border)
- Typography (
font-*, line-height, text-*)
- Visual (
background, color, box-shadow, opacity, filter)
- Motion (
transform, transition, animation)
- Use consistent spacing and alignment.
- Prefer small, single-purpose selector blocks.
Completion Checklist
- Token model is defined and mapped cleanly into CSS custom properties.
- Hard-coded values are minimized and justified when present.
- Layer order is explicit and vendor CSS is isolated.
- Nesting is shallow and readable.
- Container queries and modern selectors are used where they simplify code.
- Accessibility states include
:focus-visible and motion preferences are respected.
- Enhancement and limited features are gated with fallbacks.
- Comments are concise and intent-focused.
Version & Research Policy
- Use web search to verify current browser support data before recommending or gating CSS features.
- Inspect the host repository's
AGENTS.md or equivalent instructions when
present for project-specific version policy and tooling; do not assume it
contains this catalog's defaults.
- Do not hardcode snapshot dates or version numbers in generated guidance — keep recommendations evergreen.
Output Requirements
When generating or reviewing CSS guidance, include:
- Token note: source of truth for tokens and how they map into runtime CSS.
- Cascade note: layer order and selector-specificity strategy.
- Enhancement note: which features are baseline versus gated by
@supports.
- Accessibility note: focus, motion, contrast, and forced-color considerations.
- Validation note: lint, build, browser-support, or manual verification steps actually used.
1---2name: ub-css3description: Use this skill for plain CSS and style-block architecture. Apply it when the task involves .css files, selectors, specificity, cascade layers, tokens, layout or theming, accessibility styling, browser-support fallbacks, or CSS architecture in Vue, Nuxt, or Tailwind-bearing projects.4---5
6# UB CSS
7
8## Overview
9
10Apply modern CSS platform features with predictable cascade control, token-driven styling, and progressive enhancement. Treat design tokens as a system contract, keep selectors and specificity maintainable, and prefer native CSS features over legacy Sass-era workarounds.
11
12## Load References On Demand
13
14- Read `../ub-authoring/references/authoring-conventions.md` when adjusting routing
15 guidance or cross-skill authoring conventions.
16- Read `references/modern-css-source.md` for copy-ready patterns and framework bridges (Vue/Nuxt/Quasar/Tailwind).
17- Read `references/browser-support-baseline.md` when deciding fallback policy or feature gating.
18
19## When Not To Use
20
21- Do not use this skill when Tailwind utility workflow, Tailwind setup, or
22 Tailwind migration is the primary change surface; co-load or defer to
23 `ub-tailwind` depending on whether CSS architecture remains a first-class
24 concern.
25- Do not use this skill when the main problem is Nuxt runtime behavior, app
26 structure, or Nitro/server concerns; defer that to `ub-nuxt`.
27- Do not use this skill for general Vue component logic when CSS is secondary
28 to component architecture.
29
30## Core Workflow
31
321. Confirm token source of truth (DTCG JSON or existing token registry).
332. Map tokens to runtime CSS custom properties and semantic aliases.
343. Define cascade order with `@layer` and isolate vendor CSS in a vendor layer.
354. Implement component styles with native nesting, modern selectors, and container queries.
365. Add fluid sizing, logical properties, and modern color/theming primitives.
376. Gate partial-support features with `@supports` and explicit fallback behavior.
387. Review accessibility, motion preferences, and performance-oriented CSS features.
39
40## Modern CSS Rules
41
42### 1. Use Design Tokens As The Source Of Truth (DTCG-First)
43
44- Prefer DTCG token format for canonical token data (`$value`, `$type`, `$description`, alias references).
45- Map canonical tokens to CSS custom properties in global and semantic scopes.
46- Keep semantic token names stable; allow value churn behind them.
47- Avoid hard-coded values in components unless a one-off value is intentional and documented.
48
49```json
50{
51 "color": {
52 "brand": {
53 "primary": { "$type": "color", "$value": "oklch(62% 0.2 256)" }
54 },
55 "surface": {
56 "default": { "$type": "color", "$value": "#ffffff" }
57 }
58 }
59}
60```
61
62```css
63:root {
64 --color-brand-primary : oklch(62% 0.2 256);
65 --color-surface-default : #ffffff;
66 --space-4 : 1rem;
67 --radius-md : 0.5rem;
68}
69```
70
71### 2. Bridge Tokens Into Framework CSS Pipelines
72
73- Vue/Nuxt/Quasar: consume CSS vars directly in SFC style blocks; use `v-bind()` only for component-reactive values.
74- Tailwind (latest stable): keep tokens in `@theme` and align naming with CSS vars so utilities and raw CSS share the same source values.
75- Keep token mapping deterministic so design, app CSS, and utility classes stay synchronized.
76
77```css
78@theme {
79 --color-brand-primary : oklch(62% 0.2 256);
80 --spacing-4 : 1rem;
81 --radius-md : 0.5rem;
82}
83```
84
85### 3. Control Cascade Predictably With `@layer`
86
87- Declare global layer order once.
88- Import third-party CSS into a dedicated vendor layer.
89- Use layers to avoid specificity escalation.
90
91```css
92@layer reset, vendor, tokens, base, components, utilities, overrides;
93@import url("vendor.css") layer(vendor);
94```
95
96### 4. Use Native Nesting, But Keep It Shallow
97
98- Use native nesting for state selectors, local descendants, and colocated queries.
99- Keep depth at `<= 3` levels.
100- Avoid deep DOM-coupled selectors.
101
102### 5. Use Container Queries For Component Responsiveness
103
104- Set `container: <name> / inline-size` (or `container-type` + `container-name`) at component boundaries.
105- Prefer container queries for component internals; keep viewport media queries for page shell layout.
106- Use container query units (`cqw`, `cqh`, `cqi`, `cqmin`, `cqmax`) when sizing should track container width/height.
107
108### 6. Use Modern Selectors Deliberately
109
110- Use `:has()` for parent/state-driven styling where it simplifies markup/JS.
111- Use `:is()` to group selector variants with normal specificity.
112- Use `:where()` for zero-specificity defaults.
113- Always include accessible keyboard focus states with `:focus-visible`.
114
115### 7. Prefer Modern Layout, Sizing, and Internationalization Primitives
116
117- Use Grid/Flex with `gap` instead of margin-based spacing hacks.
118- Use `clamp()`, `min()`, `max()`, and `calc()` for fluid sizing.
119- Prefer logical properties (`padding-inline`, `border-inline-start`, `inset-block`) over physical left/right properties.
120- Use `aspect-ratio` instead of padding-box ratio hacks.
121
122### 8. Use Modern Color and Theming Primitives
123
124- Prefer perceptual color spaces (`oklch`) for token values.
125- Derive variants with `color-mix()` instead of manually duplicating palettes.
126- Use `color-scheme` and `light-dark()` when dual-theme behavior is needed.
127- Treat `accent-color` as enhancement, not correctness-critical styling.
128
129### 9. Handle Motion, Interaction, and Performance Intentionally
130
131- Respect user preferences (`prefers-reduced-motion`, contrast and forced-color modes where relevant).
132- Use `@starting-style`, `transition-behavior: allow-discrete`, and popover hooks as enhancement patterns.
133- Use `content-visibility` and containment for long lists and heavy offscreen content.
134- Use `scrollbar-gutter: stable` to reduce layout shift during scrollbar appearance.
135
136## Progressive Enhancement Policy (Tiered Modern-First)
137
138- Safe default: use broadly supported modern features by default.
139- Enhancement tier: require `@supports` guard plus acceptable fallback behavior.
140- Limited/experimental tier: use only with explicit justification and easy rollback.
141
142## Documentation, Organization, And Formatting
143
144### Organization
145
146- Split styles by role when codebase size justifies it:
147 - `styles/tokens.css`
148 - `styles/base.css`
149 - `styles/components/*.css`
150 - `styles/utilities.css`
151- Keep component styles close to components when practical.
152- Centralize global token definitions to reduce drift.
153
154### Documentation
155
156- Add short comments for non-obvious intent, fallback rationale, or compatibility constraints.
157- Document why partial-support features are used.
158- Keep comments focused on `why`, not `what`.
159
160### Formatting
161
162- Keep property ordering logical:
163 1. Layout (`display`, `position`, grid/flex, `z-index`)
164 2. Box model (`inline-size/block-size`, `margin`, `padding`, `border`)
165 3. Typography (`font-*`, `line-height`, `text-*`)
166 4. Visual (`background`, `color`, `box-shadow`, `opacity`, `filter`)
167 5. Motion (`transform`, `transition`, `animation`)
168- Use consistent spacing and alignment.
169- Prefer small, single-purpose selector blocks.
170
171## Completion Checklist
172
173- Token model is defined and mapped cleanly into CSS custom properties.
174- Hard-coded values are minimized and justified when present.
175- Layer order is explicit and vendor CSS is isolated.
176- Nesting is shallow and readable.
177- Container queries and modern selectors are used where they simplify code.
178- Accessibility states include `:focus-visible` and motion preferences are respected.
179- Enhancement and limited features are gated with fallbacks.
180- Comments are concise and intent-focused.
181
182## Version & Research Policy
183
184- Use web search to verify current browser support data before recommending or gating CSS features.
185- Inspect the host repository's `AGENTS.md` or equivalent instructions when
186 present for project-specific version policy and tooling; do not assume it
187 contains this catalog's defaults.
188- Do not hardcode snapshot dates or version numbers in generated guidance — keep recommendations evergreen.
189
190## Output Requirements
191
192When generating or reviewing CSS guidance, include:
193
1941. Token note: source of truth for tokens and how they map into runtime CSS.
1952. Cascade note: layer order and selector-specificity strategy.
1963. Enhancement note: which features are baseline versus gated by `@supports`.
1974. Accessibility note: focus, motion, contrast, and forced-color considerations.
1985. Validation note: lint, build, browser-support, or manual verification steps actually used.