Skip to content

Sass with Utility-First CSS

In modern projects, Sass and utility-first CSS often appear together.

This can feel redundant at first:

  • Sass already generates CSS
  • utility classes already encode design decisions

The key is understanding that they solve different problems.


Utility-first CSS focuses on:

  • composition at the markup level
  • consistent application of spacing, color, and layout
  • rapid iteration without writing new selectors

Sass focuses on:

  • authoring structure
  • data and generation
  • compile-time decision making

Used together, Sass supports the system, while utilities express intent in the HTML.


When using a utility-first approach, Sass is usually not responsible for:

  • recreating utility classes
  • generating one-to-one replacements for framework utilities
  • styling individual components that already compose cleanly with utilities

Duplicating utilities in Sass adds complexity without benefit.


Sass works well alongside utilities when it is used to:

  • define design tokens
  • generate CSS custom properties
  • create small, focused abstractions utilities can consume
  • organize non-utility styles (resets, base styles, layout primitives)

This keeps responsibilities clear and avoids overlap.


A common pattern is:

  1. Define tokens in Sass
  2. Generate CSS custom properties
  3. Consume those variables from utilities

For example:

$colors: (
primary: #3366ff,
surface: #ffffff,
text: #111111,
);
:root {
@each $name, $value in $colors {
--#{$name}: #{$value};
}
}

Utilities (or custom utilities) can then reference these variables rather than hard-coded values.


Utility-first CSS is about usage.

Sass is about authoring.

When those roles are respected, the two tools complement each other instead of competing.


Using Sass with utilities makes sense when:

  • the project has shared tokens or themes
  • generation or data structures reduce duplication
  • runtime flexibility is still required

It makes less sense when Sass is used only to recreate utilities that already exist.

Adding Tailwind CSS to a Vite project with Sass

Section titled “Adding Tailwind CSS to a Vite project with Sass”

We already have a Vite project compiling Sass (SCSS). Now we’re adding Tailwind on top of that same pipeline.


From the project root:

Terminal window
npm install -D tailwindcss postcss autoprefixer

Terminal window
npx tailwindcss init -p

That generates:

  • tailwind.config.js
  • postcss.config.js

Vite will automatically use PostCSS when it sees postcss.config.js.


Open tailwind.config.js and set content so Tailwind can “see” every place you use utility classes:

/** @type {import('tailwindcss').Config} */
export default {
content: ['./index.html', './src/**/*.{js,ts,jsx,tsx,vue,svelte,html}'],
theme: {
extend: {},
},
plugins: [],
};

If Tailwind classes aren’t showing up, this is the first place to look.


4) Add Tailwind directives to your main Sass file

Section titled “4) Add Tailwind directives to your main Sass file”

In your existing Sass entry file (example: src/styles/main.scss), put Tailwind at the top:

@tailwind base;
@tailwind components;
@tailwind utilities;
/* Your Sass can follow */
@use './partials/variables' as *;
@use './partials/mixins' as *;
/* Example: keep your custom styles below Tailwind */
body {
font-family: system-ui, sans-serif;
}

Notes:

  • Keep the @tailwind directives before any Sass that uses Tailwind features like @apply.
  • You can still use Sass partials/modules as usual.

In src/main.js (or src/main.ts), import your SCSS file:

import './styles/main.scss';

If you already import a CSS/SCSS file, just ensure it’s the one containing the Tailwind directives.


Terminal window
npm run dev

Then test quickly by dropping a Tailwind class into your markup, e.g. class="p-6 text-xl".


  • Nothing changes after adding Tailwind: restart the dev server.
  • Utilities don’t generate: your content globs are wrong (or your HTML/JS lives somewhere Tailwind isn’t scanning).
  • @apply errors: make sure Tailwind directives are loaded first, and you’re not trying to @apply arbitrary values that require enabling features/plugins.

📘 Sass and Tailwind CSS, United - Infographic


The last skill is judgment.

Next, we’ll look at when Sass genuinely helps a project — and when it’s better to leave it out entirely.