惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
宝玉的分享
宝玉的分享
月光博客
月光博客
小众软件
小众软件
Jina AI
Jina AI
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 【当耐特】
博客园 - 三生石上(FineUI控件)
博客园 - 司徒正美
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog
G
Google Developers Blog
M
MIT News - Artificial intelligence
N
Netflix TechBlog - Medium
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
爱范儿
爱范儿
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Blog — PlanetScale
Blog — PlanetScale

Stonecharioteer on Tech

I Traced My Traffic Through a Home Tailscale Exit Node What Was I Reading Last? In Three Not-So-Easy Pieces Dogfooding Is Hard Code blocks in your books, finally GoForGo v0.9.0 Merrilin - We built an app to read books I use a Macbook now Data Structures & Algorithms - Preparing for Interviews Using a local DNS namespace for local service discovery Direction KOllector - Publishing KOReader Highlights gbt: branches touched in the last 24 hours A Soiree into Symbols in Ruby Some Smalltalk about Ruby Loops Ruby Blocks Returning from Ruby Blocks, Procs and Lambdas My Linux Laptop Finally Works: How Claude Helped Me Fix Years of Annoyances TIL: Watchexec - Modern File Watching for Development Workflows A Less Busy Mind GoForGo - Learn Go through live examples Migrating My Old Blog to Hugo with Claude The Qtile Window Manager: A Python-Powered Tiling Experience Read the RFCs that Built the Internet Py-x-Protobuf - Or How I Learned to Stop Worrying and Love Protocol Buffers Python Reverse a List New Beginnings Leaving ChainSafe Systems Screen Lock for Cinnamon Desktop using Zenity and Terminal Commands Crews Not Teams A System for Getting Better at LeetCode
TIL: Dark Mode Toggle Web Component by Google Chrome Labs
2021-03-15 · via Stonecharioteer on Tech

Web Components and Dark Mode

Dark Mode Toggle Custom Element

  • GitHub - GoogleChromeLabs/dark-mode-toggle
  • Custom HTML element for adding dark mode toggles to websites
  • Developed by Google Chrome Labs for easy dark mode implementation
  • Standards-based web component that works across frameworks

Key Features

Easy Integration

  • Custom Element: Use as simple HTML tag <dark-mode-toggle>
  • Framework Agnostic: Works with any framework or vanilla HTML
  • No Dependencies: Self-contained web component
  • Accessibility: Built with accessibility best practices

User Experience

  • Persistent Preference: Remembers user’s dark mode choice
  • System Integration: Respects OS-level dark mode preferences
  • Smooth Transitions: Provides smooth visual transitions
  • Customizable: Configurable appearance and behavior

Technical Implementation

  • CSS Custom Properties: Uses CSS variables for theming
  • Local Storage: Persists user preferences across sessions
  • Media Queries: Integrates with prefers-color-scheme
  • Progressive Enhancement: Works without JavaScript as fallback

Dark Mode Best Practices

Design Considerations

  • Color Contrast: Ensure sufficient contrast in both modes
  • Image Handling: Consider image visibility in dark themes
  • Brand Colors: Adapt brand colors for dark backgrounds
  • User Choice: Always allow user override of system preferences

Implementation Patterns

  • CSS Variables: Use custom properties for easy theme switching
  • Semantic Colors: Define colors by purpose, not appearance
  • Component Isolation: Ensure components work in both modes
  • Testing: Test thoroughly in both light and dark modes

Key Takeaways

  • User Experience: Dark mode is becoming an expected feature
  • Web Standards: Custom elements provide reusable, standards-based solutions
  • Accessibility: Consider user preferences and system settings
  • Developer Experience: Well-designed components simplify implementation
  • Progressive Enhancement: Build features that work with or without JavaScript

This component demonstrates how web standards and thoughtful design can make complex features (like theme switching) simple to implement while maintaining excellent user experience and accessibility.