Create your own complete Web color system fast and easy!

Related tags

Color simpler-color
Overview

Simpler Color

npm build coverage license

Create your own complete Web color system fast and easy, from as little as one base color!

Color is at the heart of every UI design system. A cohesive color system enables your application to:

  • consistently express brand identity and style
  • effectively communicate intent and meaning

Simpler Color makes it super easy to implement your own CSS-compliant color system for any JavaScript/TypeScript project, no matter what platform, framework, or UI library you are using. It works in the browser, server (Node), mobile (React Native) and desktop (Electron).

Easy as 1-2-3!

Step 1: Install Simpler Color

npm install simpler-color

Step 2: Define your color palettes and their corresponding base colors

const baseColors = {
  primary: '#609E3F',
  secondary: '#5D745D',
  neutral: '#5E5F5A',
  ...etc,
}

—OR— just give Simpler Color ONE base color, and it will generate the rest!

import { harmony } from 'simpler-color'

// Generate 5 harmonious base colors from your main brand color!
const baseColors = harmony('#609E3F')

Harmony preset

Step 3: Create your color scheme(s) by mapping UI roles to specific colors from the auto-generated palettes

import { colorScheme } from 'simpler-color'

const scheme = colorScheme(
  baseColors, // 👈 From these base colors...
  // 👇 ...your color palettes are auto-generated
  colors => ({
    // 👇 which you then map to UI roles.
    primaryButton: colors.primary(40),
    primaryButtonText: colors.primary(95),
    surface: colors.neutral(98),
    text: colors.neutral(10),
    ...etc,
  }),
)
// Access various UI colors as `scheme.primaryButton` and so on.

If some of those terms sound alien to you, read on...

BUT FIRST, if you like this library, the concept, and its simplicity, please give it a star ⭐️ on the GitHub repo to let me know. 😀

Key Concepts

We're not gonna discuss Color Theory here, but let's talk a bit about what a proper color system comprises.

Color Palette

Creating your color system begins with building your color palettes. Each palette consists of a group of related colors, generated from one base color.

You decide what sort of relationship should be between colors in the palette. The most common type is the tonal palette (also called monochromatic), which is made up of various "tones" of the same general hue. For example, various shades of green is a tonal palette.

shades of green with varying lightness

Each color in a palette is accessed by a unique color key, which is a string or number that indicates its relationship with the base color. The color values are determined by a color mapping function, which returns a specific color value for a given color key.

Palettes are automatically created by Simpler Color based on your specified base colors. By default, it generates tonal palettes, with specific tones accessed by passing a numeric key between 0 and 100, which represents % lightness (0 = black, 100 = white). Any value in between generates a specific shade of the base color. So, for example, if your primary palette is based on green (like in the illustration above), primary(40) gives you green with 40% lightness.

You can, of course, define your own color mapping function to override the default. This also means that you can define a completely different set of color keys, which can be any of these common alternatives:

  • string values, e.g. 'darker', 'dark', 'base', 'light', 'lighter'
  • discrete numeric values, e.g. 0, 10, 20, ..., 90, 95, 98, 100 (like Material Design 3 does)

Color Set

The color set is simply the collective term for all the color palettes built.

Typically a color set would have a primary palette. This represents the main "brand" color of your app. This is the most prominent hue across your UI.

Common additional palettes can be any of (but not limited to) these:

  • secondary: less prominent, usually more muted
  • accent: usually complementary (opposite) to primary, to provide contrast
  • neutral: typically shades of gray or similar neutral tones
  • error: normally a brilliant red hue, to indicate errors

To ensure consistency of your color set, Simpler Color enforces that you use the same set of color keys (and thus the same color mapping function) across all your palettes.

Color Scheme

A color system consists of one or several color schemes. These days, it's quite common to implement both Light and Dark color schemes. You can also choose to add some High Contrast schemes for accessibility.

To create a color scheme, you first identify the various UI roles in your design system. Each role indicates a specific use or purpose of color as it applies to specific elements of the UI.

Some common examples of UI role:

  • primary button
  • primary button text
  • surface/background color
  • text color

The final step is to map each UI role to a specific color value from one of the palettes in your color set. Each such mapping gives us one color scheme. By using a consistent set of color roles, Simpler Color helps ensure that your UI can easily and safely switch between color schemes.

Recipes

Using the built-in color mapping functions

Color mapping functions are not only used to generate entire palettes, but also to calculate individual colors, such as palette base colors, based on another. This helps you ensure that base colors for your other palettes are "visually harmonious" with your primary palette's.

The format is always fn(baseColor, key) where the valid key values vary depending on the function. They can also be nested to perform more complex calculations.

import { analogue, complement, saturation } from 'simpler-color'

const brandColor = '#336699'
const baseColors = {
  primary: brandColor,
  secondary: analogue(brandColor, 2),
  accent: saturation(complement(brandColor, 1), 80),
}

Below is the description of each of the built-in color mapping functions:

Lightness

lightness scale of green

lightness(baseColor, percentLightness)

Generates a new color value by adjusting the base color's % lightness (the "L" value in HSL color). This is the default color mapping used to generate tonal palettes.

Saturation

saturation scale of green

saturation(baseColor, percentSaturation)

Generates a new color value by adjusting the base color's % saturation (the "S" value in HSL color).

Rotation

rotation scale of green

rotation(baseColor, rotationAngle)

Rotates the hue of the base color by a specified angle around the color wheel. A negative angle reverses the direction of rotation.

Analogue

analogue scale of green

analogue(baseColor, step)

Generates a color that is analogous to the base color. An analogous color is one that is located adjacent to the base color around the color wheel, i.e. at around 30˚ angle. It is visually similar to the base.

This mapping function rotates the hue in steps of 30˚. A negative step value rotates in the opposite direction.

Complement

complementary scale of green

complement(baseColor, step)

Generates a color that is complementary to the base color. A complementary color is one that is located at the opposite side of the color wheel, i.e. at 180˚ angle. This provides excellent color contrast.

This mapping function cycles through multiple sets of "double complementary" hue rotation. The algorithm loops from 1 to step, rotates Hue by 180˚ on every odd iteration, and 30˚ on even. A negative step value rotates in the opposite direction.

Triad

triad scale of green

triad(baseColor, step)

Generates a triadic complementary color to the base color. A triadic palette consists of 3 colors that are equally spaced around the color wheel. Therefore, producing a triadic complementary color means rotating the hue by 120˚ angle. This provides a more subtle contrast.

This mapping function is cyclic. A negative step value rotates in the opposite direction.

Opacity

opacity(baseColor, alpha)

Generates a new color value by adjusting the base color's opacity (the alpha or "A" value in RGBA) between 0 (transparent) and 1 (opaque).

Back to recipes

Defining a custom color mapping function

Although the default color mapping function already gives you great looking tonal palettes, sometimes your color system might require a different approach, such as:

  • a different set of color keys (e.g. strings or discrete numbers)
  • a different formula for calculating colors in your palettes

This is where a custom color mapping function comes in. For example, here is a modified version of the default (lightness) color mapping function that accepts a string for key instead of a number from 0-100.

import { lightness } from 'simpler-color'

function shade(baseColor, key) {
  const lightnessValues = {
    darker: 10,
    dark: 30,
    main: 40,
    light: 60,
    lighter: 80,
  }
  return lightness(baseColor, lightnessValues[key])
}

You can then tell Simpler Color to use this custom color mapping instead of the default:

const uiColors = colorScheme(
  'blue',
  colors => ({
    // notice the color keys used   👇
    primaryButton: colors.primary('main'),
    floatingActionButton: colors.accent('light'),
    navBar: colors.secondary('lighter'),
    ...etc,
  }),
  {
    colorMapping: shade, // 👈 custom color mapping
  },
)

Back to recipes

You might also like...

A CLI utility to calculate/verify accessible magic numbers for a color palette.

A CLI utility to calculate/verify accessible magic numbers for a color palette.

A11y Contrast A CLI utility to calculate/verify accessible magic numbers for a color palette. Read my blog post for some more information. Installatio

Nov 13, 2022

A dependency-free image color extraction library

A dependency-free image color extraction library

Color mage A dependency-free image color extraction library. The extraction consists of using K-Means algorithm. It has a few utility functions as wel

Mar 11, 2022

A array with color name - decimal rgbs.

colors-named-decimal A array with color name - decimal rgbs. Based on https://www.w3.org/TR/css-color-4/#colors-named Installation This package is ES

Jul 20, 2022

O Design System da Impulso Gov apresenta os padrões de interface que devem ser seguidos por designers e desenvolvedores para garantir a experiência única na interação com os sistemas interativos da Impulso Gov.

Design System O Design System da Impulso Gov apresenta os padrões de interface que devem ser seguidos por designers e desenvolvedores para garantir a

May 25, 2022

Node Terminal Colors. Fast!

Tcol npm package to add colors to your terminal Installation # npm npm install tcol # pnpm pnpm install tcol Usage import { c } from "tcol"; console.

May 13, 2022

Smarter defaults for colors on the web.

colors.css 3.0.0 Better default colors for the web. A collection of skin classes for faster prototyping and nicer looking sites. Stats 903 85 85 bytes

Jan 9, 2023

colors.js - get colors in your node.js console

 colors.js - get colors in your node.js console

colors.js Please check out the roadmap for upcoming features and releases. Please open Issues to provide feedback, and check the develop branch for th

Feb 9, 2022

get colors in your node.js console

colors.js This is a fork of Marak Squires' original colors.js project Please check out the roadmap for upcoming features and releases. Please open Iss

Jan 11, 2022

Get colors in your node.js console

Get colors in your node.js console

@colors/colors ("colors.js") Please check out the roadmap for upcoming features and releases. Please open Issues to provide feedback. get color and st

Dec 30, 2022
Comments
  • NPM package is unusable

    NPM package is unusable

    The NPM package, in both /lib and /es, references @babel/runtime, which is a devDependency. I tried importing the package with traditional node JavaScript, ESM, and typescript. They all failed.

    Solution? Run the typescript compiler first, and just export the emitted JavaScript. You can work on ESM compatibility later, but nobody can use it now.

    fix published 
    opened by binyamin 3
Releases(v1.0.0)
  • v1.0.0(May 9, 2022)

  • v0.3.0(Apr 3, 2022)

    Major functions from the new in-house color engine are now exported, to support maximum flexibility in writing custom color-mapping functions.

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Apr 1, 2022)

    Our April 1 release is NOT an April Fool's joke. 😅. It's a milestone release that introduces an in-house color engine built specifically for Simpler Color. We have completely removed dependency on third-party color library.

    Source code(tar.gz)
    Source code(zip)
Owner
Arnel Enero
Arnel Enero
Fast, small color manipulation and conversion for JavaScript

TinyColor JavaScript color tooling TinyColor is a small, fast library for color manipulation and conversion in JavaScript. It allows many forms of inp

Brian Grinstead 4.5k Jan 1, 2023
A tool for creating and maintaining cohesive, consistent, and accessible color palettes

Primer Prism Primer Prism is a tool for creating and maintaining cohesive, consistent, and accessible color palettes. ?? primer.style/prism ?? Read th

Primer 517 Jan 3, 2023
A simple Discord bot that will listen for HEX, RGB(a), and HSL(a) colors in a message, and provide a small image of that color.

Pigment For the teams of designers and developers out there - Pigment will listen for messages containing a HEX, RGB(a), or HSL(a) color, and provide

Conrad Crawford 17 Dec 8, 2022
:rainbow: Javascript color conversion and manipulation library

color JavaScript library for immutable color conversion and manipulation with support for CSS color strings. var color = Color('#7743CE').alpha(0.5).l

Qix 4.5k Jan 3, 2023
JavaScript Library for creating random pleasing colors and color schemes

#PleaseJS www.checkman.io/please Please.js is a polite companion that wants to help you make your projects beautiful. It uses HSV color space to creat

Jordan Checkman 2.3k Dec 22, 2022
Coloris - A lightweight and elegant JavaScript color picker. Written in vanilla ES6, no dependencies. Accessible.

Coloris A lightweight and elegant JavaScript color picker written in vanilla ES6. Convert any text input field into a color field. View demo Features

Momo Bassit 126 Dec 27, 2022
Color2k - a color parsing and manipulation lib served in roughly 2kB

color2k a color parsing and manipulation lib served in roughly 2kB or less (2.8kB to be more precise) color2k is a color parsing and manipulation libr

Rico Kahler 506 Dec 31, 2022
A TypeScript package to calculate WCAG 2.0/3.0 and APCA color contrasts

a11y-color-contrast A simple utility package for working with WCAG 2.2/3.0 color contrasts a11y: Built for checking how readable colors are together S

Sondre Aasemoen 10 Oct 10, 2022
JavaScript library for all kinds of color manipulations

Chroma.js Chroma.js is a tiny small-ish zero-dependency JavaScript library (13.5kB) for all kinds of color conversions and color scales. Usage Initiat

Gregor Aisch 9.2k Jan 4, 2023
A simple color picker application written in pure JavaScript, for modern browsers.

Color Picker A simple color picker application written in pure JavaScript, for modern browsers. Has support for touch events. Touchy… touchy… Demo and

Taufik Nurrohman 207 Dec 14, 2022