Navigation

v2.1.0
Forms

Gradient

A gradient being made: its stops on a bar, the stop in hand in a color picker, and its type, angle and center.

On this page

A gradient editor makes a gradient: its stops on a bar, the stop in hand in a color picker, and its type, angle and center. Every control in it is the library's own: the color picker, a slider and a number for a stop's place, a segmented control for the type, a dial for the angle, numbers for the center. What the gradient adds is the bar of stops, the preview and the gradient behavior that keeps them all in step.

Gradient

<div class="gradient max-w(640) mx-auto" id="sunrise" role="group" aria-label="Background gradient" style="--gradient-ratio: 3 / 1">  <div class="gradient-preview" aria-hidden="true"></div>  <div class="gradient-bar"></div>  <div class="flex flex-wrap items-center gap-xs">    <button type="button" class="btn btn-sm gradient-add">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M3 8L13 8" /><path d="M8 3L8 13" />      </svg>Add a stop    </button>    <button type="button" class="btn btn-sm gradient-remove">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M3 8L13 8" />      </svg>Remove    </button>    <button type="button" class="btn btn-sm btn-quiet gradient-reverse">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M8 1.6667L8 14.3333" /><path d="M5.6667 6.3298L5.6667 11.45A0.55 0.55 0 0 1 5.1167 12L2.5566 12A0.55 0.55 0 0 1 2.0647 11.204L4.6248 6.0839A0.55 0.55 0 0 1 5.6667 6.3298Z" /><path d="M10.3333 6.3298L10.3333 11.45A0.55 0.55 0 0 0 10.8833 12L13.4434 12A0.55 0.55 0 0 0 13.9353 11.204L11.3752 6.0839A0.55 0.55 0 0 0 10.3333 6.3298Z" />      </svg>Reverse    </button>  </div>  <div class="gradient-fields">    <fieldset class="gradient-color">      <legend class="mb(6) text-xs font-medium fg-text-muted">Color of the stop</legend>      <div class="color-picker" style="--color-picker-lightness: .7; --color-picker-chroma: .19; --color-picker-hue: 50">        <div class="color-picker-area">          <div class="color-picker-thumb" role="slider" tabindex="0" aria-label="Lightness and chroma" aria-valuemin="0" aria-valuemax="100" aria-valuenow="70"></div>        </div>        <span class="swatch swatch-lg color-picker-swatch"></span>        <input type="range" class="slider color-picker-hue" min="0" max="360" value="50" aria-label="Hue">        <input type="range" class="slider color-picker-alpha" min="0" max="100" value="100" aria-label="Opacity">        <div class="color-picker-fields">          <select class="select select-sm color-picker-format" aria-label="Format">            <option value="hex" selected>Hex</option>            <option value="rgb">RGB</option>            <option value="oklch">OKLCH</option>          </select>          <input class="input input-sm color-picker-text" value="#ff6a00" aria-label="Color" spellcheck="false" autocomplete="off">        </div>      </div>    </fieldset>    <div class="flex flex-col gap-md min-w(0)">      <fieldset class="gradient-offset">        <legend class="mb(6) text-xs font-medium fg-text-muted">Position</legend>        <input type="range" class="slider" min="0" max="100" step="1" value="0" aria-label="Position of the stop">        <input type="number" class="input input-sm w(72)" min="0" max="100" step="1" value="0" aria-label="Position of the stop, in percent">      </fieldset>      <fieldset class="gradient-type">        <legend class="mb(6) text-xs font-medium fg-text-muted">Type</legend>        <div class="segmented segmented-sm" role="radiogroup" aria-label="Type">          <label class="segmented-item">            <input type="radio" class="segmented-input" name="sunrise-type" value="linear" checked>Linear          </label>          <label class="segmented-item">            <input type="radio" class="segmented-input" name="sunrise-type" value="radial">Radial          </label>          <label class="segmented-item">            <input type="radio" class="segmented-input" name="sunrise-type" value="conic">Conic          </label>        </div>      </fieldset>      <div class="flex flex-wrap items-start gap-lg">        <fieldset class="gradient-angle">          <legend class="mb(6) text-xs font-medium fg-text-muted">Angle</legend>          <div class="dial dial-sm dial-full" role="slider" tabindex="0" aria-label="Angle" aria-valuenow="135" aria-valuemin="0" aria-valuemax="360" aria-valuetext="135°" style="--dial-value: 135">            <span class="dial-value">135°</span>            <span class="dial-thumb"></span>          </div>        </fieldset>        <fieldset class="gradient-center">          <legend class="mb(6) text-xs font-medium fg-text-muted">Center</legend>          <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center across, in percent">          <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center down, in percent">        </fieldset>      </div>    </div>  </div>  <pre class="code-block gradient-css" role="region" tabindex="0" aria-label="The gradient as CSS"></pre></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.gradient(document.getElementById('sunrise'), { value: { type: 'linear', angle: 135, center: [50, 50], stops: [  { id: 'dawn', offset: 0, color: '#ff6a00' },  { id: 'noon', offset: 55, color: '#ee0979' },  { id: 'dusk', offset: 100, color: '#4f46e5' }] } })})</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach, gradient } from '@master/ui/behaviors'import PlusIcon from '@master/icons-react/native/16/soft/plus'import MinusIcon from '@master/icons-react/native/16/soft/minus'import FlipHorizontalIcon from '@master/icons-react/native/16/soft/flip-horizontal'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => {    const detach = [      attach(root.current!),      gradient(document.getElementById('sunrise')!, { value: { type: 'linear', angle: 135, center: [50, 50], stops: [        { id: 'dawn', offset: 0, color: '#ff6a00' },        { id: 'noon', offset: 55, color: '#ee0979' },        { id: 'dusk', offset: 100, color: '#4f46e5' }      ] } }),    ]    return () => detach.forEach(stop => stop())  }, [])  return (    <div ref={root} className="gradient max-w(640) mx-auto" id="sunrise" role="group" aria-label="Background gradient" style={{ '--gradient-ratio': '3 / 1' } as React.CSSProperties}>      <div className="gradient-preview" aria-hidden="true"></div>      <div className="gradient-bar"></div>      <div className="flex flex-wrap items-center gap-xs">        <button type="button" className="btn btn-sm gradient-add">          <PlusIcon className="icon" />Add a stop        </button>        <button type="button" className="btn btn-sm gradient-remove">          <MinusIcon className="icon" />Remove        </button>        <button type="button" className="btn btn-sm btn-quiet gradient-reverse">          <FlipHorizontalIcon className="icon" />Reverse        </button>      </div>      <div className="gradient-fields">        <fieldset className="gradient-color">          <legend className="mb(6) text-xs font-medium fg-text-muted">Color of the stop</legend>          <div className="color-picker" style={{ '--color-picker-lightness': '.7', '--color-picker-chroma': '.19', '--color-picker-hue': '50' } as React.CSSProperties}>            <div className="color-picker-area">              <div className="color-picker-thumb" role="slider" tabIndex={0} aria-label="Lightness and chroma" aria-valuemin={0} aria-valuemax={100} aria-valuenow={70}></div>            </div>            <span className="swatch swatch-lg color-picker-swatch"></span>            <input type="range" className="slider color-picker-hue" min="0" max="360" defaultValue="50" aria-label="Hue" />            <input type="range" className="slider color-picker-alpha" min="0" max="100" defaultValue="100" aria-label="Opacity" />            <div className="color-picker-fields">              <select className="select select-sm color-picker-format" aria-label="Format" defaultValue="hex">                <option value="hex">Hex</option>                <option value="rgb">RGB</option>                <option value="oklch">OKLCH</option>              </select>              <input className="input input-sm color-picker-text" defaultValue="#ff6a00" aria-label="Color" spellCheck="false" autoComplete="off" />            </div>          </div>        </fieldset>        <div className="flex flex-col gap-md min-w(0)">          <fieldset className="gradient-offset">            <legend className="mb(6) text-xs font-medium fg-text-muted">Position</legend>            <input type="range" className="slider" min="0" max="100" step="1" defaultValue="0" aria-label="Position of the stop" />            <input type="number" className="input input-sm w(72)" min="0" max="100" step="1" defaultValue="0" aria-label="Position of the stop, in percent" />          </fieldset>          <fieldset className="gradient-type">            <legend className="mb(6) text-xs font-medium fg-text-muted">Type</legend>            <div className="segmented segmented-sm" role="radiogroup" aria-label="Type">              <label className="segmented-item">                <input type="radio" className="segmented-input" name="sunrise-type" value="linear" defaultChecked />Linear              </label>              <label className="segmented-item">                <input type="radio" className="segmented-input" name="sunrise-type" value="radial" />Radial              </label>              <label className="segmented-item">                <input type="radio" className="segmented-input" name="sunrise-type" value="conic" />Conic              </label>            </div>          </fieldset>          <div className="flex flex-wrap items-start gap-lg">            <fieldset className="gradient-angle">              <legend className="mb(6) text-xs font-medium fg-text-muted">Angle</legend>              <div className="dial dial-sm dial-full" role="slider" tabIndex={0} aria-label="Angle" aria-valuenow={135} aria-valuemin={0} aria-valuemax={360} aria-valuetext="135°" style={{ '--dial-value': '135' } as React.CSSProperties}>                <span className="dial-value">135°</span>                <span className="dial-thumb"></span>              </div>            </fieldset>            <fieldset className="gradient-center">              <legend className="mb(6) text-xs font-medium fg-text-muted">Center</legend>              <input type="number" className="input input-sm w(72)" min="0" max="100" defaultValue="50" aria-label="Center across, in percent" />              <input type="number" className="input input-sm w(72)" min="0" max="100" defaultValue="50" aria-label="Center down, in percent" />            </fieldset>          </div>        </div>      </div>      <pre className="code-block gradient-css" role="region" tabIndex={0} aria-label="The gradient as CSS">{``}</pre>    </div>  )}
<script>  import { attach, gradient } from '@master/ui/behaviors'  import PlusIcon from '@master/icons-svelte/native/16/soft/plus'  import MinusIcon from '@master/icons-svelte/native/16/soft/minus'  import FlipHorizontalIcon from '@master/icons-svelte/native/16/soft/flip-horizontal'  function mounted(root) {    const detach = [      attach(root),      gradient(document.getElementById('sunrise'), { value: { type: 'linear', angle: 135, center: [50, 50], stops: [        { id: 'dawn', offset: 0, color: '#ff6a00' },        { id: 'noon', offset: 55, color: '#ee0979' },        { id: 'dusk', offset: 100, color: '#4f46e5' }      ] } }),    ]    return () => detach.forEach(stop => stop())  }</script><div class="gradient max-w(640) mx-auto" id="sunrise" role="group" aria-label="Background gradient" style="--gradient-ratio: 3 / 1" {@attach mounted}>  <div class="gradient-preview" aria-hidden="true"></div>  <div class="gradient-bar"></div>  <div class="flex flex-wrap items-center gap-xs">    <button type="button" class="btn btn-sm gradient-add">      <PlusIcon class="icon" />Add a stop    </button>    <button type="button" class="btn btn-sm gradient-remove">      <MinusIcon class="icon" />Remove    </button>    <button type="button" class="btn btn-sm btn-quiet gradient-reverse">      <FlipHorizontalIcon class="icon" />Reverse    </button>  </div>  <div class="gradient-fields">    <fieldset class="gradient-color">      <legend class="mb(6) text-xs font-medium fg-text-muted">Color of the stop</legend>      <div class="color-picker" style="--color-picker-lightness: .7; --color-picker-chroma: .19; --color-picker-hue: 50">        <div class="color-picker-area">          <div class="color-picker-thumb" role="slider" tabindex="0" aria-label="Lightness and chroma" aria-valuemin="0" aria-valuemax="100" aria-valuenow="70"></div>        </div>        <span class="swatch swatch-lg color-picker-swatch"></span>        <input type="range" class="slider color-picker-hue" min="0" max="360" value="50" aria-label="Hue">        <input type="range" class="slider color-picker-alpha" min="0" max="100" value="100" aria-label="Opacity">        <div class="color-picker-fields">          <select class="select select-sm color-picker-format" aria-label="Format">            <option value="hex" selected>Hex</option>            <option value="rgb">RGB</option>            <option value="oklch">OKLCH</option>          </select>          <input class="input input-sm color-picker-text" value="#ff6a00" aria-label="Color" spellcheck="false" autocomplete="off">        </div>      </div>    </fieldset>    <div class="flex flex-col gap-md min-w(0)">      <fieldset class="gradient-offset">        <legend class="mb(6) text-xs font-medium fg-text-muted">Position</legend>        <input type="range" class="slider" min="0" max="100" step="1" value="0" aria-label="Position of the stop">        <input type="number" class="input input-sm w(72)" min="0" max="100" step="1" value="0" aria-label="Position of the stop, in percent">      </fieldset>      <fieldset class="gradient-type">        <legend class="mb(6) text-xs font-medium fg-text-muted">Type</legend>        <div class="segmented segmented-sm" role="radiogroup" aria-label="Type">          <label class="segmented-item">            <input type="radio" class="segmented-input" name="sunrise-type" value="linear" checked>Linear          </label>          <label class="segmented-item">            <input type="radio" class="segmented-input" name="sunrise-type" value="radial">Radial          </label>          <label class="segmented-item">            <input type="radio" class="segmented-input" name="sunrise-type" value="conic">Conic          </label>        </div>      </fieldset>      <div class="flex flex-wrap items-start gap-lg">        <fieldset class="gradient-angle">          <legend class="mb(6) text-xs font-medium fg-text-muted">Angle</legend>          <div class="dial dial-sm dial-full" role="slider" tabindex="0" aria-label="Angle" aria-valuenow="135" aria-valuemin="0" aria-valuemax="360" aria-valuetext="135°" style="--dial-value: 135">            <span class="dial-value">135°</span>            <span class="dial-thumb"></span>          </div>        </fieldset>        <fieldset class="gradient-center">          <legend class="mb(6) text-xs font-medium fg-text-muted">Center</legend>          <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center across, in percent">          <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center down, in percent">        </fieldset>      </div>    </div>  </div>  <pre class="code-block gradient-css" role="region" tabindex="0" aria-label="The gradient as CSS"></pre></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach, gradient } from '@master/ui/behaviors'import PlusIcon from '@master/icons-vue/native/16/soft/plus'import MinusIcon from '@master/icons-vue/native/16/soft/minus'import FlipHorizontalIcon from '@master/icons-vue/native/16/soft/flip-horizontal'const root = ref(null)let detach = []onMounted(() => {  detach = [    attach(root.value),    gradient(document.getElementById('sunrise'), { value: { type: 'linear', angle: 135, center: [50, 50], stops: [      { id: 'dawn', offset: 0, color: '#ff6a00' },      { id: 'noon', offset: 55, color: '#ee0979' },      { id: 'dusk', offset: 100, color: '#4f46e5' }    ] } }),  ]})onUnmounted(() => detach.forEach(stop => stop()))</script><template>  <div ref="root" class="gradient max-w(640) mx-auto" id="sunrise" role="group" aria-label="Background gradient" style="--gradient-ratio: 3 / 1">    <div class="gradient-preview" aria-hidden="true"></div>    <div class="gradient-bar"></div>    <div class="flex flex-wrap items-center gap-xs">      <button type="button" class="btn btn-sm gradient-add">        <PlusIcon class="icon" />Add a stop      </button>      <button type="button" class="btn btn-sm gradient-remove">        <MinusIcon class="icon" />Remove      </button>      <button type="button" class="btn btn-sm btn-quiet gradient-reverse">        <FlipHorizontalIcon class="icon" />Reverse      </button>    </div>    <div class="gradient-fields">      <fieldset class="gradient-color">        <legend class="mb(6) text-xs font-medium fg-text-muted">Color of the stop</legend>        <div class="color-picker" style="--color-picker-lightness: .7; --color-picker-chroma: .19; --color-picker-hue: 50">          <div class="color-picker-area">            <div class="color-picker-thumb" role="slider" tabindex="0" aria-label="Lightness and chroma" aria-valuemin="0" aria-valuemax="100" aria-valuenow="70"></div>          </div>          <span class="swatch swatch-lg color-picker-swatch"></span>          <input type="range" class="slider color-picker-hue" min="0" max="360" value="50" aria-label="Hue">          <input type="range" class="slider color-picker-alpha" min="0" max="100" value="100" aria-label="Opacity">          <div class="color-picker-fields">            <select class="select select-sm color-picker-format" aria-label="Format">              <option value="hex" selected>Hex</option>              <option value="rgb">RGB</option>              <option value="oklch">OKLCH</option>            </select>            <input class="input input-sm color-picker-text" value="#ff6a00" aria-label="Color" spellcheck="false" autocomplete="off">          </div>        </div>      </fieldset>      <div class="flex flex-col gap-md min-w(0)">        <fieldset class="gradient-offset">          <legend class="mb(6) text-xs font-medium fg-text-muted">Position</legend>          <input type="range" class="slider" min="0" max="100" step="1" value="0" aria-label="Position of the stop">          <input type="number" class="input input-sm w(72)" min="0" max="100" step="1" value="0" aria-label="Position of the stop, in percent">        </fieldset>        <fieldset class="gradient-type">          <legend class="mb(6) text-xs font-medium fg-text-muted">Type</legend>          <div class="segmented segmented-sm" role="radiogroup" aria-label="Type">            <label class="segmented-item">              <input type="radio" class="segmented-input" name="sunrise-type" value="linear" checked>Linear            </label>            <label class="segmented-item">              <input type="radio" class="segmented-input" name="sunrise-type" value="radial">Radial            </label>            <label class="segmented-item">              <input type="radio" class="segmented-input" name="sunrise-type" value="conic">Conic            </label>          </div>        </fieldset>        <div class="flex flex-wrap items-start gap-lg">          <fieldset class="gradient-angle">            <legend class="mb(6) text-xs font-medium fg-text-muted">Angle</legend>            <div class="dial dial-sm dial-full" role="slider" tabindex="0" aria-label="Angle" aria-valuenow="135" aria-valuemin="0" aria-valuemax="360" aria-valuetext="135°" style="--dial-value: 135">              <span class="dial-value">135°</span>              <span class="dial-thumb"></span>            </div>          </fieldset>          <fieldset class="gradient-center">            <legend class="mb(6) text-xs font-medium fg-text-muted">Center</legend>            <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center across, in percent">            <input type="number" class="input input-sm w(72)" min="0" max="100" value="50" aria-label="Center down, in percent">          </fieldset>        </div>      </div>    </div>    <pre class="code-block gradient-css" role="region" tabindex="0" aria-label="The gradient as CSS"></pre>  </div></template>
Drag a stop, or take it in hand and use the arrow keys; switch the type and turn the angle.

#The value

The gradient is a value of four parts:

PartIs
typelinear, radial or conic
angleDegrees, for a linear and a conic gradient
centerTwo percentages, for a radial and a conic gradient
stopsEach with an id that stays with it, an offset from 0 to 100 and a color

A color is written as the color picker writes it, as sRGB in hex with its opacity. gradientCss(value) writes the gradient as CSS, and both the preview and the copied text come from it: interpolated in OKLab where the browser can be told to, after a fallback for where it cannot.

copied.css
background-image: linear-gradient(90deg, #ff6a00 0%, #ee0979 100%);background-image: linear-gradient(in oklab 90deg, #ff6a00 0%, #ee0979 100%);

No CSS is read back: the editor holds the value, and an application stores the value, not the text.

#The stops

  • A stop's handle is a slider of its offset, a disc of its color on the bar. A press takes it in hand and a drag moves it; the arrow keys move it by one, by ten with Shift, and Home and End take it to the ends. The stop in hand is aria-current="true"; it stands a little forward with an ink ring.
  • Stops may cross. A stop moved past another keeps its id and its handle keeps focus; the gradient paints them in the order of their offsets. Two stops at one offset make a hard edge, and keep their order.
  • Adding puts a stop of the color in hand ten points after it, at 100 at most. Removing, with the button or Delete, hands focus to the next stop on the bar, or the one before. Two stops are the least: at two, removing is disabled.
  • Reversing turns the stops round: each offset becomes 100 less itself.

Dragging is never the only way: the offset has a range and a number beside it, and every stop is reached with Tab.

#States

aria-readonly="true" on the root shows a gradient that cannot be changed, and aria-disabled="true" one that is not in use: the handles stay where they are, and the controls are disabled.

#The behavior

app.js
import { gradient, gradientCss } from '@master/ui/behaviors/gradient.js'const editor = gradient(document.querySelector('.gradient'), {  value: { type: 'linear', angle: 90, center: [50, 50], stops: [    { id: 'from', offset: 0, color: '#ff6a00' },    { id: 'to', offset: 100, color: '#ee0979' },  ] },})editor.value                     // the value as abovegradientCss(editor.value).text   // the two lines to copy

The reader's moves dispatch input while they go on and change when they end; setting value shows another gradient and dispatches nothing. The behavior writes the handles from the value, so a framework that writes them itself gives draw. It publishes the gradient as --gradient and --gradient-fallback on the root, and each stop as --gradient-offset and --gradient-color on its handle: what the editor paints is its content, and the stylesheet places it.

#Keyboard

KeysAction
TabMoves to the stop in hand on the bar, then through the controls; the other stops are reached by taking them in hand with the pointer or from their place in the tab order of the bar
ArrowRight, ArrowUpOn a stop: moves it one point toward the end; ten with Shift. ArrowRight goes left where the page runs right to left
ArrowLeft, ArrowDownOn a stop: moves it one point toward the start; ten with Shift
PageUp, PageDownOn a stop: moves it ten points
Home, EndOn a stop: moves it to 0 or to 100
Delete, BackspaceOn a stop: removes it while there are more than two, and hands focus to its neighbor

#Accessibility

  • Each handle is named with its place among the stops and says its offset and its color in aria-valuetext.
  • The preview is a picture of the value: hide it from assistive technology, since the stops and the CSS say the same.
  • In forced colors the gradient keeps its own colors, since they are its content, and the handles and the bar are outlined in system colors.

#React, Svelte and Vue

The gradient component writes the handles and the controls from the value and attaches the behavior. Copy it into the project with npx master-ui add gradient; React, Svelte and Vue says how the components are built and used.

ui/gradient.tsx
'use client'import { useId, useState, type ComponentProps, type CSSProperties } from 'react'import { colorPickerState } from '@master/ui/behaviors/color-picker.js'import { gradient, gradientCss, gradientStops, gradientValue, type GradientValue } from '@master/ui/behaviors/gradient.js'import { useBehavior } from './use-behavior'export type { GradientValue }/** What the controls are called, in the page's words. */export interface GradientLabels {  add?: string  remove?: string  reverse?: string  color?: string  position?: string  type?: string  linear?: string  radial?: string  conic?: string  angle?: string  center?: string  centerX?: string  centerY?: string  css?: string}export interface GradientProps extends Omit<ComponentProps<'div'>, 'defaultValue' | 'children' | 'ref'> {  value?: GradientValue  defaultValue?: GradientValue  onValueChange?: (value: GradientValue) => void  /** The gradient is shown and cannot be changed. */  readOnly?: boolean  disabled?: boolean  labels?: GradientLabels}const icon = (...paths: string[]) => <svg className="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">{paths.map(d => <path key={d} d={d} />)}</svg>/** * A gradient editor. React writes the controls and a handle for each stop from the value, so the first HTML * holds the gradient; the behavior moves every state and asks for the stops again when they change. */export function Gradient({ value, defaultValue, onValueChange, readOnly, disabled, labels = {}, className, style, ...root }: GradientProps) {  const id = useId()  const [first] = useState(() => gradientValue(value ?? defaultValue))  const [shown, setShown] = useState(first)  const words = { add: 'Add a stop', remove: 'Remove', reverse: 'Reverse', color: 'Color of the stop', position: 'Position', type: 'Type', linear: 'Linear', radial: 'Radial', conic: 'Conic', angle: 'Angle', center: 'Centre', centerX: 'Centre across, in percent', centerY: 'Centre down, in percent', css: 'The gradient as CSS', ...labels }  const ref = useBehavior(gradient, { value: first, draw: setShown }, { value, defaultValue, onValueChange })  const css = gradientCss(first)  const color = colorPickerState(first.stops[0]!.color)!  return (    <div className={className ? `gradient ${className}` : 'gradient'} ref={ref} aria-readonly={readOnly || undefined} aria-disabled={disabled || undefined} style={{ '--gradient': css.css, '--gradient-fallback': css.fallback, ...style } as CSSProperties} {...root}>      <div className="gradient-preview" aria-hidden="true" />      <div className="gradient-bar">        {gradientStops(shown.stops).map((stop, index, all) => (          <span className="gradient-stop" role="slider" data-id={stop.id} aria-label={`Stop ${index + 1} of ${all.length}`} aria-valuemin={0} aria-valuemax={100} aria-valuenow={stop.offset} style={{ '--gradient-offset': stop.offset, '--gradient-color': stop.color } as CSSProperties} key={stop.id} />        ))}      </div>      <div className="flex flex-wrap items-center gap-xs">        <button type="button" className="btn btn-sm gradient-add">{icon('M3 8L13 8', 'M8 3L8 13')}{words.add}</button>        <button type="button" className="btn btn-sm gradient-remove">{icon('M3 8L13 8')}{words.remove}</button>        <button type="button" className="btn btn-sm btn-quiet gradient-reverse">{icon('M8 1.6667L8 14.3333', 'M5.6667 6.3298L5.6667 11.45A0.55 0.55 0 0 1 5.1167 12L2.5566 12A0.55 0.55 0 0 1 2.0647 11.204L4.6248 6.0839A0.55 0.55 0 0 1 5.6667 6.3298Z', 'M10.3333 6.3298L10.3333 11.45A0.55 0.55 0 0 0 10.8833 12L13.4434 12A0.55 0.55 0 0 0 13.9353 11.204L11.3752 6.0839A0.55 0.55 0 0 0 10.3333 6.3298Z')}{words.reverse}</button>      </div>      <div className="gradient-fields">        <fieldset className="gradient-color">          <legend className="mb(6) text-xs font-medium fg-text-muted">{words.color}</legend>          <div className="color-picker" style={color.properties as CSSProperties}>            <div className="color-picker-area">              <div className="color-picker-thumb" role="slider" tabIndex={0} aria-label="Lightness and chroma" aria-valuemin={0} aria-valuemax={100} aria-valuenow={color.valueNow} aria-valuetext={color.valueText} />            </div>            <span className="swatch swatch-lg color-picker-swatch" />            <input type="range" className="slider color-picker-hue" min={0} max={360} defaultValue={color.hue} aria-label="Hue" />            <input type="range" className="slider color-picker-alpha" min={0} max={100} defaultValue={color.alpha * 100} aria-label="Opacity" />            <div className="color-picker-fields">              <select className="select select-sm color-picker-format" defaultValue="hex" aria-label="Format">                <option value="hex">Hex</option>                <option value="rgb">RGB</option>                <option value="oklch">OKLCH</option>              </select>              <input className="input input-sm color-picker-text" defaultValue={color.value} aria-label={words.color} spellCheck={false} autoComplete="off" />            </div>          </div>        </fieldset>        <div className="flex flex-col gap-md min-w(0)">          <fieldset className="gradient-offset">            <legend className="mb(6) text-xs font-medium fg-text-muted">{words.position}</legend>            <input type="range" className="slider" min={0} max={100} step={1} defaultValue={first.stops[0]!.offset} aria-label={words.position} />            <input type="number" className="input input-sm w(72)" min={0} max={100} step={0.1} defaultValue={first.stops[0]!.offset} aria-label={`${words.position}, %`} />          </fieldset>          <fieldset className="gradient-type">            <legend className="mb(6) text-xs font-medium fg-text-muted">{words.type}</legend>            <div className="segmented segmented-sm" role="radiogroup" aria-label={words.type}>              {(['linear', 'radial', 'conic'] as const).map(type => (                <label className="segmented-item" key={type}><input type="radio" className="segmented-input" name={`${id}type`} value={type} defaultChecked={first.type === type} />{words[type]}</label>              ))}            </div>          </fieldset>          <div className="flex flex-wrap items-start gap-lg">            <fieldset className="gradient-angle">              <legend className="mb(6) text-xs font-medium fg-text-muted">{words.angle}</legend>              <div className="dial dial-sm dial-full" role="slider" tabIndex={0} aria-label={words.angle} aria-valuenow={first.angle} aria-valuemin={0} aria-valuemax={360} aria-valuetext={`${first.angle}°`} style={{ '--dial-value': first.angle } as CSSProperties}>                <span className="dial-value">{`${first.angle}°`}</span>                <span className="dial-thumb" />              </div>            </fieldset>            <fieldset className="gradient-center">              <legend className="mb(6) text-xs font-medium fg-text-muted">{words.center}</legend>              <input type="number" className="input input-sm w(72)" min={0} max={100} defaultValue={first.center[0]} aria-label={words.centerX} />              <input type="number" className="input input-sm w(72)" min={0} max={100} defaultValue={first.center[1]} aria-label={words.centerY} />            </fieldset>          </div>        </div>      </div>      <pre className="code-block gradient-css" aria-label={words.css}>{css.text}</pre>    </div>  )}
ui/Gradient.svelte
<script lang="ts" module>  import type { HTMLAttributes } from 'svelte/elements'  import type { GradientValue } from '@master/ui/behaviors/gradient.js'  export type { GradientValue }  /** What the controls are called, in the page's words. */  export interface GradientLabels {    add?: string    remove?: string    reverse?: string    color?: string    position?: string    type?: string    linear?: string    radial?: string    conic?: string    angle?: string    center?: string    centerX?: string    centerY?: string    css?: string  }  export interface GradientProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {    /** The gradient. Bind it, or leave it out: two stops, black to white. */    value?: GradientValue    onValueChange?: (value: GradientValue) => void    /** The gradient is shown and cannot be changed. */    readOnly?: boolean    disabled?: boolean    labels?: GradientLabels  }</script><script lang="ts">  import { untrack } from 'svelte'  import { colorPickerState } from '@master/ui/behaviors/color-picker.js'  import { gradient, gradientCss, gradientStops, gradientValue } from '@master/ui/behaviors/gradient.js'  import { behavior } from './behavior.svelte.js'  let { value = $bindable(), onValueChange, readOnly, disabled, labels = {}, class: className, style, ...root }: GradientProps = $props()  const id = $props.id()  const first = untrack(() => gradientValue(value))  let shown = $state(first)  const words = $derived({ add: 'Add a stop', remove: 'Remove', reverse: 'Reverse', color: 'Color of the stop', position: 'Position', type: 'Type', linear: 'Linear', radial: 'Radial', conic: 'Conic', angle: 'Angle', center: 'Centre', centerX: 'Centre across, in percent', centerY: 'Centre down, in percent', css: 'The gradient as CSS', ...labels })  const css = gradientCss(first)  // Svelte writes a style again whenever its owner changes it, so it writes the gradient the behavior holds.  const painted = $derived(gradientCss(shown))  const color = colorPickerState(first.stops[0]!.color)!  const attach = behavior(gradient, () => ({ value: first, draw: (next: GradientValue) => { shown = next } }), {    value: () => value,    change: (next) => { value = next; onValueChange?.(next) },  })  const types = ['linear', 'radial', 'conic'] as const  const pickerStyle = Object.entries(color.properties).map(([name, text]) => `${name}: ${text}`).join('; ')</script><!--  @component  A gradient editor. Svelte writes the controls and a handle for each stop from the value, so the first HTML  holds the gradient; the behavior moves every state and asks for the stops again when they change.--><div class={['gradient', className]} aria-readonly={readOnly || undefined} aria-disabled={disabled || undefined} {style} style:--gradient={painted.css} style:--gradient-fallback={painted.fallback} {@attach attach} {...root}>  <div class="gradient-preview" aria-hidden="true"></div>  <div class="gradient-bar">    {#each gradientStops(shown.stops) as stop, index (stop.id)}      <span class="gradient-stop" role="slider" data-id={stop.id} aria-label="Stop {index + 1} of {shown.stops.length}" aria-valuemin={0} aria-valuemax={100} aria-valuenow={stop.offset} style="--gradient-offset: {stop.offset}; --gradient-color: {stop.color}"></span>    {/each}  </div>  <div class="flex flex-wrap items-center gap-xs">    <button type="button" class="btn btn-sm gradient-add"><svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 8L13 8" /><path d="M8 3L8 13" /></svg>{words.add}</button>    <button type="button" class="btn btn-sm gradient-remove"><svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 8L13 8" /></svg>{words.remove}</button>    <button type="button" class="btn btn-sm btn-quiet gradient-reverse"><svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 1.6667L8 14.3333" /><path d="M5.6667 6.3298L5.6667 11.45A0.55 0.55 0 0 1 5.1167 12L2.5566 12A0.55 0.55 0 0 1 2.0647 11.204L4.6248 6.0839A0.55 0.55 0 0 1 5.6667 6.3298Z" /><path d="M10.3333 6.3298L10.3333 11.45A0.55 0.55 0 0 0 10.8833 12L13.4434 12A0.55 0.55 0 0 0 13.9353 11.204L11.3752 6.0839A0.55 0.55 0 0 0 10.3333 6.3298Z" /></svg>{words.reverse}</button>  </div>  <div class="gradient-fields">    <fieldset class="gradient-color">      <legend class="mb(6) text-xs font-medium fg-text-muted">{words.color}</legend>      <div class="color-picker" style={pickerStyle}>        <div class="color-picker-area">          <div class="color-picker-thumb" role="slider" tabindex="0" aria-label="Lightness and chroma" aria-valuemin={0} aria-valuemax={100} aria-valuenow={color.valueNow} aria-valuetext={color.valueText}></div>        </div>        <span class="swatch swatch-lg color-picker-swatch"></span>        <input type="range" class="slider color-picker-hue" min="0" max="360" value={color.hue} aria-label="Hue" />        <input type="range" class="slider color-picker-alpha" min="0" max="100" value={color.alpha * 100} aria-label="Opacity" />        <div class="color-picker-fields">          <select class="select select-sm color-picker-format" aria-label="Format">            <option value="hex" selected>Hex</option>            <option value="rgb">RGB</option>            <option value="oklch">OKLCH</option>          </select>          <input class="input input-sm color-picker-text" value={color.value} aria-label={words.color} spellcheck="false" autocomplete="off" />        </div>      </div>    </fieldset>    <div class="flex flex-col gap-md min-w(0)">      <fieldset class="gradient-offset">        <legend class="mb(6) text-xs font-medium fg-text-muted">{words.position}</legend>        <input type="range" class="slider" min="0" max="100" step="1" value={first.stops[0]!.offset} aria-label={words.position} />        <input type="number" class="input input-sm w(72)" min="0" max="100" step="0.1" value={first.stops[0]!.offset} aria-label="{words.position}, %" />      </fieldset>      <fieldset class="gradient-type">        <legend class="mb(6) text-xs font-medium fg-text-muted">{words.type}</legend>        <div class="segmented segmented-sm" role="radiogroup" aria-label={words.type}>          {#each types as type (type)}            <label class="segmented-item"><input type="radio" class="segmented-input" name="{id}type" value={type} checked={first.type === type} />{words[type]}</label>          {/each}        </div>      </fieldset>      <div class="flex flex-wrap items-start gap-lg">        <fieldset class="gradient-angle">          <legend class="mb(6) text-xs font-medium fg-text-muted">{words.angle}</legend>          <div class="dial dial-sm dial-full" role="slider" tabindex="0" aria-label={words.angle} aria-valuenow={first.angle} aria-valuemin={0} aria-valuemax={360} aria-valuetext="{first.angle}°" style="--dial-value: {first.angle}">            <span class="dial-value">{first.angle}°</span>            <span class="dial-thumb"></span>          </div>        </fieldset>        <fieldset class="gradient-center">          <legend class="mb(6) text-xs font-medium fg-text-muted">{words.center}</legend>          <input type="number" class="input input-sm w(72)" min="0" max="100" value={first.center[0]} aria-label={words.centerX} />          <input type="number" class="input input-sm w(72)" min="0" max="100" value={first.center[1]} aria-label={words.centerY} />        </fieldset>      </div>    </div>  </div>  <pre class="code-block gradient-css" aria-label={words.css}>{css.text}</pre></div>
ui/Gradient.vue
<script lang="ts">import type { GradientValue } from '@master/ui/behaviors/gradient.js'export type { GradientValue }/** What the controls are called, in the page's words. */export interface GradientLabels {  add?: string  remove?: string  reverse?: string  color?: string  position?: string  type?: string  linear?: string  radial?: string  conic?: string  angle?: string  center?: string  centerX?: string  centerY?: string  css?: string}</script><script setup lang="ts">import { computed, shallowRef, useId, useTemplateRef } from 'vue'import { colorPickerState } from '@master/ui/behaviors/color-picker.js'import { gradient, gradientCss, gradientStops, gradientValue } from '@master/ui/behaviors/gradient.js'import { useBehavior } from './use-behavior'defineOptions({ inheritAttrs: false })const { readOnly, disabled, labels = {} } = defineProps<{  /** The gradient is shown and cannot be changed. */  readOnly?: boolean  disabled?: boolean  labels?: GradientLabels}>()/** The gradient: `v-model`. Two stops, black to white, by default. */const model = defineModel<GradientValue>()/* * A gradient editor. Vue writes the controls and a handle for each stop from the value, so the first HTML holds * the gradient; the behavior moves every state and asks for the stops again when they change. */const id = useId()const first = gradientValue(model.value)const shown = shallowRef<GradientValue>(first)const words = computed(() => ({ add: 'Add a stop', remove: 'Remove', reverse: 'Reverse', color: 'Color of the stop', position: 'Position', type: 'Type', linear: 'Linear', radial: 'Radial', conic: 'Conic', angle: 'Angle', center: 'Centre', centerX: 'Centre across, in percent', centerY: 'Centre down, in percent', css: 'The gradient as CSS', ...labels }))const css = gradientCss(first)// Vue writes a style again each time it renders, so it writes the gradient the behavior holds, not the first one.const painted = computed(() => gradientCss(shown.value))const color = colorPickerState(first.stops[0]!.color)!const types = ['linear', 'radial', 'conic'] as constconst root = useTemplateRef<HTMLDivElement>('root')useBehavior(root, gradient, () => ({ value: first, draw: (next: GradientValue) => { shown.value = next } }), model)</script><template>  <div class="gradient" ref="root" :aria-readonly="readOnly || undefined" :aria-disabled="disabled || undefined" :style="{ '--gradient': painted.css, '--gradient-fallback': painted.fallback }" v-bind="$attrs">    <div class="gradient-preview" aria-hidden="true"></div>    <div class="gradient-bar">      <span v-for="(stop, index) in gradientStops(shown.stops)" :key="stop.id" class="gradient-stop" role="slider" :data-id="stop.id" :aria-label="`Stop ${index + 1} of ${shown.stops.length}`" :aria-valuemin="0" :aria-valuemax="100" :aria-valuenow="stop.offset" :style="{ '--gradient-offset': stop.offset, '--gradient-color': stop.color }"></span>    </div>    <div class="flex flex-wrap items-center gap-xs">      <button type="button" class="btn btn-sm gradient-add"><svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 8L13 8" /><path d="M8 3L8 13" /></svg>{{ words.add }}</button>      <button type="button" class="btn btn-sm gradient-remove"><svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 8L13 8" /></svg>{{ words.remove }}</button>      <button type="button" class="btn btn-sm btn-quiet gradient-reverse"><svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 1.6667L8 14.3333" /><path d="M5.6667 6.3298L5.6667 11.45A0.55 0.55 0 0 1 5.1167 12L2.5566 12A0.55 0.55 0 0 1 2.0647 11.204L4.6248 6.0839A0.55 0.55 0 0 1 5.6667 6.3298Z" /><path d="M10.3333 6.3298L10.3333 11.45A0.55 0.55 0 0 0 10.8833 12L13.4434 12A0.55 0.55 0 0 0 13.9353 11.204L11.3752 6.0839A0.55 0.55 0 0 0 10.3333 6.3298Z" /></svg>{{ words.reverse }}</button>    </div>    <div class="gradient-fields">      <fieldset class="gradient-color">        <legend class="mb(6) text-xs font-medium fg-text-muted">{{ words.color }}</legend>        <div class="color-picker" :style="color.properties">          <div class="color-picker-area">            <div class="color-picker-thumb" role="slider" tabindex="0" aria-label="Lightness and chroma" :aria-valuemin="0" :aria-valuemax="100" :aria-valuenow="color.valueNow" :aria-valuetext="color.valueText"></div>          </div>          <span class="swatch swatch-lg color-picker-swatch"></span>          <input type="range" class="slider color-picker-hue" min="0" max="360" :value.attr="color.hue" aria-label="Hue" />          <input type="range" class="slider color-picker-alpha" min="0" max="100" :value.attr="color.alpha * 100" aria-label="Opacity" />          <div class="color-picker-fields">            <select class="select select-sm color-picker-format" aria-label="Format">              <option value="hex" selected>Hex</option>              <option value="rgb">RGB</option>              <option value="oklch">OKLCH</option>            </select>            <input class="input input-sm color-picker-text" :value.attr="color.value" :aria-label="words.color" spellcheck="false" autocomplete="off" />          </div>        </div>      </fieldset>      <div class="flex flex-col gap-md min-w(0)">        <fieldset class="gradient-offset">          <legend class="mb(6) text-xs font-medium fg-text-muted">{{ words.position }}</legend>          <input type="range" class="slider" min="0" max="100" step="1" :value.attr="first.stops[0]!.offset" :aria-label="words.position" />          <input type="number" class="input input-sm w(72)" min="0" max="100" step="0.1" :value.attr="first.stops[0]!.offset" :aria-label="`${words.position}, %`" />        </fieldset>        <fieldset class="gradient-type">          <legend class="mb(6) text-xs font-medium fg-text-muted">{{ words.type }}</legend>          <div class="segmented segmented-sm" role="radiogroup" :aria-label="words.type">            <label v-for="type in types" :key="type" class="segmented-item"><input type="radio" class="segmented-input" :name="`${id}-type`" :value="type" :checked="first.type === type" />{{ words[type] }}</label>          </div>        </fieldset>        <div class="flex flex-wrap items-start gap-lg">          <fieldset class="gradient-angle">            <legend class="mb(6) text-xs font-medium fg-text-muted">{{ words.angle }}</legend>            <div class="dial dial-sm dial-full" role="slider" tabindex="0" :aria-label="words.angle" :aria-valuenow="first.angle" :aria-valuemin="0" :aria-valuemax="360" :aria-valuetext="`${first.angle}°`" :style="{ '--dial-value': shown.angle }">              <span class="dial-value">{{ first.angle }}°</span>              <span class="dial-thumb"></span>            </div>          </fieldset>          <fieldset class="gradient-center">            <legend class="mb(6) text-xs font-medium fg-text-muted">{{ words.center }}</legend>            <input type="number" class="input input-sm w(72)" min="0" max="100" :value.attr="first.center[0]" :aria-label="words.centerX" />            <input type="number" class="input input-sm w(72)" min="0" max="100" :value.attr="first.center[1]" :aria-label="words.centerY" />          </fieldset>        </div>      </div>    </div>    <pre class="code-block gradient-css" :aria-label="words.css">{{ css.text }}</pre>  </div></template>

#Classes

ClassDescription
gradientThe editor: a preview, a bar of stops and the controls. The gradient behavior writes the stops' handles and publishes the gradient. Mark aria-readonly="true" or aria-disabled="true" on it to keep it from changing
gradient-previewThe gradient over a checkerboard, 16 : 9 unless --gradient-ratio says otherwise; hide it with aria-hidden, since the stops and the CSS say the same
gradient-barThe stops from start to end, whatever the type, as a short well the handles stand on
gradient-stopA stop's handle, written by the behavior: a disc of its color in a pearl ring at --gradient-offset along the bar, a slider of the offset named with its place among the stops
gradient-fieldsThe controls, in one column, and two side by side when the room allows
gradient-colorHolds the color-picker of the stop in hand; the gradient behavior attaches the picker
gradient-offsetHolds a range and a number input, from 0 to 100, for the offset of the stop in hand
gradient-typeHolds the radios, linear, radial and conic, that choose the type; a segmented control
gradient-angleHolds a dial of the angle, from 0 to 360 degrees, for a linear and a conic gradient
gradient-centerHolds two number inputs, the centre's x and y in percent, for a radial and a conic gradient
gradient-addAdds a stop of the color in hand ten points after it, 100 at most
gradient-removeRemoves the stop in hand; disabled at two stops
gradient-reverseTurns the stops round
gradient-cssThe gradient as CSS to copy, written by the behavior: the fallback, then the line interpolated in OKLab

#Custom properties

PropertyDefaultDescription
--gradientnoneThe gradient interpolated in OKLab, written by the behavior
--gradient-fallbacknoneThe gradient interpolated in sRGB, for a browser that cannot be told how to interpolate
--gradient-barThe bar's paint: every stop from start to end as a straight gradient in sRGB, whatever the type, written by the behaviorSet on gradient
--gradient-ratioThe preview's shape; 16 / 9 by defaultSet on gradient-preview
--gradient-offsetWhere a handle stands along the bar, from 0 to 100, written by the behaviorSet on gradient-stop
--gradient-colorThe color of a handle's stop, written by the behaviorSet on gradient-stop

#Source

@master/ui/components/gradient.css
/* * Gradient: a gradient being made. A preview of it, a bar of its stops, and the controls of the stop in hand and * of the whole gradient, which are the library's own: a color picker, a range and a number, a segmented * control for the type, a dial for the angle, numbers for the centre. * * What the gradient looks like is its content, not a material: the gradient behavior publishes it as * --gradient (interpolated in OKLab) and --gradient-fallback on the root, and each stop's place and color as * --gradient-offset and --gradient-color on its handle. The stylesheet paints the preview and the bar from * them over a checkerboard, so a stop's opacity shows, and places each handle along the bar. * * The bar is a short pressed track as wide as the gradient; a handle is a disc of its stop's color with a * pearl ring, standing on the bar where its stop is, its middle on the stop. The stop in hand rises and takes an * ink ring; a handle the keys are on draws the focus ring as well. Handles keep their place in the DOM as they * move, so the one in hand never loses focus when it passes another. */@layer components.ui {  .gradient {    --gradient: none;    --gradient-fallback: none;    --gradient-handle: 1.25rem;    --gradient-check: color-mix(in oklab, var(--color-text-strong) 9%, transparent);    container: gradient / inline-size;    display: grid;    gap: 1rem;    min-width: 0;    &[aria-disabled="true"] {      opacity: .6;    }  }  /*   * The preview: the gradient on a face with a large control's corner, over a checkerboard, so transparency   * reads as such. Its size is the page's to give; it keeps a 16 : 9 shape by default.   */  .gradient-preview {    aspect-ratio: var(--gradient-ratio, 16 / 9);    min-height: 0;    border-radius: calc(var(--radius-control-lg) * var(--corner-scale));    corner-shape: var(--corner-shape);    background:      var(--gradient-fallback),      repeating-conic-gradient(var(--gradient-check) 0 25%, transparent 0 50%) 0 0 / 16px 16px,      var(--color-surface-raised);    box-shadow: inset 0 0 0 .5px var(--color-line-image-strong);    @supports (background-image: linear-gradient(in oklab, white, black)) {      background:        var(--gradient),        repeating-conic-gradient(var(--gradient-check) 0 25%, transparent 0 50%) 0 0 / 16px 16px,        var(--color-surface-raised);    }    @media (forced-colors: active) {      forced-color-adjust: none;      outline: 1px solid CanvasText;    }  }  /*   * The bar: the stops from start to end, whatever the type, as a short well. The handles stand on it, half   * a handle in from its ends at 0 and 100, so they never hang outside the gradient. Only a handle takes the   * press, so the bar leaves a finger to scroll the page; each handle reaches 44px on touch itself.   */  .gradient-bar {    position: relative;    /* The stop in hand comes forward within the bar, never over the page around it. */    isolation: isolate;    height: .75rem;    margin-inline: calc(var(--gradient-handle) / 2);    border-radius: 999px;    corner-shape: round;    background:      var(--gradient-bar, var(--gradient-fallback)),      repeating-conic-gradient(var(--gradient-check) 0 25%, transparent 0 50%) 0 0 / 8px 8px,      var(--color-surface-raised);    box-shadow: var(--shadow-pressed);    @media (forced-colors: active) {      forced-color-adjust: none;      outline: 1px solid CanvasText;    }  }  /* A stop's handle: a disc of its color in a pearl ring, its middle on the stop. */  .gradient-stop {    position: absolute;    top: 50%;    inset-inline-start: calc(var(--gradient-offset, 0) * 1%);    width: var(--gradient-handle);    height: var(--gradient-handle);    translate: -50% -50%;    border-radius: 999px;    corner-shape: round;    background: linear-gradient(var(--gradient-color, transparent), var(--gradient-color, transparent)), repeating-conic-gradient(var(--gradient-check) 0 25%, transparent 0 50%) 0 0 / 6px 6px, var(--color-surface-raised);    box-shadow: 0 0 0 2px var(--color-thumb-high), 0 0 0 2.5px var(--color-line-strong), 0 1px 3px 1px var(--color-shade-1), 0 2px 6px var(--color-shade-2);    cursor: grab;    touch-action: none;    -webkit-tap-highlight-color: transparent;    transition-property: box-shadow, scale;    transition-duration: var(--duration-quick);    transition-timing-function: var(--easing-glide);    &:dir(rtl) {      translate: 50% -50%;    }    /* The stop in hand stands a little forward, ringed in ink. */    &[aria-current="true"] {      z-index: 1;      scale: 1.12;      box-shadow: 0 0 0 2px var(--color-thumb-high), 0 0 0 3.5px var(--color-text-strong), 0 2px 6px 1px var(--color-shade-1), 0 4px 10px var(--color-shade-2);    }    &:active {      cursor: grabbing;    }    &:focus-visible {      @apply --focus-ring;      outline-offset: 4px;    }    /* Locked: as heavy as :active, and later, so a press shows no grip either. */    &[aria-disabled="true"] {      cursor: not-allowed;    }    /* On touch the target reaches 44px around the handle, which keeps its size. */    @media (pointer: coarse) {      &::after {        @apply --touch-target;      }    }    @media (prefers-reduced-motion: reduce) {      transition-property: box-shadow;      &[aria-current="true"] {        scale: none;      }    }    @media (forced-colors: active) {      forced-color-adjust: none;      outline: 2px solid ButtonText;      &[aria-current="true"] {        outline-color: Highlight;        outline-width: 3px;      }      /* Opted out of forced colors, the focus ring would keep the theme's ink: it takes the system's own. */      &:focus-visible {        outline-color: Highlight;      }      &[aria-disabled="true"] {        outline-color: GrayText;      }    }  }  /*   * The controls: the stop in hand (its color, its offset, remove and add) and the gradient (its type, angle and   * centre, reverse), in a column that becomes two side by side when the room allows.   */  .gradient-fields {    display: grid;    gap: .75rem 1.25rem;    align-items: start;  }  @container gradient (width >= 34rem) {    .gradient-fields {      grid-template-columns: auto minmax(0, 1fr);    }  }  /* A labelled group of the gradient's controls: a row of a label over its control. */  .gradient-color, .gradient-offset, .gradient-type, .gradient-angle, .gradient-center {    display: grid;    gap: .375rem;    min-width: 0;    margin: 0;    padding: 0;    border: 0;  }  .gradient-offset, .gradient-center {    grid-template-columns: minmax(0, 1fr) auto;    align-items: center;  }  .gradient-add, .gradient-remove, .gradient-reverse {    flex: none;  }  /* The CSS of the gradient, as it is copied: the fallback, then the OKLab line. A code block scrolls it. */  .gradient-css {    min-width: 0;    margin: 0;  }}