---
title: "Theme System"
description: "Manage colors, radius, icon sets and dark mode through module defaults, the ThemePicker component and the useTheme composable, with build-time font configuration."
canonical_url: "https://nuxt.mhaibaraai.me/en/docs/getting-started/theme"
---
# Theme System

> Manage colors, radius, icon sets and dark mode through module defaults, the ThemePicker component and the useTheme composable, with build-time font configuration.

## Introduction

Movk Nuxt provides unified runtime theme management on top of [Nuxt UI](https://ui.nuxt.com) theming: colors, radius, fonts, icon sets and dark mode are all centrally controlled and can be interactively adjusted at runtime, with one-click export of CSS variables or configuration code.

Theme capabilities consist of three parts:

- **[Module defaults](https://nuxt.mhaibaraai.me/en/docs/getting-started/configuration)**: Declare available options in `movk.theme` inside `nuxt.config.ts`.
- **`ThemePicker` component**: A user-facing visual control panel with export support.
- **`useTheme` composable**: Read and write theme state in scripts, export CSS/config.

## Enable & Disable

The theme module is enabled by default. When disabled, `appConfig` defaults, the theme plugin and the `ThemePicker` component are no longer injected:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  movk: {
    theme: { enabled: false }
  }
})
```

## ThemePicker Component

`ThemePicker` provides visual switching for colors, radius, icon sets and dark mode, and can export the current theme.

> [!TIP]
> See: #themepicker-reference
> 
> View the complete props, events and usage of ThemePicker.

## useTheme

`useTheme` exposes reactive theme state and export methods, suitable for custom theme panels or reading theme values in business logic:

```ts
const {
  color, neutral, radius, icon, mode,
  exportCSS, exportConfig, resetTheme
} = useTheme()

// Read/switch theme
color.value = 'green'
mode.value = 'dark'

// Export current theme
const css = exportCSS()
const config = exportConfig()
```

> [!TIP]
> See: #usetheme-reference
> 
> View all state and methods returned by useTheme.

## Fonts

The font is build-time configuration and does not switch at runtime. One line is all it takes:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  movk: {
    theme: {
      font: 'Alibaba PuHuiTi'
    }
  }
})
```

At build time the module does three things, all served straight from SSR with no runtime JS involved:

- Writes the font stylesheet `<link>` into `<head>`
- Adds a `preconnect` with `crossorigin` for cross-origin fonts
- Injects `@theme { --font-sans }`, appending a fallback stack that covers the system Chinese fonts on macOS, Windows and Linux

Built-in fonts are hosted by [movk-fonts](https://cdn.mhaibaraai.me). The value must match the `font-family` in their `@font-face` declarations character for character:

| Value | Stylesheet |
| --- | --- |
| `Alibaba PuHuiTi` | `https://cdn.mhaibaraai.me/fonts/alibaba-puhuiti.css` |
| `OPPO Sans` | `https://cdn.mhaibaraai.me/fonts/oppo-sans.css` |

For self-hosted fonts, use the `{ name, href }` form to supply the stylesheet URL:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  movk: {
    theme: {
      font: { name: 'My Font', href: '/fonts/my-font.css' }
    }
  }
})
```

> [!WARNING]
> 
> A wrong 
> 
> name
> 
>  raises no error — it silently falls back to the system font. CSS family matching is case-insensitive, but 
> 
> alibaba-puhuiti
> 
>  and 
> 
> Alibaba PuHuiTi
> 
>  are two different names. A font that is neither built in nor given an 
> 
> href
> 
>  triggers no request at all, and the module warns during development.

The `@theme` injected by the module lands with `@import "@movk/nuxt"`, so any `@theme` written after it overrides `--font-sans`. To control the font entirely from your own CSS, leave `movk.theme.font` unset:

```css [app/assets/css/main.css]
@import "tailwindcss";
@import "@movk/nuxt";

@theme {
  --font-sans: "OPPO Sans", sans-serif;
}
```

> [!NOTE]
> 
> Chinese fonts are split by 
> 
> unicode-range
> 
> , so the browser only downloads the shards holding characters the page actually uses. That is why these fonts 
> 
> must not
> 
>  be handed to 
> 
> @nuxt/fonts
> 
>  — it downloads every shard into the build output at build time, losing both on-demand loading and the CDN cache shared across projects. 
> 
> @movk/nuxt
> 
>  already sets 
> 
> ui.fonts: false
> 
>  by default, so your project never needs to declare it.

## Icon Sets

`ThemePicker` and `useTheme` switch between the Lucide, Phosphor and Tabler icon sets at runtime. Switching only rewrites `appConfig.ui.icons` — no rebuild required.

By default the module feeds the icons used by its own components, plus all three icon sets, into the `@nuxt/icon` build-time bundle, so nothing has to be fetched from the Iconify API at runtime. Each set needs its own `@iconify-json` package to be inlined:

```bash
npx nypm add -D @iconify-json/lucide @iconify-json/ph @iconify-json/tabler
```

> [!NOTE]
> 
> A missing collection never fails the build; its icons simply fall back to on-demand runtime loading. The module warns when the default 
> 
> lucide
> 
>  collection is missing, while 
> 
> ph
> 
>  and 
> 
> tabler
> 
>  — only needed after switching icon sets — are reported as a debug log.

To opt out entirely (for example when your project manages the icon bundle itself), turn it off; movk component icons then load at runtime:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  movk: {
    icon: { clientBundle: false }
  }
})
```

## Radius

`--ui-radius` keeps its three-level precedence: `ThemePicker` selection > `movk.theme.radius` > your project CSS. When omitted, the module does not inject the variable and the `@nuxt/ui` default (`0.25rem`) applies, so your project can override it in its own CSS:

```css [app/assets/css/main.css]
@theme {
  --ui-radius: 0.5rem;
}
```

## Customizing Options

Color aliases, radius steps and neutral colors can all be overridden in `movk.theme`, serving as the value range for `ThemePicker` and `useTheme`:

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  movk: {
    theme: {
      colors: ['primary', 'secondary', 'success', 'info', 'warning', 'error'],
      radiuses: [0, 0.125, 0.25, 0.375, 0.5],
      neutralColors: ['slate', 'gray', 'zinc', 'neutral', 'stone']
    }
  }
})
```

> [!TIP]
> See: /en/docs/getting-started/configuration
> 
> See Module Configuration · Theme for field descriptions

## Export & Reuse

The CSS variables exported by `ThemePicker` and `useTheme.exportCSS()` can be written directly into your project's `main.css`, solidifying runtime debugging results as the default theme:

```css [app/assets/css/main.css]
@import "tailwindcss";
@import "@movk/nuxt";

:root {
  /* Paste variables exported by exportCSS() */
}
```

## ThemePicker Reference

### Introduction

`MThemePicker` is a visual theme configuration component that allows users to preview and customize the application theme in real time. It unifies adjustments to `primary`, `neutral`, border-radius, icon sets, and color mode, with support for exporting CSS variables and `app.config.ts` configuration code.

> [!NOTE]
> See: https://github.com/nuxt/ui/tree/v4/docs/app/components/theme-picker
> 
> Configuration changes are stored locally and automatically restored on the next visit. The component source originates from Nuxt UI.

> [!NOTE]
> 
> MThemePicker
> 
>  is part of the theme module. If 
> 
> movk.theme.enabled
> 
>  is set to 
> 
> false
> 
> , this component will not be registered.

### Usage

`MThemePicker` is typically used as a global theme configuration entry, placed in the application header or toolbar:

> [!TIP]
> 
> The current theme tokens update immediately after panel operations, making it easy to verify configuration changes. Use 
> 
> useTheme
> 
>  to read reactive state:

```vue [ComponentsThemePickerStateExample.vue]
<script setup lang="ts">
const theme = useTheme()
</script>

<template>
  <div class="gap-4 flex">
    <MThemePicker />

    <ClientOnly>
      <div class="grid grid-cols-2 gap-2 text-sm">
        <div>primary: <UBadge :label="theme.primary.value" variant="subtle" /></div>
        <div>neutral: <UBadge :label="theme.neutral.value" variant="outline" /></div>
        <div>radius: {{ theme.radius.value }}rem</div>
        <div>icons: {{ theme.icon.value }}</div>
        <div>mode: {{ theme.mode.value }}</div>
      </div>
      <template #fallback>
        <div class="grid grid-cols-2 gap-2 text-sm text-muted">
          <USkeleton class="h-5" />
          <USkeleton class="h-5" />
          <USkeleton class="h-5" />
          <USkeleton class="h-5" />
          <USkeleton class="h-5" />
        </div>
      </template>
    </ClientOnly>
  </div>
</template>
```

### Features

#### Primary Color Configuration

- **Primary**: Choose the main brand color, supporting black or preset colors
- **Neutral**: Configure neutral tones affecting text and backgrounds

#### Style Configuration

- **Radius**: Adjust global border-radius size (0–5 levels)
- **Icons**: Switch icon sets (Lucide, Phosphor, Tabler)

#### Color Mode

Three color modes are supported:

- `light`: Light mode
- `dark`: Dark mode
- `system`: Follow system preference

#### Export Configuration

Once configured, you can export:

- `main.css`: CSS variable configuration
- `app.config.ts`: Application configuration code

### Theme

::component-theme
::

### Changelog

See commit history for [src/runtime/components/theme-picker/Theme System.vue](https://github.com/mhaibaraai/movk-nuxt/commits/main/src/runtime/components/theme-picker/Theme System.vue).

## useTheme Reference

### Introduction

`useTheme` exposes the reactive theme state and export methods. It is the underlying logic for the [`ThemePicker`](#themepicker-reference) component and can be used to build custom theme panels or read/write theme values in business logic.

### Return Values

```ts
const {
  // Color
  color, primary, primaryColors, neutral, neutralColors,
  blackAsPrimary, setBlackAsPrimary,
  // Radius / Icon / Mode
  radius, radiuses, icon, icons, mode, modes,
  // Injection and state
  style, hasCSSChanges, hasConfigChanges,
  // Export
  exportCSS, exportConfig, resetTheme
} = useTheme()
```

| Group | Members | Description |
| --- | --- | --- |
| Color | `color` / `primary` / `primaryColors` | Primary color and available options |
| Color | `neutral` / `neutralColors` | Neutral color and available options |
| Color | `blackAsPrimary` / `setBlackAsPrimary` | Toggle for using black as the primary color |
| Radius | `radius` / `radiuses` | Current border radius and available presets |
| Icon | `icon` / `icons` | Current icon set and available options |
| Mode | `mode` / `modes` | Dark mode (`light`/`dark`/`system`) and available options |
| Injection | `style` | CSS variables to inject into the page |
| State | `hasCSSChanges` / `hasConfigChanges` | Whether there are changes relative to the defaults |

> [!TIP]
> See: #themepicker-reference
> 
> For a ready-to-use visual theme panel, see the ThemePicker component.


## Sitemap

See the full [sitemap](https://nuxt.mhaibaraai.me/sitemap.md) for all pages.
