Skip to main content
Documentation
On this page

Install Cirth for Electron

An Electron app's renderer is the Chromium page shown inside a window. Link Cirth in that page's <head>, where it applies to the whole rendered document. The Content Security Policy also needs to allow data: images, because Cirth uses them for its icons.

Verified with Electron 44.5.1 on

Three steps: install, link it and check it.

1 Install #

Package manager
npm install @cirthcss/cirth
pnpm add @cirthcss/cirth
yarn add @cirthcss/cirth
bun add @cirthcss/cirth

In the page the window loads, with a policy that allows data: images:

<head>
  <meta charset="utf-8">
  <meta http-equiv="Content-Security-Policy"
    content="default-src 'self'; style-src 'self'; img-src 'self' data:">
  <link rel="stylesheet" href="./node_modules/@cirthcss/cirth/dist/cirth.min.css">
</head>

Without data: in img-src, the policy blocks the check of a checkbox, the chevron of a select and every other icon, and logs each one. If the renderer is bundled with Vite (Electron Forge's Vite template), import Cirth as in the Vite guide instead, and set the CSS target there.

3 Check it #

Put this forced-dark region in a page or component that uses the global stylesheet:

<section data-theme="dark">
  <article>
    <p>Dark, whatever the system scheme is.</p>
  </article>
</section>

Run the app, then open the page while the system uses a light theme. A dark article proves that Cirth loaded and that data-theme="dark" is working. It remains dark when the system switches to a dark theme.

nativeTheme.themeSource = "dark" in the main process switches the whole window, and Cirth with it.

Customization covers the --cirth-* properties; set yours in a stylesheet loaded after Cirth's. Package and builds lists the classless, scoped and print entry points. Return to Framework guides for another stack.

Electron® is a registered trademark of the OpenJS Foundation.

Search documentation

Type at least two characters to search.