Color string output
Use css() to write a color to a stylesheet. Choose a specific method like hex() or oklch() when your output needs that format.
Example
import { colore } from 'colore-js';
const blue = colore('#2563eb80');
console.log(blue.hex()); // '#2563eb80'
console.log(blue.rgb()); // 'rgb(37 99 235 / 0.502)'
Syntax
Parameters
These methods take no arguments. For named numeric channels, use Color object output.
Returns
A string. css() uses hex when the color fits sRGB, Display P3 when it fits there, and OKLCH for wider colors. An explicit sRGB format such as hex() clips channels when the color is outside sRGB.
Keep a wide-gamut color in a stylesheet
import { colore } from 'colore-js';
const red = colore('color(display-p3 1 0 0)');
console.log(red.css()); // 'color(display-p3 1.00000 0.00000 0.00000)'
console.log(red.toGamut('srgb').hex()); // '#ff0b0c'
Use the CSS string on a surface that can display P3. Call toGamut('srgb') first when you need a hex fallback that stays closer to the original appearance.
Related
- toCss for a standalone formatter
- toHex for an sRGB hex string
- Gamut and CSS output for the choice between formats