/symfony-ux-skills:ux-cssfrom symfony-ux-skills
Generates atomic CSS class names from design tokens in Twig templates using a css() function inspired by Panda CSS. Validates styles at compile time and writes CSS to a single file with zero Node.js tooling.
Ships in symfony-ux-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A css() Twig function inspired by Panda CSS: pass a hash of styles, get atomic class names built from your design tokens. The bundle writes the matching rules to one file, var/ux_css/styles.css. Styles are validated when Twig compiles the template, so a typo is a Twig error with the template line, also caught by lint:twig and cache:warmup. PHP writes the CSS, with zero Node.js tooling.
Since Symfony UX 3.7+. The package is experimental: its API may still change.
<div class="{{ css({ p: 'md', color: 'fg', _hover: { color: 'primary' }, md: { p: 'lg' } }) }}">
{# class="p_md c_fg hover:c_primary md:p_lg" #}
composer require symfony/ux-css
Flex registers UXCssBundle, creates config/packages/ux_css.yaml (with default_tokens: panda), and adds the import to your stylesheet:
/* assets/styles/app.css */
@layer reset, base, tokens, components, utilities;
@import '../../var/ux_css/styles.css';
/* your own styles */
Works with AssetMapper (the bundle registers var/ux_css/ under the ux_css prefix), Reprise and Encore. In debug mode the bundle also writes config/reference_css.php (editor types): commit it.
Requires PHP 8.4+, Symfony 7.4 or 8.x, TwigBundle, Twig 3.24+.
# config/packages/ux_css.yaml
ux_css:
default_tokens: panda # Panda palette, spacing 0-96, sizes, radii, fonts...
tokens:
colors:
brand: '#4f46e5'
bg: { DEFAULT: '#ffffff', muted: '#f9fafb' } # "bg" and "bg.muted"
spacing: { sm: '0.5rem', md: '1rem', lg: '2rem' }
sizes: { prose: '65ch' }
fonts:
body: ['Inter', 'sans-serif']
semantic_tokens:
colors:
primary: '{colors.blue.500}'
fg: { base: '{colors.gray.900}', _dark: '{colors.gray.50}' }
Your tokens add to (and override, path by path) the default ones. Every token becomes a CSS variable (--colors-primary, --spacing-md) usable in hand-written CSS. Each property takes one fixed category (from Panda): color/bg/borderColor take colors, p/m/gap/inset take spacing, w/h/maxW take sizes, rounded takes radii, shadow takes shadows, fontSize takes fontSizes... The full list is in references/reference.md.
{{ css({ color: 'primary' }) }} {# token #}
{{ css({ display: 'flex', zIndex: 10 }) }} {# keyword, number #}
{{ css({ w: '[37ch]', color: '[#ff6600]' }) }} {# raw value: square brackets #}
{{ css({ bg: 'primary/50' }) }} {# 50% opacity with color-mix() #}
{{ css({ mt: '-md' }) }} {# negative spacing #}
{{ css({ gap: 'var(--card-gap)' }) }} {# your own variable #}
{{ css({ color: 'primary!' }) }} {# !important #}
{{ css({ border: '1px solid token(colors.blue.500, gray)' }) }}
{{ css({ _before: { content: '""' } }) }} {# CSS strings must be complete #}
Shorthands: p px py pt pr pb pl, m mx my mt mr mb ml, w h minW maxW minH maxH, bg bgColor, rounded, shadow.
{# Condition: underscore prefix, a hash or a conditional value #}
{{ css({ color: 'fg', _hover: { color: 'primary' } }) }}
{{ css({ color: { base: 'fg', _hover: 'primary' } }) }}
{# Nested: hover:dark:bg_gray.900 #}
{{ css({ _hover: { _dark: { bg: 'gray.900' } } }) }}
{# Breakpoints, mobile-first: sm 640px, md 768px, lg 1024px, xl 1280px, 2xl 1536px #}
{{ css({ p: { base: 'sm', md: 'lg' } }) }}
{{ css({ p: ['sm', 'md', 'lg'] }) }} {# base, sm, md #}
{{ css({ display: { base: 'none', mdOnly: 'block' } }) }}
{# Selectors and at-rules #}
{{ css({ '& > li': { mt: 'sm' }, '@media print': { display: 'none' } }) }}
Common conditions: _hover, _focus, _focusVisible, _active, _disabled, _checked, _invalid, _expanded, _open, _placeholder, _before, _after, _first, _last, _even, _odd, _dark (.dark &), _light, _osDark, _motionReduce, _print, _groupHover, _peerFocus. Ranges per breakpoint: mdOnly, mdDown, smToLg.
Dark mode follows .dark on an ancestor by default; change it once:
ux_css:
conditions:
dark: '[data-theme=dark] &'
sidebarOpen: 'body.sidebar-open &' # use as _sidebarOpen
Values written in the template (including both branches of a ternary, or a {% set %} constant above the call) are resolved at compile time and free at render. Values from variables are resolved at render (microseconds), but their CSS only exists if the same style appears in a template or in static_css:
ux_css:
static_css:
css:
- properties:
color: [success, warning, danger]
conditions: [hover]
- properties:
padding: ['*']
responsive: true
In debug mode, a runtime class without CSS logs a warning on the ux_css channel (profiler Logs panel). Map user input to a known list before passing it to css().
The file writes @layer tokens, utilities; (reset first with preflight). Unlayered CSS beats layered CSS, so a Bootstrap or app rule outside any layer overrides a css() class. Put your own CSS in base / components layers declared before the import, as above.
APP_ENV=prod php bin/console cache:warmup # writes the compact CSS, fails on any invalid css()
php bin/console asset-map:compile # or: npm run build (after warmup)
In a multi-stage Docker build, copy var/ux_css/styles.css from the PHP stage before the Node build. For stylesheet imports and build order by asset pipeline, see bundlers and deployment.
Since Symfony UX 3.8+, cva() describes a component's variants with style hashes, like Panda CSS cva():
{# templates/components/Button.html.twig #}
{% props size = 'sm', visual = 'solid' %}
{% set button = cva(
base: { px: '3', py: '1', rounded: 'md' },
variants: {
size: { sm: { fontSize: 'sm' }, lg: { fontSize: 'lg', px: '5' } },
visual: { solid: { bg: 'primary', color: 'fg' }, outline: { borderWidth: '1px' } },
},
compoundVariants: [{ size: 'lg', visual: 'outline', css: { borderWidth: '2px' } }],
defaultVariants: { size: 'sm', visual: 'solid' },
) %}
<button {{ attributes.defaults({ class: button.apply({ size: size, visual: visual }) }) }}>
{% block content %}{% endblock %}
</button>
The config must be readable at compile time; the chosen variants can come from runtime props. Hashes merge before generating classes, so the last value of each property wins (lg gives px_5 alone). A caller can override per property with <twig:Button class="{{ css({ px: 'md' }) }}"> (requires symfony/ux-twig-component 3.8+).
Since Symfony UX 3.8+, css() returns a Symfony\UX\Css\CssClassList, printed as a string. Append an empty string wherever a plain string is required:
{{ html_classes(css({ p: 'md' }) ~ '', { active: isActive }) }}
{% if (css({ p: 'md' }) ~ '') starts with 'p_' %}...{% endif %}
html_classes() refuses the list, the variants of html_cva() silently drop it, and in / starts with tests fail on it: use cva() for variants, and ~ '' for the rest. A sandboxed template must allow CssClassList::__toString().
Tokens are the vocabulary. strict_tokens (default on) refuses non-token values; use [raw] deliberately, or add a token.
Write the styles in the template. Compile-time styles are free and always have CSS; runtime values need static_css.
One hash per call. css(a, b) merging is not supported; use a spread { ...base, p: 'md' }.
Not supported yet: recipes from the configuration, slot recipes (sva()), patterns (stack, grid), text/layer/animation styles, themes, keyframes, global CSS, custom utilities. For variants, write them with cva().
symfony/ux-css on Packagist.css() inside component templates; combine with attributes.defaults({class: css({...})}).What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub smnandre/symfony-ux-skills --plugin symfony-ux-skills20 skills in this plugin
/live-componentSymfony UX LiveComponent: live search, live filters, dependent selects and form validation as users type. Use for reactive PHP and Twig components, #[AsLiveComponent], LiveProp, LiveAction, data-model, loading states, emit/listen, lazy rendering and LiveResponse downloads./stimulusSymfony UX Stimulus: JavaScript behavior for dropdowns, tabs, modals, clipboard buttons and third-party widgets. Use for StimulusBundle, data-controller, data-action, targets, values, outlets, lazy controllers and Twig stimulus_* helpers./symfony-uxSymfony UX: choose and combine packages for a Symfony frontend. Use when deciding between Stimulus, Turbo, TwigComponent and LiveComponent, or fitting several Symfony UX packages into the same feature. Prefer the dedicated skill for a task that fits one package./turboSymfony UX Turbo: Turbo Frames for partial navigation and form submissions, Turbo Streams for multiple updates and Mercure broadcasts, and Turbo Drive for links and forms. Use for turbo-frame, turbo-stream, twig:Turbo, TurboFrame, TurboStreamResponse, turbo_stream_from and #[Broadcast]./twig-componentSymfony UX TwigComponent: reusable Twig buttons, cards, alerts and design system components. Use for twig: tags, #[AsTwigComponent], props, blocks, attributes.defaults(), anonymous components, computed properties, provide()/inject() and html_cva./ux-autocompleteSymfony UX Autocomplete: searchable selects and Ajax suggestions for large Symfony form lists. Use for EntityType, ChoiceType, Tom Select, the autocomplete option, #[AsEntityAutocompleteField], #[AsAutocompleteField], AutocompleterInterface, extra_options and tom_select_options.Other plugins' skills for the same job