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.
Fetch a website's CSS and extract :root custom properties (‑‑color) to reveal its design token palette. For learning and inspiration.
Interactively create colors in HWB space and get the CSS hwb() function. Simplifies tint/shade workflows. Live preview.
Design a layout where nested grids share track sizes with their parent via subgrid. Copy the complete CSS.
Create a pure CSS scroll progress indicator using animation‑timeline: scroll(). No JavaScript. Copy the complete code.
Pick colors for the shadcn/ui design system and generate the complete CSS variable theme file. Copy into your project.
Paste your CSS and see warnings for properties that have limited browser support. Links to CanIUse. Modernize safely.
Paste an SVG and get an optimized, URL‑encoded data URI for use in CSS backgrounds. Reduces file size and escapes characters.
Limit browser gestures on an element: pan‑x, pinch‑zoom, manipulation. Draw on a canvas to test. Mobile dev helper.
Create complex linear gradients with any number of color stops, exact angles, and length units. Live preview and CSS code.
Style underlines, overlines, and strike-throughs with colors, wavy styles, and thickness. Modern CSS text‑decoration.
Generate a random HTML/CSS card with different box model properties. Inspect and guess the size. For learners.
Design a button or card that glows on hover. Adjust shadow color, spread, and transition. Copy the CSS. Rich UI.
Interactively add and adjust multiple box shadows on a sample element. Drag sliders for offset, blur, spread, and color. Copy the clean CSS code instantly.
Create a realistic letterpress (debossed) text effect using CSS text‑shadow and background. Adjust depth and light direction. Copy code.
Generate a subtle noise/grain texture as a CSS background pattern. Adjust opacity and size. For that film look.
Create a customizable checkerboard or grid background using pure CSS gradients. Adjust cell size and colors. Copy the code.
Upload two images and apply CSS blend modes (multiply, screen, overlay, etc.). See the result and copy the filter CSS. Pure frontend.
Add print styles like removing backgrounds, adding page breaks, setting margins. See print preview instantly.
Create a pure CSS countdown timer with a flipping number effect. Adjust duration and style. No JavaScript needed for display.
Create a glowing or rotating border animation around an element. Copy the CSS keyframes. Pure CSS magic.
Create a custom HTML/CSS progress bar with percentage, colors, and animation. Copy the code. Modern UI element.
Design a realistic neon sign text with multiple layers of glow. Copy the CSS and HTML. Perfect for headers.
A replica of the famous Flexbox Froggy game: solve alignment puzzles by writing CSS. Progress saved locally. Fun frontend learning.
Recreate the target CSS linear gradient by adjusting stops and colors. A unique game for front‑end developers to master gradients.
Browse and search all Font Awesome 6 icons with preview, class name, and unicode. Copy the HTML snippet. Perfect for web developers.
Create text with a gradient fill using CSS background-clip. Configure colors and direction. Copy the code. Works in modern browsers.
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.
Visually experiment with Flexbox container and item properties. See the layout update in real time and copy the CSS. Learn by doing, fully interactive.