Getting startedComponentsDesign tokensThemingTheme synthesizerFrameworksAccessibilityUtilitiesServer renderingBrowser supportContributingChangelogApp ShellAspect GridAuth ShellCenterContainerDashboard GridFloat BarInsetMasonryPage HeaderPage LayoutResizableResponsive SwitcherSectionSettings LayoutSplit PaneStatus BarStickyToolbarAnchor NavBottom NavBreadcrumbBreadcrumb MenuCommand BarDrawerFooterLinkMenubarNavigation MenuPage IndicatorPaginationRailScroll IndicatorScroll SpyScroll To TopSidebarSkip LinkStepper NavTabsTop BarTree ViewAccordionAspect RatioAvatarAvatar GroupCardCarouselCollapsibleColor SwatchCTA BannerDividerEmpty StateFeature CardIconImageImage CompareImage HotspotsInfinite ScrollLightboxMarqueeQR CodeScroll AreaSkeletonSpinnerStackVideoVirtual ListActivity HeatmapAnimated NumberBadgeBar ListChartClockComparisonCountdown TimerData GridDescription ListDiffGaugeJSON TreeKanbanLevel MeterListMeterSparklineStatStepperTagTimelineUptimeValue CardWaveformBlockquoteCode BlockCode GroupGradient TextHighlightKbdKeyboard MapMarkdownNumber FormatProseTerminalTextTime AgoTruncateTypewriterButtonButton GroupCalendarCheckboxChipColor PickerComboboxCopy ButtonDate PickerDate Range PickerField ListFieldsetFile UploadFormHotkeyIcon ButtonImage CropperInline EditInputInput GroupKnobLabelMasked InputMulti SelectNumber InputPassword InputPin InputRadio GroupRange SliderRatingSearchSegmented ControlSelectSignature PadSliderSortable ListSwitch GroupTag InputTextareaTheme ToggleTime PickerToggleTransfer ListTree SelectAlertAnnouncementBannerCommand PaletteConfirmConnection StatusContext MenuConversationDialogDropdown MenuHover CardLoading OverlayNotification PanelPopoverProgressSheetToastTooltip
ARC UIARC Radiant Components
v4.9DocsComponentsTokensSynthesizer
Getting startedFrameworksServer renderingDesign tokensThemingTheme synthesizerTypographyUtilitiesAll componentsAccessibilityBrowser supportChangelogContributingStatsApp ShellAspect GridAuth ShellCenterContainerDashboard GridFloat BarInsetMasonryPage HeaderPage LayoutResizableResponsive SwitcherSectionSettings LayoutSplit PaneStatus BarStickyToolbarAnchor NavBottom NavBreadcrumbBreadcrumb MenuCommand BarDrawerFooterLinkMenubarNavigation MenuPage IndicatorPaginationRailScroll IndicatorScroll SpyScroll To TopSidebarSkip LinkStepper NavTabsTop BarTree ViewAccordionAspect RatioAvatarAvatar GroupCardCarouselCollapsibleColor SwatchCTA BannerDividerEmpty StateFeature CardIconImageImage CompareImage HotspotsInfinite ScrollLightboxMarqueeQR CodeScroll AreaSkeletonSpinnerStackVideoVirtual ListActivity HeatmapAnimated NumberBadgeBar ListChartClockComparisonCountdown TimerData GridDescription ListDiffGaugeJSON TreeKanbanLevel MeterListMeterSparklineStatStepperTagTimelineUptimeValue CardWaveformBlockquoteCode BlockCode GroupGradient TextHighlightKbdKeyboard MapMarkdownNumber FormatProseTerminalTextTime AgoTruncateTypewriterButtonButton GroupCalendarCheckboxChipColor PickerComboboxCopy ButtonDate PickerDate Range PickerField ListFieldsetFile UploadFormHotkeyIcon ButtonImage CropperInline EditInputInput GroupKnobLabelMasked InputMulti SelectNumber InputPassword InputPin InputRadio GroupRange SliderRatingSearchSegmented ControlSelectSignature PadSliderSortable ListSwitch GroupTag InputTextareaTheme ToggleTime PickerToggleTransfer ListTree SelectAlertAnnouncementBannerCommand PaletteConfirmConnection StatusContext MenuConversationDialogDropdown MenuHover CardLoading OverlayNotification PanelPopoverProgressSheetToastTooltip

Theme Toggle

One button that cycles the page theme through dark, light and auto, and remembers the choice.

ComponentsTheme Toggle
inputinteractive
<arc-theme-toggle>

Overview

ThemeToggle is one button that cycles through dark, light and auto (the system setting). Each mode has its own icon (a moon, a sun or a monitor), and the icons scale and rotate as they change. The chosen mode is written to `data-theme` on the document root and to `localStorage` under `arc-theme`, so it persists across page loads. On first mount it uses the `theme` attribute if you set one. Otherwise it reads `arc-theme` from `localStorage`, then the `data-theme` already on the root, and falls back to `auto`. By default the button shows the current mode's name next to the icon. `icon-only` drops the name for a compact button in a toolbar or header.

Guidelines

Do

  • Put it somewhere that's always on screen, such as the top bar or a settings panel
  • Use `icon-only` where space is tight
  • Listen to `arc-change` to save the choice to a backend preference
  • Make sure your styles follow the `data-theme` attribute on the document root, or switching does nothing
  • Set `data-theme` on the HTML element during server rendering, so the page doesn't flash the wrong theme

Don't

  • Don't change the theme by writing the `arc-theme` key in `localStorage`. The toggle doesn't watch storage. Set a toggle's `theme` property or the root's `data-theme`, and every toggle on the page picks it up
  • Don't use it for settings other than the theme. Use Toggle

Features

  • Fires `arc-change` with the new mode in `detail.value` on every change
  • Enter and Space cycle the mode
  • The button scales to 0.95 while pressed

Preview

Usage

This component needs JavaScript. Use the Web Component or a framework wrapper.

<arc-theme-toggle></arc-theme-toggle>

API

theme'dark' | 'light' | 'auto''auto'
The current theme mode. Synced in both directions: changing it (by click, by key, or by assigning the property) writes the document root's data-theme and localStorage, and a change to that attribute from anywhere else is adopted back, so every toggle on the page agrees.
disabledbooleanfalse
Prevents cycling and reduces opacity to 40%.
iconOnlybooleanfalse
Renders the button as a compact square without the theme name label, matching an icon-only arc-icon-button of the same size. Attribute name is icon-only.
size'xs' | 'sm' | 'md' | 'lg''md'
Box size when icon-only, on the same scale as arc-icon-button: xs=28px, sm=32px, md=36px, lg=44px. Set both controls to the same value when they sit side by side. Ignored by the labeled form, which is sized by its text.

Events

arc-changedetail:{ value: 'dark' | 'light' | 'auto' }
Fired when the theme is toggled, with { theme } detail

See also