EN
Getting started
13 · Menu

Theme toggle

An icon button that switches between the light and dark themes. The preference is stored in the browser and, if the layout has a preference-url, also saved to the account. Since the icon is chosen with CSS, it looks right as soon as the page first opens.

acun:theme-toggle
01

Basic usage

A moon icon is shown in the light theme and a sun icon in the dark theme; clicking switches to the opposite of the theme on screen. For screen readers, the button text also changes with the theme ("Switch to the dark theme" / "Switch to the light theme").

LIVE EXAMPLE
<acun:theme-toggle />
02

In the layout

acun:layout.sidebar and acun:layout.horizontal show the button in the top bar themselves. To move it elsewhere, pass :theme-toggle="false" to the layout and put the button in the slot you want; attributes such as class are added to the button.

BLADE
<acun:layout.sidebar :theme-toggle="false">
    <acun:slot:drawerFooter>
        <acun:theme-toggle class="ms-auto" />
    </acun:slot:drawerFooter>

    {{ $slot }}
</acun:layout.sidebar>
PropValues
theme-toggletrue | false (layout prop)
03

Light, dark and system

The button only switches between light and dark. To also offer the user the option of following the operating system, build your own picker with $store.appearance.set().

LIVE EXAMPLE
<div x-data class="inline-flex gap-1 rounded-sm bg-gray-100 p-1 dark:bg-zinc-800">
    <acun:button size="sm" variant="ghost" x-on:click="$store.appearance.set('light')">Light</acun:button>
    <acun:button size="sm" variant="ghost" x-on:click="$store.appearance.set('dark')">Dark</acun:button>
    <acun:button size="sm" variant="ghost" x-on:click="$store.appearance.set('system')">System</acun:button>
</div>
PropValues
$store.appearance.set()light | dark | system
API

Props and slots

The values the component accepts.

PropDefaultDescription
(attributes) — Takes no props; attributes such as class and aria-* are added to the button
Acun UI · Theme toggleDetailed usage and examples