Socket
Socket
Sign inDemoInstall

postcss-dark-theme-class

Package Overview
Dependencies
5
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    postcss-dark-theme-class

CSS solution for light/dark/auto theme switcher for websites


Version published
Weekly downloads
4.7K
decreased by-1.74%
Maintainers
1
Install size
36.5 kB
Created
Weekly downloads
 

Changelog

Source

1.3.0

  • Added removeMedia option (by @aletorrado).

Readme

Source

PostCSS Dark Theme Class

CSS solution for light/dark/auto theme switcher for websites.

  • It doesn’t have FART flash of light theme during JS initialization.
  • Pure CSS solution. You need JS only to set HTML class, when user.
  • Automatic theme provide better UX for users with theme switching by subset/sunrise (all operating systems now have theme switching schedule).

PostCSS plugin to make switcher to force dark or light theme by copying styles from media query or light-dark() to special class.

/* Input CSS */

@media (prefers-color-scheme: dark) {
  html {
    --text-color: white
  }
  body {
    background: black
  }
}

section {
  background: light-dark(white, black);
}
/* Output CSS */

@media (prefers-color-scheme: dark) {
  html:where(:not(.is-light)) {
    --text-color: white
  }
  :where(html:not(.is-light)) body {
    background: black
  }
}
html:where(.is-dark) {
  --text-color: white
}
:where(html.is-dark) body {
  background: black
}

@media (prefers-color-scheme: dark) {
  :where(html:not(.is-light)) section {
    background: black;
  }
}
:where(html.is-dark) section {
  background: black;
}
@media (prefers-color-scheme: light) {
  :where(html:not(.is-dark)) section {
    background: white;
  }
}
:where(html.is-light) section {
  background: white;
}

By default (without classes on html), website will use browser dark/light theme. If user want to use dark theme, you set html.is-dark class. If user want to force light theme, you use html.is-light.

Sponsored by Evil Martians

Docs

Read full docs here.

Keywords

FAQs

Last updated on 22 Apr 2024

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc