{"slug":"ux-css","title":"ux-css","summary":"Symfony UX CSS: design tokens, atomic CSS and responsive styles in Twig. Use for hover states, dark mode, breakpoints, css(), cva(), Panda CSS syntax, semantic_tokens, preflight, static_css and the generated var/ux_css/styles.css.","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-12-02T16:48:37.951206Z","repo":{"url":"https://github.com/smnandre/symfony-ux-skills","stars":191,"forks":15,"license":"MIT","updatedAt":"2026-12-02T03:34:06Z"},"bodyHtml":"<hr>\n<h2>name: ux-css\ndescription: 'Symfony UX CSS: design tokens, atomic CSS and responsive styles in Twig. Use for hover states, dark mode, breakpoints, css(), cva(), Panda CSS syntax, semantic_tokens, preflight, static_css and the generated var/ux_css/styles.css.'\nlicense: MIT\nmetadata:\nauthor: Simon André\nurl: <a href=\"https://smnandre.dev\">https://smnandre.dev</a></h2>\n<h1>UX CSS</h1>\n<p>A <code>css()</code> 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, <code>var/ux_css/styles.css</code>. Styles are validated when Twig compiles the template, so a typo is a Twig error with the template line, also caught by <code>lint:twig</code> and <code>cache:warmup</code>. PHP writes the CSS, with zero Node.js tooling.</p>\n<p>Since Symfony UX 3.7+. The package is <strong>experimental</strong>: its API may still change.</p>\n<pre><code>&lt;div class=\"{{ css({ p: 'md', color: 'fg', _hover: { color: 'primary' }, md: { p: 'lg' } }) }}\"&gt;\n{# class=\"p_md c_fg hover:c_primary md:p_lg\" #}\n</code></pre>\n<h2>Installation</h2>\n<pre><code>composer require symfony/ux-css\n</code></pre>\n<p>Flex registers <code>UXCssBundle</code>, creates <code>config/packages/ux_css.yaml</code> (with <code>default_tokens: panda</code>), and adds the import to your stylesheet:</p>\n<pre><code>/* assets/styles/app.css */\n@layer reset, base, tokens, components, utilities;\n@import '../../var/ux_css/styles.css';\n/* your own styles */\n</code></pre>\n<p>Works with AssetMapper (the bundle registers <code>var/ux_css/</code> under the <code>ux_css</code> prefix), Reprise and Encore. In debug mode the bundle also writes <code>config/reference_css.php</code> (editor types): commit it.</p>\n<p>Requires PHP 8.4+, Symfony 7.4 or 8.x, TwigBundle, Twig 3.24+.</p>\n<h2>Tokens</h2>\n<pre><code># config/packages/ux_css.yaml\nux_css:\n    default_tokens: panda          # Panda palette, spacing 0-96, sizes, radii, fonts...\n    tokens:\n        colors:\n            brand: '#4f46e5'\n            bg: { DEFAULT: '#ffffff', muted: '#f9fafb' }   # \"bg\" and \"bg.muted\"\n        spacing: { sm: '0.5rem', md: '1rem', lg: '2rem' }\n        sizes: { prose: '65ch' }\n        fonts:\n            body: ['Inter', 'sans-serif']\n    semantic_tokens:\n        colors:\n            primary: '{colors.blue.500}'\n            fg: { base: '{colors.gray.900}', _dark: '{colors.gray.50}' }\n</code></pre>\n<p>Your tokens add to (and override, path by path) the default ones. Every token becomes a CSS variable (<code>--colors-primary</code>, <code>--spacing-md</code>) usable in hand-written CSS. Each property takes one fixed category (from Panda): <code>color</code>/<code>bg</code>/<code>borderColor</code> take <code>colors</code>, <code>p</code>/<code>m</code>/<code>gap</code>/<code>inset</code> take <code>spacing</code>, <code>w</code>/<code>h</code>/<code>maxW</code> take <code>sizes</code>, <code>rounded</code> takes <code>radii</code>, <code>shadow</code> takes <code>shadows</code>, <code>fontSize</code> takes <code>fontSizes</code>... The full list is in <a href=\"references/reference.md\">references/reference.md</a>.</p>\n<h2>Values</h2>\n<pre><code>{{ css({ color: 'primary' }) }}                 {# token #}\n{{ css({ display: 'flex', zIndex: 10 }) }}      {# keyword, number #}\n{{ css({ w: '[37ch]', color: '[#ff6600]' }) }}  {# raw value: square brackets #}\n{{ css({ bg: 'primary/50' }) }}                 {# 50% opacity with color-mix() #}\n{{ css({ mt: '-md' }) }}                        {# negative spacing #}\n{{ css({ gap: 'var(--card-gap)' }) }}           {# your own variable #}\n{{ css({ color: 'primary!' }) }}                {# !important #}\n{{ css({ border: '1px solid token(colors.blue.500, gray)' }) }}\n{{ css({ _before: { content: '\"\"' } }) }}       {# CSS strings must be complete #}\n</code></pre>\n<p>Shorthands: <code>p px py pt pr pb pl</code>, <code>m mx my mt mr mb ml</code>, <code>w h minW maxW minH maxH</code>, <code>bg bgColor</code>, <code>rounded</code>, <code>shadow</code>.</p>\n<h2>Conditions and Breakpoints</h2>\n<pre><code>{# Condition: underscore prefix, a hash or a conditional value #}\n{{ css({ color: 'fg', _hover: { color: 'primary' } }) }}\n{{ css({ color: { base: 'fg', _hover: 'primary' } }) }}\n\n{# Nested: hover:dark:bg_gray.900 #}\n{{ css({ _hover: { _dark: { bg: 'gray.900' } } }) }}\n\n{# Breakpoints, mobile-first: sm 640px, md 768px, lg 1024px, xl 1280px, 2xl 1536px #}\n{{ css({ p: { base: 'sm', md: 'lg' } }) }}\n{{ css({ p: ['sm', 'md', 'lg'] }) }}            {# base, sm, md #}\n{{ css({ display: { base: 'none', mdOnly: 'block' } }) }}\n\n{# Selectors and at-rules #}\n{{ css({ '&amp; &gt; li': { mt: 'sm' }, '@media print': { display: 'none' } }) }}\n</code></pre>\n<p>Common conditions: <code>_hover</code>, <code>_focus</code>, <code>_focusVisible</code>, <code>_active</code>, <code>_disabled</code>, <code>_checked</code>, <code>_invalid</code>, <code>_expanded</code>, <code>_open</code>, <code>_placeholder</code>, <code>_before</code>, <code>_after</code>, <code>_first</code>, <code>_last</code>, <code>_even</code>, <code>_odd</code>, <code>_dark</code> (<code>.dark &amp;</code>), <code>_light</code>, <code>_osDark</code>, <code>_motionReduce</code>, <code>_print</code>, <code>_groupHover</code>, <code>_peerFocus</code>. Ranges per breakpoint: <code>mdOnly</code>, <code>mdDown</code>, <code>smToLg</code>.</p>\n<p>Dark mode follows <code>.dark</code> on an ancestor by default; change it once:</p>\n<pre><code>ux_css:\n    conditions:\n        dark: '[data-theme=dark] &amp;'\n        sidebarOpen: 'body.sidebar-open &amp;'     # use as _sidebarOpen\n</code></pre>\n<h2>Runtime Values</h2>\n<p>Values written in the template (including both branches of a ternary, or a <code>{% set %}</code> constant above the call) are resolved at compile time and free at render. Values from variables are resolved at render (microseconds), but <strong>their CSS only exists if the same style appears in a template or in <code>static_css</code></strong>:</p>\n<pre><code>ux_css:\n    static_css:\n        css:\n            - properties:\n                  color: [success, warning, danger]\n              conditions: [hover]\n            - properties:\n                  padding: ['*']\n              responsive: true\n</code></pre>\n<p>In debug mode, a runtime class without CSS logs a warning on the <code>ux_css</code> channel (profiler Logs panel). Map user input to a known list before passing it to <code>css()</code>.</p>\n<h2>Cascade Layers</h2>\n<p>The file writes <code>@layer tokens, utilities;</code> (<code>reset</code> first with <code>preflight</code>). Unlayered CSS beats layered CSS, so a Bootstrap or app rule outside any layer overrides a <code>css()</code> class. Put your own CSS in <code>base</code> / <code>components</code> layers declared before the import, as above.</p>\n<h2>Production</h2>\n<pre><code>APP_ENV=prod php bin/console cache:warmup    # writes the compact CSS, fails on any invalid css()\nphp bin/console asset-map:compile            # or: npm run build (after warmup)\n</code></pre>\n<p>In a multi-stage Docker build, copy <code>var/ux_css/styles.css</code> from the PHP stage before the Node build. For stylesheet imports and build order by asset pipeline, see <a href=\"references/reference.md#bundlers-and-deployment\">bundlers and deployment</a>.</p>\n<h2>Variants with cva()</h2>\n<p>Since Symfony UX 3.8+, <code>cva()</code> describes a component's variants with style hashes, like Panda CSS <code>cva()</code>:</p>\n<pre><code>{# templates/components/Button.html.twig #}\n{% props size = 'sm', visual = 'solid' %}\n\n{% set button = cva(\n    base: { px: '3', py: '1', rounded: 'md' },\n    variants: {\n        size: { sm: { fontSize: 'sm' }, lg: { fontSize: 'lg', px: '5' } },\n        visual: { solid: { bg: 'primary', color: 'fg' }, outline: { borderWidth: '1px' } },\n    },\n    compoundVariants: [{ size: 'lg', visual: 'outline', css: { borderWidth: '2px' } }],\n    defaultVariants: { size: 'sm', visual: 'solid' },\n) %}\n\n&lt;button {{ attributes.defaults({ class: button.apply({ size: size, visual: visual }) }) }}&gt;\n    {% block content %}{% endblock %}\n&lt;/button&gt;\n</code></pre>\n<p>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 (<code>lg</code> gives <code>px_5</code> alone). A caller can override per property with <code>&lt;twig:Button class=\"{{ css({ px: 'md' }) }}\"&gt;</code> (requires <code>symfony/ux-twig-component</code> 3.8+).</p>\n<h2>css() Returns a Class List</h2>\n<p>Since Symfony UX 3.8+, <code>css()</code> returns a <code>Symfony\\UX\\Css\\CssClassList</code>, printed as a string. Append an empty string wherever a plain string is required:</p>\n<pre><code>{{ html_classes(css({ p: 'md' }) ~ '', { active: isActive }) }}\n{% if (css({ p: 'md' }) ~ '') starts with 'p_' %}...{% endif %}\n</code></pre>\n<p><code>html_classes()</code> refuses the list, the <code>variants</code> of <code>html_cva()</code> silently drop it, and <code>in</code> / <code>starts with</code> tests fail on it: use <code>cva()</code> for variants, and <code>~ ''</code> for the rest. A sandboxed template must allow <code>CssClassList::__toString()</code>.</p>\n<h2>Key Principles</h2>\n<p><strong>Tokens are the vocabulary.</strong> <code>strict_tokens</code> (default on) refuses non-token values; use <code>[raw]</code> deliberately, or add a token.</p>\n<p><strong>Write the styles in the template.</strong> Compile-time styles are free and always have CSS; runtime values need <code>static_css</code>.</p>\n<p><strong>One hash per call.</strong> <code>css(a, b)</code> merging is not supported; use a spread <code>{ ...base, p: 'md' }</code>.</p>\n<p><strong>Not supported yet</strong>: recipes from the configuration, slot recipes (<code>sva()</code>), patterns (<code>stack</code>, <code>grid</code>), text/layer/animation styles, themes, keyframes, global CSS, custom utilities. For variants, write them with <code>cva()</code>.</p>\n<h2>References</h2>\n<ul>\n<li><a href=\"https://ux.symfony.com/css\">Symfony UX package page</a> (<a href=\"https://ux.symfony.com/css.md\">Markdown summary</a>) · <a href=\"https://packagist.org/packages/symfony/ux-css\"><code>symfony/ux-css</code> on Packagist</a>.</li>\n<li>Try the <a href=\"https://ux.symfony.com/css#demo\">interactive design tokens and styles demo</a>.</li>\n<li>For design tokens, writing styles and deployment, see the <a href=\"https://symfony.com/bundles/ux-css\">Symfony UX CSS documentation</a>.</li>\n<li><strong>Reference</strong> (property categories, configuration, validation messages, editors, Panda differences): <a href=\"references/reference.md\">references/reference.md</a></li>\n</ul>\n<h2>See Also</h2>\n<ul>\n<li><strong>twig-component</strong>: call <code>css()</code> inside component templates; combine with <code>attributes.defaults({class: css({...})})</code>.</li>\n<li><strong>live-component</strong>: every template is scanned, so classes in components rendered later already have CSS.</li>\n</ul>\n","files":[{"path":"references/reference.md","sizeBytes":10437,"isText":true},{"path":"SKILL.md","sizeBytes":9292,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-12-02T16:49:25.119338Z","sha256":"7633A65A201BEBECD95D273386D1744CA0F43223C61A00EED4FBDF38A8010D6F","sizeBytes":8574},"review":null,"source":{"repositoryUrl":"https://github.com/smnandre/symfony-ux-skills","path":"skills/ux-css","license":"MIT","commit":"78c25ed0b79bcc21d7611002dc81d8b87c3316e2","subtreeSha":"BD0BC1AEBF2C2E977D91803DE8056420DDE381241AD549623398A009AF4CE52F","lastSyncedAt":"2026-12-02T16:48:36.132977Z"},"reviewedAt":"2026-12-02T16:50:54.68373Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/smnandre/symfony-ux-skills/tree/main/skills/ux-css"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install smnandre-symfony-ux-skills@llmmart"},{"target":"git","command":"git clone https://github.com/smnandre/symfony-ux-skills.git"}]}