> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getsabo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dark Mode

> How to customize and apply dark mode styles in your Sabo project.

Sabo has full support for dark mode, built on top of **[next-themes](https://github.com/pacocoursey/next-themes)** and Tailwind CSS.

## How It Works

The theme system is enabled in `src/app/layout.tsx`, where the `<ThemeProvider>` component wraps your entire application.

```tsx src/app/layout.tsx theme={null}
// ...
import { ThemeProvider } from "@/components/theme-provider";

export default function RootLayout({ children }) {
  return (
    <html lang="en" suppressHydrationWarning>
      <body>
        <ThemeProvider
          attribute="class"
          defaultTheme="system"
          enableSystem
          disableTransitionOnChange
        >
          {children}
        </ThemeProvider>
        {/* ... */}
      </body>
    </html>
  );
}
```

* **`attribute="class"`**: This tells `next-themes` to toggle dark mode by adding or removing the `dark` class on the `<html>` element.
* **`defaultTheme="system"`**: The default theme is set to match the user's operating system preference.
* **`enableSystem`**: Allows the theme to sync with the system setting.

## Applying Dark Mode Styles

Sabo offers two ways to apply dark mode styles. The recommended approach is to use the semantic color system, which handles theme changes automatically.

<Tabs>
  <Tab title="Option 1: Semantic System (Recommended)">
    Sabo's components are built with a semantic color system based on CSS variables. This means you use classes that describe a component's **purpose**, not its color, and the theme system handles the color switching automatically.

    For example, instead of specifying `bg-white dark:bg-black`, you should use `bg-card`:

    ```tsx CardComponent.tsx theme={null}
    export function CardComponent() {
      return (
        <div className="bg-card text-card-foreground p-4 rounded-lg">
          <p>This card automatically adapts to dark mode.</p>
        </div>
      );
    }
    ```

    This works because variables like `--card` are defined with different values for light and dark themes in `src/app/globals.css`.
  </Tab>

  <Tab title="Option 2: Direct Styling with `dark:`">
    For one-off styles or unique components not covered by the semantic system, you can apply styles only for dark mode using the `dark:` prefix.

    ```tsx ThemedComponent.tsx theme={null}
    export function ThemedComponent() {
      return (
        <div className="bg-gray-100 text-black dark:bg-gray-900 dark:text-white">
          <p>This component's background and text will invert in dark mode.</p>
        </div>
      );
    }
    ```

    This method should be used sparingly.
  </Tab>
</Tabs>

<Info>
  This semantic approach is used for all themed components in Sabo. To learn more, see the **[Styling](/customization-guides/theme/styling)** guide.
</Info>

## Theme Toggle Component

Sabo includes a theme toggle component that allows users to switch between light, dark, and system themes.

* **Location**: `src/components/shared/theme-toggle.tsx`
* **Usage**: You can place the `<ThemeToggle />` component anywhere in your application. In this boilerplate, it is located in the `Footer` component.

Here is an example of how you might use it in a `Header` component:

```tsx src/components/shared/header.tsx theme={null}
import { ThemeToggle } from "@/components/shared/theme-toggle";
// ...
export function Header() {
  return (
    <header>
      {/* ... other header content */}
      <ThemeToggle />
    </header>
  );
}
```

The component handles all the state management for switching themes automatically.
