<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/light-mode-toggle-web-component-zachleat-com-nv3pyth9q" -->

---
title: light mode toggle Web Component)—zachleat.com | daily.dev
description: Zach Leatherman released a reusable Web Component called @zachleat/solar-eclipse-toggle, an accessible light/dark theme toggle button that follows the system...
canonical: https://daily.dev/posts/light-mode-toggle-web-component-zachleat-com-nv3pyth9q
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: light mode toggle Web Component)—zachleat.com | daily.dev
og:description: Zach Leatherman released a reusable Web Component called @zachleat/solar-eclipse-toggle, an accessible light/dark theme toggle button that follows the system...
og:url: https://daily.dev/posts/light-mode-toggle-web-component-zachleat-com-nv3pyth9q
og:image: https://api.daily.dev/og/posts/Nv3PyTH9q.png
og:image:alt: light mode toggle Web Component)—zachleat.com
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# light mode toggle Web Component)—zachleat.com

**[Zach Leatherman](https://daily.dev/sources/zachleat)** · 1 min read · 4 upvotes · 0 comments

## Summary

Zach Leatherman released a reusable Web Component called @zachleat/solar-eclipse-toggle, an accessible light/dark theme toggle button that follows the system preference by default. It grew out of an earlier experiment on his personal site, refined with accessibility feedback from a reader. Notable design details include an inert pre-JS button, no cumulative layout shift, graceful degradation via the hidden attribute when CSS fails to load, and light DOM string insertion for proper internationalization. Available on GitHub, npm, and npmx.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.zachleat.com/web/solar-eclipse>

## Questions this post answers

### How can I build an accessible dark/light mode toggle as a Web Component?

The @zachleat/solar-eclipse-toggle Web Component provides an accessible light/dark theme toggle button that follows the system preference by default. It renders an inert button before JavaScript loads, causes no cumulative layout shift, remains functional via the hidden attribute if its separate CSS fails to load, and inserts all strings from light DOM for proper internationalization.

_daily.dev surfaces web component patterns like this for developers polishing theme toggle accessibility._

### Why use light DOM for text strings in a Web Component instead of shadow DOM content?

Inserting strings from light DOM rather than shadow DOM improves internationalization support, since light DOM content remains directly accessible to translation tools and browser features that operate on the page's regular DOM tree, unlike text hidden inside a shadow root. This approach was a deliberate design choice in the solar-eclipse-toggle component's accessible toggle button.

_Developers weighing shadow DOM versus light DOM tradeoffs can find related component patterns on daily.dev._

## Similar posts on daily.dev

- [Theme Switching Made Easy](https://daily.dev/posts/theme-switching-made-easy-cqbsbpe7j) · Aaron Gustafson · 1 upvotes · 0 comments
- [Trying out a Two-state Dark Mode Toggle—zachleat.com](https://daily.dev/posts/trying-out-a-two-state-dark-mode-toggle-zachleat-com-djhvmr6jc) · Zach Leatherman · 5 upvotes · 1 comments
- [Dark Mode Toggle : Frontend Coding Exercises](https://daily.dev/posts/dark-mode-toggle-frontend-coding-exercises-mapdzpbjg) · Kirupa · 4 upvotes · 0 comments
- [Choose your own dark mode](https://daily.dev/posts/choose-your-own-dark-mode-spbiqs4dm) · dbushell · 37 upvotes · 1 comments
- [How to Build a Dark Mode Toggle Without JavaScript](https://daily.dev/posts/how-to-build-a-dark-mode-toggle-without-javascript-nbeu3nil3) · freeCodeCamp · 30 upvotes · 5 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#css](https://daily.dev/tags/css), [#accessibility](https://daily.dev/tags/accessibility), [#web-components](https://daily.dev/tags/web-components)

[View this post on daily.dev](https://daily.dev/posts/light-mode-toggle-web-component-zachleat-com-nv3pyth9q)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"light mode toggle Web Component)—zachleat.com","url":"https://daily.dev/posts/light-mode-toggle-web-component-zachleat-com-nv3pyth9q","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/light-mode-toggle-web-component-zachleat-com-nv3pyth9q"},"datePublished":"2026-09-14T16:20:56.817Z","dateModified":"2026-09-14T16:21:16.144Z","description":"Zach Leatherman released a reusable Web Component called @zachleat/solar-eclipse-toggle, an accessible light/dark theme toggle button that follows the system...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/0eda5c9cea72140c5dbf8d00908c8b10?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/0eda5c9cea72140c5dbf8d00908c8b10?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Zach Leatherman","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Zach Leatherman","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/7ce10e5a06b74735aa2b19fa200414bf","url":"https://daily.dev/sources/zachleat"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/light-mode-toggle-web-component-zachleat-com-nv3pyth9q","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":4},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"javascript,css,accessibility,web-components","timeRequired":"PT1M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Zach Leatherman","item":"https://daily.dev/sources/zachleat"},{"@type":"ListItem","position":3,"name":"light mode toggle Web Component)—zachleat.com"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/light-mode-toggle-web-component-zachleat-com-nv3pyth9q#faq","mainEntity":[{"@type":"Question","name":"How can I build an accessible dark/light mode toggle as a Web Component?","acceptedAnswer":{"@type":"Answer","text":"The @zachleat/solar-eclipse-toggle Web Component provides an accessible light/dark theme toggle button that follows the system preference by default. It renders an inert button before JavaScript loads, causes no cumulative layout shift, remains functional via the hidden attribute if its separate CSS fails to load, and inserts all strings from light DOM for proper internationalization. daily.dev surfaces web component patterns like this for developers polishing theme toggle accessibility."}},{"@type":"Question","name":"Why use light DOM for text strings in a Web Component instead of shadow DOM content?","acceptedAnswer":{"@type":"Answer","text":"Inserting strings from light DOM rather than shadow DOM improves internationalization support, since light DOM content remains directly accessible to translation tools and browser features that operate on the page's regular DOM tree, unlike text hidden inside a shadow root. This approach was a deliberate design choice in the solar-eclipse-toggle component's accessible toggle button. Developers weighing shadow DOM versus light DOM tradeoffs can find related component patterns on daily.dev."}}]}
```

