---
components: ["Theme"]
---

<script>
  import { InlineNotification, CodeSnippet } from "carbon-components-svelte";
  import Preview from "../../components/Preview.svelte";

  let code = `import "carbon-components-svelte/css/all.css";`;
</script>

The `Theme` component provides dynamic client-side theming using CSS variables. It supports five Carbon themes: white, g10, g80, g90, and g100, and allows for custom theme token overrides. The component can persist theme preferences using [window.localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) and provides built-in toggle and select controls for theme switching.

<InlineNotification svx-ignore lowContrast title="Note:" kind="info" hideCloseButton>
  <div class="body-short-01">You must use the "all.css" StyleSheet with the <code>Theme</code> component.</div>
</InlineNotification>

The `all.css` StyleSheet uses [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) for dynamic theming.

<CodeSnippet svx-ignore {code} />

## Default

Create a basic theme component that can be controlled programmatically.

<FileSource src="/framed/Theme/Theme" />

## Persist locally

Set `persist` to `true` to save the theme preference in [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage). Use `persistKey` to specify a custom storage key.

<FileSource src="/framed/Theme/ThemePersist" />

## Custom theme

Override default Carbon theme tokens by providing custom key-value pairs in the `tokens` prop. Refer to the [Carbon website](https://carbondesignsystem.com/guidelines/themes/overview#customizing-a-theme) for guidance on customizing themes.

<FileSource src="/framed/Theme/ThemeTokens" />

## Theme toggle

Set `render` to `"toggle"` to display a toggle switch for switching between two themes. By default, it toggles between "white" and "g100" themes.

<FileSource src="/framed/Theme/ThemeToggle" />

## Theme toggle (custom)

Customize the toggle appearance and behavior using the `toggle` prop. You can specify custom themes, labels, and other toggle properties.

<FileSource src="/framed/Theme/ThemeToggleCustom" />

## Theme select

Set `render` to `"select"` to display a dropdown menu for selecting from all available themes.

<FileSource src="/framed/Theme/ThemeSelect" />

## Theme select (custom)

Customize the select dropdown using the `select` prop. You can specify which themes to include, customize labels, and adjust other select properties.

<FileSource src="/framed/Theme/ThemeSelectCustom" />