|
| 1 | +--- |
| 2 | +title: "Adding dark mode to the main Sugar Labs website" |
| 3 | +excerpt: "New developer Syed Khubayb Ur Rahman shares how he implemented dark mode, what issues he faced and how he debugged them." |
| 4 | +category: "DEVELOPER NEWS" |
| 5 | +date: "2025-10-04" |
| 6 | +slug: "adding-dark-mode-to-sugar-labs" |
| 7 | +author: "@/constants/MarkdownFiles/authors/syed-khubayb-ur-rahman.md" |
| 8 | +tags: "dark-mode,accessibility,frontend,Sugar Labs" |
| 9 | +image: "assets/Images/darkmode.png" |
| 10 | +--- |
| 11 | + |
| 12 | + |
| 13 | +<!-- markdownlint-disable --> |
| 14 | + |
| 15 | + |
| 16 | +# Adding dark mode to a Sugar Labs Website |
| 17 | + |
| 18 | + |
| 19 | +## Introduction |
| 20 | +Sugar Labs builds free/libre/open-source (FLO) tools that make learning playful and accessible. I recently contributed dark mode to a Sugar Labs web project. This post outlines the problem I encountered, how I debugged and fixed it, and the key lessons I learned so others can ship accessible theming with confidence. |
| 21 | +Repository: [https://github.com/sugarlabs/www-v2](https://github.com/sugarlabs/www-v2) |
| 22 | + |
| 23 | + |
| 24 | +## The Problem |
| 25 | +The main Sugar Labs website originally lacked a dark mode option, which made browsing less comfortable in low-light conditions. |
| 26 | +Without dark mode, the bright interface could cause eye strain and reduce accessibility for users with light sensitivity. |
| 27 | + |
| 28 | + |
| 29 | +- **Goal:** Deliver a robust dark mode that respects system preference, including a manual toggle with persistence, and maintaining accessible contrast across the interface. |
| 30 | + |
| 31 | + |
| 32 | +Implementing the dark mode required careful planning to ensure consistency and accessibility. I began by auditing the color system, identifying issues with hardcoded values, and setting up a structure that would support scalable theming. The steps below summarize my debugging process and how each challenge was resolved. |
| 33 | + |
| 34 | + |
| 35 | +## Debugging and Solution |
| 36 | +- **Color audit and mapping:** I inventoried all color usages, identified hardcoded values, and grouped them into semantic tokens (background, text, muted, accent, surface). This created a maintainable foundation for theming. |
| 37 | +- **Single source of truth:** I centralized color decisions via tokens instead of scattering values across files and components. This reduced duplication and made changes less error‑prone. |
| 38 | +- **Preference‑aware default:** The implementation respects the user’s system setting via the `prefers-color-scheme` media query when no explicit preference is stored. This provides a sensible baseline experience that aligns with OS‑level accessibility choices. |
| 39 | +- **Manual toggle with persistence:** A simple theme switch allows users to override the system default. The selected theme is persisted (e.g., using `localStorage`) so their preference remains consistent across sessions. |
| 40 | +- **Component‑wide updates:** I refactored buttons, inputs, cards, alerts, focus rings, and states (hover, active, disabled) to use tokens. Each state was validated for contrast in both themes. |
| 41 | +- **Icons and media adjustments:** I standardized icons to adapt to the active theme and introduced subtle borders/surfaces to preserve structure on dark backgrounds. |
| 42 | +- **Accessibility validation:** I checked contrast ratios, improved focus visibility, and tested keyboard navigation and zoom to ensure inclusive design. |
| 43 | +- **Cross‑browser and performance checks:** I verified behavior across major browsers and optimized the switch to be instantaneous by relying on theme variables rather than heavy DOM updates. |
| 44 | + |
| 45 | + |
| 46 | +## Challenges and Takeaways |
| 47 | +- **Third‑party components:** Some libraries hardcoded their colors. Carefully scoped overrides and mapping external variables to our tokens aligned them with the overall theme. |
| 48 | +- **Brand color tuning:** The primary accent required adjustments for dark backgrounds. Preserving hue while tweaking lightness/saturation retained brand identity and improved legibility. |
| 49 | +- **Legacy inline styles:** Inline color rules resisted theming. Moving values into tokens eliminated one‑off overrides and simplified maintenance. |
| 50 | +- **Documentation as leverage:** I documented the token system and theme architecture. Clear guidelines made it easier for future contributors to build consistently. |
| 51 | +- **Accessibility‑first mindset:** Dark mode is not color inversion. Designing for contrast, depth, and hierarchy from the start avoids costly rework later. |
| 52 | + |
| 53 | + |
| 54 | +## Impact and Conclusion |
| 55 | +- **Impact on users:** Reduced eye strain, improved readability, and a cohesive experience especially valuable for users with light sensitivity. |
| 56 | +- **Impact on the project:** A unified token system speeds up future development, theming, and contributor onboarding. |
| 57 | +- **Community value:** The approach respects user preferences, provides control, and centers accessibility principles aligned with Sugar Labs’ mission. |
| 58 | + |
| 59 | + |
| 60 | +By sharing my experience, I hope to inspire others to contribute to Sugar Labs and make a positive impact on the community. I started by defining semantic tokens, honoring system preferences, and prioritizing accessibility. Through this process, I was able to deliver a dark mode that feels natural, inclusive, and maintainable. |
| 61 | + |
| 62 | +## Try it out |
| 63 | + |
| 64 | +The dark mode toggle button is available on the top-right corner of the page. |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +*Look for this button to switch between light and dark themes!* |
0 commit comments