light‑dark() Function Tester - Online Color Switch
Use the light‑dark() CSS function to change colors based on color scheme. Build a simple dark mode toggle with one property.
UD5 Toolkit
This preview shows how your CSS custom properties render in a real UI component with text, buttons, and interactive elements.
-- prefix (e.g., --bg-primary) that store reusable values. They cascade through the DOM, can be updated dynamically with JavaScript, and enable powerful features like easy theme switching without rewriting entire stylesheets. They are supported in all modern browsers.:root for light mode, then override them inside a dark mode selector like [data-theme="dark"] or @media (prefers-color-scheme: dark). Apply these variables throughout your stylesheet. Use JavaScript to toggle a data-theme attribute on the <html> element to switch themes on demand.[data-theme="dark"] is a manual approach where JavaScript controls theme switching based on user interaction (a toggle button). @media (prefers-color-scheme: dark) automatically follows the user's operating system preference. Many websites combine both: default to the OS preference but allow manual override via a toggle that sets the data attribute.document.documentElement.setAttribute('data-theme', 'dark') to switch to dark mode, and document.documentElement.removeAttribute('data-theme') to revert to light. Store the user's preference in localStorage so it persists across page reloads. Add a smooth CSS transition on your variables for a polished feel.filter: brightness(0.9) on images in dark mode to reduce eye strain. For logos and icons, consider using SVG with currentColor or providing separate light/dark versions swapped via CSS. The <picture> element with prefers-color-scheme media queries can also serve different image assets.--color-bg-primary, --color-text-body, --spacing-md. Define all light theme variables under :root and dark overrides in a single dark theme block. Keep variable definitions in one centralized file for maintainability.* { transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease; }. Be mindful of performance—limit transitions to color-related properties and avoid transitioning on too many elements simultaneously. For a more refined approach, apply transitions only to specific component containers.[data-theme="solarized"], [data-theme="high-contrast"], or [data-theme="sepia"]. Each theme block overrides the same set of variables with different values. This generator tool can help you create as many theme variants as you need—simply copy the CSS block and adjust the selector.localStorage: localStorage.setItem('theme', 'dark'). On page load, read the stored value and apply it before the page renders to avoid a flash of incorrect theme (FOIT). For optimal UX, check the stored preference in a small inline script in the <head> so the correct theme is applied immediately.Use the light‑dark() CSS function to change colors based on color scheme. Build a simple dark mode toggle with one property.
Paste a list of hex colors and generate CSS custom properties for them. Create your design token file instantly.
Grid of all 148 named CSS colors. Hover to see detail, click to copy the name or hex. Essential frontend reference.
Pick a base color and generate a full palette of 10 shades (50 to 900) like Tailwind CSS. Copy as hex or hsl.
Fetch a website's CSS and extract :root custom properties (‑‑color) to reveal its design token palette. For learning and inspiration.
Dynamically blend two colors using the CSS color‑mix() function in different color spaces. Copy the exact CSS snippet. No JS required.
Pick a color in the Display‑P3 space and get the CSS color() function. See the difference from sRGB. For modern design.
Style an `<input type='range'>` with custom track and thumb. Cross‑browser CSS. Preview and copy the code.
Type a CSS color name like 'tomato' or 'mediumseagreen' and instantly get its hex code and preview. Complete named colors list.
Browse every Tailwind default color palette side by side. Click any shade to copy the hex or class. For rapid design.
Set a custom accent color for checkboxes, radios, range, and progress. See the browser’s rendering. Copy the CSS.
A complete, searchable list of all 140+ named HTML/CSS colors with their hex codes and color previews. Click to copy code. Essential web reference.
Test the upcoming contrast‑color() CSS function. Get white or black automatically for a given background. See it live.
Type a word like 'sunset' or 'calm' and generate a color palette inspired by that mood. Simple associative mapping.
See the Pantone Colors of the Year and popular palettes from past years. Get hex codes. Design inspiration.
Enter a palette of colors and see a grid showing whether each foreground/background pair passes AA or AAA contrast. Must for designers.
Paste a stylesheet and extract every unique color (hex, rgb, hsl) into a palette. Swatches displayed. Copy as JSON.
Match gap size around doors/windows to the correct type of weather stripping (foam, V-strip, door sweep). Save energy.
Paste body text and test different font/background combos. See an actual passage rendered, not just a ratio. True feel for legibility.
Classic HSV color wheel with sliders. See hex, RGB, and HSL equivalents. Intuitive for artists. No server interaction.
Generate single random colors or full palettes. Displays hex, RGB, and copy on click. Great for design inspiration.
Use <input type='color'> and see its change events and value in hex. Understand the native color picker. Quick demo.
Experiment with CSS container queries in a live editor. Resize the container and see styles change based on its width/height. Learn modern responsive.
Find the official name of any hex color from the extended color dictionary. Search by name to get the hex code. Handy for CSS and design language.
Select a color and see which cocktails match it roughly. Blue for Blue Lagoon, red for Negroni. Fun bar guide.
Build the same layout with both Grid and Flexbox side by side. See the code differences and visual results.
Experiment with CSS container queries. Resize a container and see the styles change according to its size, not the viewport. Learn the new spec.
Test if your display supports HDR colors by rendering a gradient in Rec.2020 space. See what you're missing. Canvas based.
A replica of the famous Flexbox Froggy game: solve alignment puzzles by writing CSS. Progress saved locally. Fun frontend learning.
Add grid items beyond defined tracks and see how implicit rows/columns expand. Set sizes interactively. Master the grid.