# color-interpolate

> Pick color from a given color palette by index

Latest version **2.1.1** (published 2026-07-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install color-interpolate
pnpm add color-interpolate
yarn add color-interpolate
bun add color-interpolate
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2026-07-22 |
| First published | 2016-08-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 70 |
| Author | Dmitry Iv |
| Maintainers | dfcreative, dy |
| Keywords | color, interpolate, lerp, interpolate-arrays, interpolation, smootstep, palette, colormap, gradient |

## Links

- npm: https://www.npmjs.com/package/color-interpolate
- Repository: https://github.com/colorjs/color-interpolate
- Homepage: https://github.com/colorjs/color-interpolate#readme
- Issues: https://github.com/colorjs/color-interpolate/issues
- npm.io page: https://npm.io/package/color-interpolate

## Dependencies (1)

- [color-rgba](https://npm.io/package/color-rgba.md) ^3.1.0

## Alternatives

- [postcss-color-hex-alpha](https://npm.io/package/postcss-color-hex-alpha.md) — 6.4M weekly downloads
- [randomcolor](https://npm.io/package/randomcolor.md) — 348.0K weekly downloads
- [bows](https://npm.io/package/bows.md) — 1.3K weekly downloads
- [ep_prefer_color_scheme](https://npm.io/package/ep_prefer_color_scheme.md) — 260 weekly downloads
- [coc-yank](https://npm.io/package/coc-yank.md) — 61 weekly downloads

## Recent versions

- 2.1.1 (latest) — 2026-07-22
- 2.1.0 — 2026-07-22
- 2.0.0 — 2025-05-22
- 1.0.7 — 2025-05-22
- 1.0.6 — 2025-05-21
- 1.0.5 — 2019-10-30
- 1.0.4 — 2018-11-10
- 1.0.3 — 2018-11-10
- 1.0.2 — 2016-08-15
- 1.0.1 — 2016-08-14
- 1.0.0 — 2016-08-14

## README

# color-interpolate [![test](https://github.com/colorjs/color-interpolate/actions/workflows/test.js.yml/badge.svg)](https://github.com/colorjs/color-interpolate/actions/workflows/test.js.yml) [![size](https://img.shields.io/bundlephobia/minzip/color-interpolate?label=size)](https://bundlephobia.com/result?p=color-interpolate) ![stable](https://img.shields.io/badge/stability-stable-green)

For a given palette, return color by any float index. Useful for interpolating colormaps, color palettes or gradients.

## Usage

`$ npm install color-interpolate`

```js
import interpolate from 'color-interpolate';

let colormap = interpolate(['black', 'gray', 'white']);
let black = colormap(0); // 'rgb(0, 0, 0)'
let white = colormap(1); // 'rgb(255, 255, 255)'
let gray = colormap(.5); // 'rgb(128, 128, 128)'
```

## API

### `let palette = interpolate(colors)`

Create interpolator from a list of `colors`. Colors can be any string [color-rgba](https://github.com/colorjs/color-rgba) recognizes — hex, keywords, `rgb()`, `hsl()`, `lab()`, `oklch()`, `color(display-p3 …)` etc. — or an array with channel values, or a number. An unrecognized color throws.

### `let color = palette(index, fn?)`

Get interpolated color from palette by `index` value within `0..1` range. Pass optional `fn` interpolation function, by default [lerp](https://npmjs.org/package/lerp) is used, but [smoothstep](https://npmjs.org/package/smoothstep) can be used as an alternative.

Example:

```js
import palettes from 'nice-color-palettes'
import interpolate from 'color-interpolate'

const palette = interpolate(palettes[32])

let activeColor = palette(.2) // 'rgb(51, 23 47)'
let background = palette(1) // 'rgb(255, 255, 255)'
let foreground = palette(0) // 'rgb(0, 0, 0)'
```

## Credits

Thanks to **[@mattdesl](https://github.com/mattdesl/)** for [interpolation](https://github.com/mattdesl/interpolation) functions and **[@mikkoh](https://github.com/mikkoh/)** for API insight in [interpolation-arrays](https://github.com/jam3/interpolation-arrays).

## Related

> [colormap](https://github.com/bpostlethwaite/colormap) — collection of beautiful colormaps, a good source for palettes.<br/>
> [nice-color-palettes](https://github.com/jam3/nice-color-palettes) — collection of beautiful color palettes from colourlovers.<br/>
> [color-alpha](https://github.com/colorjs/color-alpha) — change alpha of a color string.<br/>
> [color-spectrum](https://github.com/colorjs/color-spectrum) — convert spectrum, like FFT result, to color.<br/>
> [color-space](https://github.com/colorjs/color-space) — collection of color space transforms, useful for custom interpolation modes.<br/>

© Dmitry Iv. MIT License

---
_Source: https://npm.io/package/color-interpolate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
