New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

ng-theme-toggle

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-theme-toggle

An Angular component for toggling dark/light theme in a simple and customizable way

latest
v20-lts
Source
npmnpm
Version
20.0.2
Version published
Maintainers
2
Created
Source

NgThemeToggle cover

NgThemeToggle - Angular Theme toggle button

ng-theme-toggle is a standalone, reusable and customizable component for Angular 18, 19 and 20.

It is designed to work with signals and Angular zoneless, providing a lightweight, flexible, and accessible theme toggle button. It is also fully compatible with SSR, CSR and prerender.

Table of Contents

Installation

If you want to install the latest version (currently 20):

npm install ng-theme-toggle

Angular 19:

npm install ng-theme-toggle@v19-lts

Angular 18:

npm install ng-theme-toggle@v18-lts

Overview

Using ng-theme-toggle is easy:

  • Provide a complete signal to the [isDarkSignal] input and the component will handle the state automatically.
  • Configure its type, shape, hover behavior, and accessibility using inputs.
  • Style it with customizable CSS variables to match your design needs.

Here’s a basic usage example:

import { Component, signal } from '@angular/core';
import { NgThemeToggle } from 'ng-theme-toggle';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [NgThemeToggle],
  template: `
    <ng-theme-toggle
      [isDarkSignal]="isDark"
    />
  `
})
export class App {
  isDark = signal<boolean>(false);
}`

Functionality

As shown in the example above, you can use the [isDarkSignal] input to manage your theme mode signal.

It’s important to provide the entire signal (not just its value, e.g. isDark()) because the component itself changes the value of the signal when clicking on it.

Inputs and Outputs

Here is a list of all input/ouput:

Functionality Input

InputDescriptionDefault
isDarkSignalProvides the writable signal that controls the current theme mode.

Style & Behavior Inputs

InputDescriptionDefault
typeDefines the toggle’s visual style (solid, minimal, or outline).'minimal'
hoverSets the hover effect style (tone, scale, shadow, or none).'scale'
animationDetermines the toggle animation (rotateX, rotateY, or soft).'soft'
fasterSpeeds up the toggle animation when set to true.false

Accessibility Inputs

InputDescriptionDefault
tabIndexControls the toggle’s tab order in keyboard navigation.0
langDefines the language for built-in ARIA labels (en, es, fr, etc.).'en'
customAriaProvides custom ARIA labels to override default accessibility text.null

Styling

You can easily customize the component’s appearance using the CSS variables listed below.

ng-theme-toggle {
  --theme-toggle-bg: var(--global-color-from-theme);
  --theme-toggler-padding: 8px 16px;
}
VariableDescriptionDefault
--theme-toggle-sizeDefines the toggle width and height40px
--theme-toggle-bgBackground color of the buttonInherits light/dark mode
--theme-toggle-bg-lightBackground in light modetransparent / white (solid)
--theme-toggle-bg-darkBackground in dark modetransparent / black (solid)
--theme-toggle-paddingInner spacing of the button0 / 5px (solid/outline)
--theme-toggle-borderBorder style of the buttonInherits light/dark mode
--theme-toggle-border-lightBorder in light mode2px solid black
--theme-toggle-border-darkBorder in dark mode2px solid white
--theme-toggle-radiusControls the corner roundness50%
--theme-toggle-shadowBox shadow of the buttonInherits light/dark mode
--theme-toggle-shadow-lightShadow in light modenone
--theme-toggle-shadow-darkShadow in dark modenone
--theme-toggle-hover-transitionTransition timing for hover effects.4s ease-in-out
--theme-toggle-color-transitionTransition timing for color and stroke changes.4s ease-in-out
--theme-toggle-colorMain icon color and focus outlineInherits light/dark mode
--theme-toggle-color-lightIcon color in light modeblack
--theme-toggle-color-darkIcon color in dark modewhite
--theme-toggle-hover-bgBackground on hoverInherits light/dark mode
--theme-toggle-hover-bg-lightHover background in light mode#949494
--theme-toggle-hover-bg-darkHover background in dark mode#949494
--theme-toggle-hover-scaleScale effect applied on hover1.05
--theme-toggle-hover-shadow-color-lightShadow color on hover in light modergba(0, 0, 0, 0.623)
--theme-toggle-hover-shadow-color-darkShadow color on hover in dark modergba(255, 255, 255, 0.664)
--theme-toggle-rays-stroke-widthStroke width of the SVG rays50

💡 Usage Notes

  • Variables with suffixes -light and -dark are automatically applied based on the theme state (isDark).
  • The generic variables (like --theme-toggle-bg or --theme-toggle-border) act as entry points to override both modes at once.
  • You can freely mix hover effects (hover-tone, hover-scale, hover-shadow) for combined transitions.
  • All color and transform transitions share the same easing and duration for visual consistency.

Accessibility

There are two ways of setting the aria-label attributes: by lang attribute or by customAria attribute

InputDescriptionTypeDefault
langAria labels predefine languageThemeToggleLangs'en'
customAriaAria labels custom contentThemeToggleCustomAria or nullnone
  • If needed, you can import ThemeToggleLangs and ThemeToggleCustomAria types like this:
import { NgThemeButton, ThemeToggleLangs, ThemeToggleCustomAria } from 'ng-theme-toggle';

1. lang attribute:

The component includes five predefined languages for accessibility labels that you can set easily with the lang attribute:

LanguageCodeExample
English (default)en"Change to light mode" / "Change to dark mode"
Spanishes"Cambiar a modo claro" / "Cambiar a modo oscuro"
Italianit"Passa alla modalità chiara" / "Passa alla modalità scura"
Frenchfr"Passer en mode clair" / "Passer en mode sombre"
Germande"Wechseln Sie zum hellen Modus" / "Wechseln Sie zum dunklen Modus"

💡 If no value is provided in lang, the default language is English (en).
💡 If your application supports multiple languages, you can bind the lang attribute to a signal and link it with a select, for example.

2. customAria attribute:

In addition to the predefined languages available through the lang attribute, you can fully customize the ARIA labels for your theme toggle button by using the customAria input.

This option gives you full control over the text announced by screen readers when the theme is dark or light — perfect for custom translations, accessibility improvements, or when you want to use a language that is not included in the predefined set.

🧩 Example usage
<ng-theme-toggle
  [customAria]="{
    ariaLabelDark: 'Custom - set light mode',
    ariaLabelLight: 'Custom - set dark mode'
  }"
/>

💡 Remember that what is indicated in the customAria attribute replaces the default language set in lang.
💡 If you only set one of the properties, the other will use the label from the current lang.

Contribute or report

Choose the form that best fits your case:

👉 Or go to the form selector.

License

MIT

Keywords

angular

FAQs

Package last updated on 18 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts