Working with Tailwind CSS in Hyvä

Where the Tailwind files live, the build commands, theme tokens and the habits that prevent classes from disappearing.

Working with Tailwind CSS in Hyvä – illustration

Every Hyvä theme carries its own Tailwind CSS setup. Understanding how it works makes styling faster and prevents the most common surprise in Hyvä projects: a class that works in development but vanishes in production.

This guide covers where the files live, how the build works, how to customise the design system and which habits keep your stylesheet complete and small.

Why Hyvä uses Tailwind

Tailwind is a utility-first framework. Instead of writing a custom class for every component, you compose small single-purpose classes, such as p-4, text-lg or rounded-xl, directly in the markup.

For a Magento theme this has two advantages. First, styles live next to the template they affect, so changing a component rarely means hunting through stylesheets. Second, the compiler includes only classes that are actually used, so the final CSS stays small no matter how large the theme grows.

Where the files live

Inside a theme, the Tailwind workspace sits in web/tailwind. It contains:

  • package.json, which lists the build tools and defines the npm scripts.
  • tailwind-source.css, the main entry point in Hyvä 1.4 and later.
  • Component and theme CSS files imported by the entry point.
  • A generated folder that build scripts fill with module sources and design tokens.

The compiled result is written to web/css/styles.css, which Magento then deploys like any other static file.

Tailwind v3 and v4

Since release 1.4.0, Hyvä uses Tailwind CSS v4. In v4, configuration moves out of JavaScript and into CSS, and the build runs through the Tailwind CLI rather than PostCSS. Release 1.4 also introduced design tokens and CSS components, which make it easier to change the theme's appearance without editing HTML.

Older releases use Tailwind v3 with a tailwind.config.js file. The concepts are the same, but the syntax differs, so check which version your theme contains before following any tutorial. Hyvä provides upgrade helper scripts for moving a theme from v3 to v4.

Build commands

cd app/design/frontend/Acme/storefront/web/tailwind
npm ci           # install the exact versions in package-lock.json
npm run watch    # rebuild automatically while you edit
npm run build    # minified build for deployment

Since Hyvä 1.4.0, npm start is an alias for npm run watch, and the older build-prod script has been removed. You can also run the scripts from elsewhere with npm --prefix path/to/web/tailwind run build, which is convenient in deployment pipelines.

How Tailwind finds your classes

Tailwind does not ship every possible class. It scans the files it has been told about and generates only the classes it finds there. In a Hyvä theme, those sources include your theme's templates, the parent theme's templates and any Hyva-compatible modules.

Two commands keep the module list current:

bin/magento hyva:config:generate
npm run generate   # Hyva 1.4+: runs hyva-sources and hyva-tokens

The first writes app/etc/hyva-themes.json, a list of installed modules that contain Hyvä templates. The second turns that list into CSS imports and generates token variables. In 1.4 the build script runs the generate step automatically before each build.

Customising colours, fonts and spacing

Brand colours, fonts and spacing belong in the theme's design tokens rather than scattered across templates. In a Tailwind v4 theme this is done with CSS variables inside an @theme block:

@theme {
  --color-primary: #E8112D;
  --color-secondary: #FCD116;
  --font-sans: "Poppins", sans-serif;
}

Utilities such as bg-primary, text-secondary and font-sans then follow the brand automatically. Changing one value updates every component that uses it.

Keep the token list short and meaningful. A palette of a primary colour, a secondary colour, a few neutrals and status colours for success, warning and error covers most stores.

Responsive design

Tailwind is mobile-first. An unprefixed class applies to all screen sizes, while prefixes such as md: and lg: apply from a breakpoint upwards. For example, grid-cols-2 md:grid-cols-4 shows two product columns on phones and four on larger screens.

Design for the smallest screen first, then add larger layouts. This matches how most shoppers arrive and keeps mobile styles simple.

Habits that prevent missing styles

  • Write class names in full. Building names from fragments, such as 'text-' . $colour, hides them from the scanner. Map values to complete class names instead.
  • Rebuild after adding modules. Run hyva:config:generate and the build again whenever a Hyva-compatible module is installed.
  • Use @apply sparingly. It is handy for repeated patterns, but heavy use recreates the large stylesheets Tailwind is meant to avoid.
  • Handle CMS content. Classes typed into CMS blocks are not in template files; the CMS Tailwind JIT module covers them.
  • Check your .gitignore. Tailwind v4 respects ignore files when scanning, so an overly broad ignore rule can hide templates from the compiler.

Deploying the stylesheet

After a production build, the updated web/css/styles.css must reach the server. Commit it to version control, or generate it in CI and include it in the release artefact. Then run Magento's static content deployment so the file is copied to pub/static, and flush the cache.

CSS components in Hyvä 1.4

Release 1.4 introduced CSS components: small, named styles for recurring elements such as buttons, form fields and cards. They are defined once in the Tailwind workspace and used across templates with a single class.

The advantage is that a design change, for example making all primary buttons rounder, can be made in one place without editing dozens of templates. This complements utility classes rather than replacing them: use components for repeated patterns and utilities for one-off layout.

Working with Hyvä UI components

Hyvä UI, a paid library, offers ready-made sections such as headers, menus, sliders and product cards. Each component is copied into your theme rather than installed as a dependency, so you own and can change the code. Because they are written in Tailwind and Alpine, they follow the same conventions as the default theme and slot in without extra tooling.

Debugging styles

When a style does not appear as expected, work through these checks in order:

  1. Is the watch process running, or has the production build been rerun?
  2. Does the class appear, written in full, in a file that Tailwind scans?
  3. Has the new stylesheet been deployed to pub/static and the cache flushed?
  4. Is another class with higher specificity or later order overriding it? Browser developer tools show which rule wins.
  5. Was the class renamed between Tailwind v3 and v4? A few utilities changed names.

Keeping the stylesheet lean

A Hyvä stylesheet typically stays small because only used classes are compiled. It can still grow if templates use many arbitrary values, such as mt-[13px], or if large CSS files are imported wholesale. Prefer the design scale, keep custom CSS focused, and review the compiled file size occasionally as part of routine maintenance.

Conclusion

Tailwind gives Hyvä themes a small stylesheet and a fast way to style components. Keep brand decisions in design tokens, run npm run build before every deployment, and write class names in full so the compiler can find them. With those habits in place, styling a Hyvä store becomes one of the quickest parts of the project.

Frequently Asked Questions

Hyvä 1.4.0 and later use Tailwind CSS v4. Earlier releases use Tailwind v3 with a tailwind.config.js file.

Usually because the class name is built dynamically or the file containing it is not scanned. Write the full class name and rebuild.

Yes. You can add custom CSS files to the Tailwind workspace. Utility classes are recommended for most styling, but plain CSS is fine where it is clearer.

During development, npm run watch rebuilds automatically. Before deployment, run npm run build once to produce the minified file.

Sources and Further Reading

Hyvä Editorial Team
Hyvä Editorial Team

We write practical guides on the Hyvä theme for Magento 2, checked against the official documentation and public repositories. How we research