Customization

Styling

Get started with styling your app.

To build the user web interface TurboStarter comes with Tailwind CSS and Radix UI pre-configured.

Why Tailwind CSS and Radix UI?

The combination of Tailwind CSS and Radix UI gives ready-to-use, accessible UI components that can be fully customized to match your brands design.

Tailwind config

In the tooling/tailwind/config directory you will find shared Tailwind CSS configuration files. To change some global styles you can edit the files in this folder.

Here is an example of a shared Tailwind config file:

tooling/tailwind/config/base.ts
import type { Config } from "tailwindcss";
 
export default {
  darkMode: "class",
  content: ["src/**/*.{ts,tsx}"],
  theme: {
    extend: {
      colors: {
        ...
        primary: {
          DEFAULT: "hsl(var(--primary))",
          foreground: "hsl(var(--primary-foreground))",
        },
        secondary: {
          DEFAULT: "hsl(var(--secondary))",
          foreground: "hsl(var(--secondary-foreground))",
        },
        success: {
          DEFAULT: "hsl(var(--success))",
          foreground: "hsl(var(--success-foreground))",
        },
        ...
      },
    },
  },
  plugins: [animate, containerQueries, typography],
} satisfies Config;

As you can see, for the colors part, we bet stricly on CSS Variables in HSL format to allow for easy theme management without a need for any JavaScript.

Also, each app has its own tailwind.config.ts file which extends the shared config and allows you to override the global styles.

Here is an example of a app's tailwind.config.ts file:

apps/web/tailwind.config.ts
import type { Config } from "tailwindcss";
import { fontFamily } from "tailwindcss/defaultTheme";
 
import baseConfig from "@turbostarter/tailwind-config/web";
 
export default {
  // We need to append the path to the UI package to the content array so that
  // those classes are included correctly.
  content: [...baseConfig.content, "../../packages/ui/**/*.{ts,tsx}"],
  presets: [baseConfig],
  theme: {
    extend: {
      fontFamily: {
        sans: ["var(--font-sans)", ...fontFamily.sans],
        mono: ["var(--font-mono)", ...fontFamily.mono],
      },
    },
  },
} satisfies Config;

That way we can have a separation of concerns and a clear structure for the Tailwind CSS configuration.

Themes

TurboStarter comes with 10+ predefined themes which you can use to quickly change the look and feel of your app.

They're defined in apps/packages/ui/shared/themes directory. Each theme is a set of CSS variables that can be overridden:

apps/packages/ui/shared/themes/orange.css
[data-theme="orange"] {
  ...
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --popover: 0 0% 100%;
  ...
}

Feel free to add your own themes or override the existing ones to match your brand's identity.

To apply a theme to your app, you can use the data-theme attribute on the html element:

apps/web/src/app/layout.tsx
export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html data-theme="orange">
      <body>{children}</body>
    </html>
  );
}

Dark mode

TurboStarter comes with a built-in dark mode support.

Each theme has a corresponding dark mode variables which are used to change the theme to its dark mode counterpart.

apps/packages/ui/shared/themes/orange.css
.dark[data-theme="orange"] {
  ...
  --background: 220 37% 8%;
  --foreground: 0 0% 98%;
  --card: 240 10% 3.9%;
  --card-foreground: 0 0% 98%;
  --popover: 240 10% 3.9%;
  ...
}

As we define the darkMode as class in the shared Tailwind config, we need to add the dark class to the html element to apply the dark mode styles.

For this purpose we're using next-themes package under the hood to handle the user preferences management.

apps/web/src/providers/theme.tsx
export const ThemeProvider = memo<ThemeProviderProps>(({ children }) => {
  return (
    <NextThemeProvider
      attribute="class"
      defaultTheme={appConfig.theme.default.mode}
      enableSystem
    >
      {children}
      <ThemeConfigProvider />
    </NextThemeProvider>
  );
});

As we saw in App configuration, we can define the default theme mode in the app configuration as well as available colors for your users.

Last updated on

On this page

Ship your startup everywhere. In minutes.Get TurboStarter