DEV Community

Cover image for How to Use FSCSS with React.js and Next.js
FSCSS tutorial for FSCSS tutorial

Posted on • Edited on

How to Use FSCSS with React.js and Next.js

FSCSS (Figured Shorthand Cascading Style Sheet) is a next-generation CSS preprocessor that simplifies and accelerates styling workflows. It allows you to write compact, functional, and dynamic styles with built-in logic — and it compiles directly to plain CSS.

In this guide, you'll learn how to use FSCSS efficiently in React.js and Next.js projects.


Using FSCSS as a Build Tool (Recommended)

This approach compiles .fscss files into .css before running your React or Next.js app.

Install FSCSS globally

npm install -g fscss
Enter fullscreen mode Exit fullscreen mode

Create your FSCSS file

Create a file in your src/ directory named style.fscss:

$primary: teal;
$accent: #069069;
.button {
  background: $primary!;
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  &:hover {
    background: $accent!;
  }
}
Enter fullscreen mode Exit fullscreen mode

Compile FSCSS into CSS

fscss src/style.fscss src/style.css
Enter fullscreen mode Exit fullscreen mode

This converts your shorthand FSCSS code into normal CSS that React or Next.js can understand.

Import in your component

import "./style.css";

export default function App() {
  return <button className="button">Click Me</button>;
}
Enter fullscreen mode Exit fullscreen mode

Done! Your FSCSS is now compiled and ready for use in your app.


Option 2: Using FSCSS via CDN (Runtime Mode)

If you don't want a build step, you can use the FSCSS runtime compiler via CDN.

Add this to your index.html (React) or _document.js (Next.js):

<script src="https://cdn.jsdelivr.net/npm/fscss@1.1.7/exec.min.js" defer></script>
<style>@import(exec(styles/style.fscss))</style>
Enter fullscreen mode Exit fullscreen mode

This lets FSCSS compile styles dynamically in the browser — perfect for prototypes or dynamic theming.


Option 3: Use FSCSS in Node.js during SSR (Next.js)

You can also process FSCSS on the server side for Next.js static generation or SSR.

Install locally:

npm install fscss
Enter fullscreen mode Exit fullscreen mode

Then, use it in your Next.js config or a pre-build script:

// scripts/build-css.js
import { readFileSync, writeFileSync } from "fs";
import { processFscss } from "fscss";

const input = readFileSync("src/style.fscss", "utf-8");
const output = await processFscss(input);
writeFileSync("public/style.css", output);

console.log("✅ FSCSS compiled successfully!");
Enter fullscreen mode Exit fullscreen mode

Then, in your _app.js:

import "../public/style.css";
Enter fullscreen mode Exit fullscreen mode

Why Use FSCSS in React/Next?

  • Lightweight preprocessor (no setup)
  • Fast compilation (CLI or CDN-based)
  • Works in both frontend and backend
  • Great for prototyping, design systems, and theme-based UIs

Top comments (0)