What is CSS Light-Dark Function Generator?
The light-dark() CSS function takes two color values and automatically picks the first for light mode and the second for dark mode based on the color-scheme property. This eliminates the need for duplicate CSS custom property blocks or a JavaScript theme toggle for basic dark mode support.
Quick answer
The light-dark() CSS function returns one of two color values based on the current color scheme, making it easy to support light and dark modes without duplicating CSS rules.
Limitations
- light-dark() only works when the color-scheme property is set on the document or element. Without it the function defaults to the first color.
- The function accepts exactly two color values -- one for light and one for dark. Complex theme switching still requires custom properties or media queries.
- Older browsers do not support light-dark(). Provide a fallback color before the light-dark() function in the property declaration.
How to use this tool
- Choose the color properties you want to theme, such as text color or background.
- Enter a light color and a dark color for each property.
- The tool generates the color-scheme declaration and light-dark() function calls.
- Copy the CSS and add the color-scheme meta tag to your page head.
What you can use it for
- Add basic dark mode to a static site without JavaScript.
- Create light and dark color pairs for text, backgrounds, and borders.
- Build a small design token system using light-dark() for theme consistency.