Skip to content
color-kitnext
StartAPI
color-kit on GitHub
Start

Concepts

  • OKLCH-canonical
  • Requested vs displayed
  • Planes and queries
  • Gamut and tolerance
  • Contrast

Guides

  • Headless picker
  • React
  • Contrast-aware palettes
  • GPU and three.js
  • Performance

API

  • Overview
  • @pbroom/color-kit
      • ffunctiontoRgb
      • ffunctionfromRgb
      • ffunctiontoHex
      • ffunctionfromHex
      • ffunctiontoHsl
      • ffunctionfromHsl
      • ffunctiontoHsv
      • ffunctionfromHsv
      • ffunctiontoHct
      • ffunctionfromHct
      • ffunctiontoOklab
      • ffunctionfromOklab
      • ffunctiontoOklch
      • ffunctionfromOklch
      • ffunctiontoP3
      • ffunctionfromP3
      • ffunctiontoCss
      • ffunctionparse
      • ffunctiontryParse
      • ffunctionsrgbToLinear
      • ffunctionlinearToSrgb
      • ffunctionrgbToHex
      • ffunctionhexToRgb
      • ffunctionrgbToHsl
      • ffunctionhslToRgb
      • ffunctionrgbToHsv
      • ffunctionhsvToRgb
      • ffunctionlinearRgbToOklab
      • ffunctionoklabToLinearRgb
      • ffunctionoklabToOklch
      • ffunctionoklchToOklab
      • ffunctionoklchToColor
      • ffunctioncolorToOklch
      • ffunctionlinearSrgbToLinearP3
      • ffunctionlinearP3ToLinearSrgb
      • ffunctionlinearP3ToP3
      • ffunctionp3ToLinearP3
      • ffunctiontoOklabInto
      • ffunctionfromOklabInto
      • ffunctiontoLinearSrgbInto
      • ffunctionfromLinearSrgbInto
      • ffunctiontoRgbInto
      • ffunctionfromRgbInto
      • ffunctiontoP3Into
      • ffunctionfromP3Into
      • ffunctionsrgbToLinearInto
      • ffunctionlinearToSrgbInto
      • ffunctionlinearRgbToOklabInto
      • ffunctionoklabToLinearRgbInto
      • ffunctionoklabToOklchInto
      • ffunctionoklchToOklabInto
      • ffunctionlinearSrgbToLinearP3Into
      • ffunctionlinearP3ToLinearSrgbInto
      • ffunctionlinearP3ToP3Into
      • ffunctionp3ToLinearP3Into
      • KconstLINEAR_SRGB_TO_LINEAR_P3
      • KconstLMS_TO_LINEAR_SRGB
      • KconstOKLAB_TO_LMS
      • TtypeCssColorFormat
      • TtypeMatrix3
  • @pbroom/color-kit/plane
  • @pbroom/color-kit/interop
  • @pbroom/color-kit/compute
  • @pbroom/color-kit/hct
  • @pbroom/color-kit/driver
  • @pbroom/color-kit/react
Map

@pbroom/color-kit/Conversion

fromRgb

Convert sRGB (0-255 per channel, fractional values allowed) to a Color.

functionimport { fromRgb } from '@pbroom/color-kit';index.ts:112
function fromRgb(rgb: Rgb): Color;

Parameters

rgbRgb
sRGB color; channels are not clamped

Returns

ColorA new OKLCH Color

Example

TypeScript
import { fromRgb, toCss } from '@pbroom/color-kit';

toCss(fromRgb({ r: 59, g: 130, b: 246, alpha: 1 }), 'oklch');
// → 'oklch(0.6231 0.188 259.81)'

See also

  • toRgb
  • fromRgbInto

Your display: detecting

MIT licensedSource