ActionsModeToggle

Open in Create
Search
astronomic.dev

ModeToggle

Free

In the navbar, to let a reader switch between light and dark; with nothing chosen the page follows their system.

File
ModeToggle.astro
Group
Actions
Kind
Interactive: inline script
Examples
3
import ModeToggle from "@astronomic-dev/ui/components/ModeToggle.astro";

Examples

Drag the orange handle to set the width. Frames get real breakpoints.

  • Static
  • Interactive
  • Framed

The switch

One button. With nothing chosen the page follows the reader's system. A press shows the other look and saves it; a press back to the system's own look clears the choice. Put the no-flash script in the page's <head> too: <script is:inline set:html={modeScript} />, with modeScript from @astronomic-dev/ui/lib/mode.ts; it applies a saved choice before the first paint.

Press to switch light and dark. Press again to follow your system.
Force state
main.astro

A light base

For a site that opens in light whatever the reader's system: base="light" here and modeScriptFor("light") in the page's <head>, from @astronomic-dev/ui/lib/mode.ts. A press shows dark and saves it; a press back to light clears the choice. base="dark" works the same way the other round.

Opens in light. Press for dark; press again to go back to light.
Force state
base.astro

In the navbar

In the utilities slot with tone="band", so it takes the bar's colors when a preset sets a band.

navbar.astro
Minimal · Light

Waitlist

Be first in line

Join the waitlist and we'll email you the moment it's out.

You'll also get our newsletter: new themes, plugins and guides. Unsubscribe any time.