mrkeyoor.com_
Wed 23 Sept 00:35 UTC
npmWeb Frontendupdated 22 Sept 2026

css-color-names review

css-color-names 1.0.1 is one JSON object: 148 lowercase CSS color names mapped to opaque six-digit hex strings. It has no parser, functions, validation rules, alpha values, conversion methods, or TypeScript declarations. The README says its generator scraped a website and then serialized the result, and the published package has remained at 1.0.1 since 2019. Our Node 22 sandbox could require the CommonJS JSON entry, but direct ESM import failed. This is useful as frozen lookup data and a bad choice for deciding whether arbitrary user input is a valid CSS color.

Verdict

Our css-color-names 1.0.1 install took 0.6 seconds and its browser bundle measured 2.4 KB gzipped, but ESM import failed and no TypeScript declarations were present. Keep it for an existing CommonJS name-to-hex lookup; choose a parser for any user-facing CSS color field.

We installed it

Lab card: what happened when we installed css-color-namesScreenshot of css-color-names documentation
Install✓ · 0.6s1 package on disk · 1 MB
Import½ESM import fails · require() works · CommonJS package
Browser2.4 KBgzipped (6.2 KB minified), bundled with esbuild
Typesno TypeScript types found
Known vulns00 critical · 0 high · 0 moderate · 0 low (npm audit)

Answers from our run

Does css-color-names install cleanly?

Yes. In a fresh container with an empty cache, npm install css-color-names finished in 0.6s, leaving 1 package and 1 MB on disk. npm audit reported no known vulnerabilities.

How much does css-color-names add to a browser bundle?

2.4 KB gzipped (6.2 KB minified) when the whole package is bundled for the browser with esbuild. Importing only part of it is usually smaller.

Does css-color-names work with both ESM and CommonJS?

CommonJS only in our run: require('css-color-names') worked but the ESM import failed.

Does css-color-names include TypeScript types?

No type declarations were found in our install, so TypeScript users need their own declarations.

css-color-names or color-name: which should you use?

color-name: Use it when RGB channel arrays fit better than hex strings and you want a more recently maintained table. Our css-color-names 1.0.1 install took 0.6 seconds and its browser bundle measured 2.4 KB gzipped, but ESM import failed and no TypeScript declarations were present.

When should you not use css-color-names?

You accept general CSS color syntax; this table cannot parse hex strings, rgb(), hsl(), lab(), color(), currentColor, custom properties, or transparent

API stability5/5Version 1.0.1 exposes one JSON object and has not changed since February 2019. There are no methods, options, asynchronous paths, dependencies, or peer ranges that can move underneath an application. That frozen surface makes a pinned install predictable, although the repository states no compatibility policy for a future regeneration of the table. Stability here comes from inactivity and a tiny contract, rather than an active release process.
Docs2/5The README accurately shows the CommonJS require call, object shape, install command, MIT license, and the scraping pipeline used to create the file. It omits several facts callers need: there are 148 lowercase keys, duplicate-value aliases exist, transparent and non-name CSS syntax are absent, own-property checks matter, direct Node 22 ESM import fails, and version 1.0.1 contains no TypeScript declarations. The source is easy to inspect, but the guide is too short for modern integration questions.
Maintenance1/5GitHub reports the last repository push on 2019-02-19, and npm still marks 1.0.1 as latest. The repository is unarchived and has 0 open issues and pull requests, but there has been no visible data refresh, release, type addition, provenance change, or toolchain update in more than seven years. A fixed color table does not need weekly commits, yet consumers receive no recent verification that its scraped source still matches the intended CSS list.
Ecosystem3/5The npm endpoint counted 2,935,721 downloads in the latest completed week, while GitHub shows 149 stars. Those figures point to substantial transitive use for a 20 KB data package. The package has no plugin surface, framework wrappers, declarations, or documented integrations, so its ecosystem is compatibility with existing consumers rather than a community of extensions. Modern color packages cover many syntaxes and operations that this object deliberately lacks.

Use it if

  • A CommonJS tool needs a plain name-to-hex object with no runtime API
  • You are building autocomplete, fixtures, a picker, or generated documentation from the 148 stored names
  • Exact compatibility with code already importing this package matters more than standards provenance or active releases
Skip it if

Setup reality

Our install of css-color-names 1.0.1 completed in 0.6 seconds and left 1 package using 1 MB on disk. The package was 20 KB unpacked, with 0 direct dependencies and 0 peer dependencies. npm audit found 0 known vulnerabilities. It is CommonJS without an exports map; require() worked, while direct ESM import failed on Node.js 22.23.2. No TypeScript declarations were present. Our esbuild browser check produced 6.2 KB minified and 2.4 KB gzipped.

There are no credentials, native builds, config files, or initialization calls. Requiring the package returns the JSON object. All keys are lowercase, while CSS names are case-insensitive, so trim and lowercase user input before lookup. Use Object.hasOwn(colors, key) instead of testing colors[key]; inherited properties are not color names.

Every value is an opaque #rrggbb string. transparent is absent, and aliases can share a value, including aqua with cyan and the gray/grey spellings. Reverse lookup therefore returns zero, one, or several names. The package does not choose a canonical alias.

The data arrives as one JSON file and has no per-color exports. Node ESM import failed in our measured environment, and toolchains differ in how they handle a JSON package entry. Test the exact bundler path or use CommonJS interop. For a browser build, the full table cost 2.4 KB gzipped in our sandbox.

Patterns

Read a known color value lookup-name

const colors = require('css-color-names');

console.log(colors.tomato); // #ff6347

Version 1.0.1 exports the JSON object itself, with lowercase keys and lowercase six-digit hex values.

Normalize case before lookup normalize-name

const colors = require('css-color-names');

const key = '  RebeccaPurple '.trim().toLowerCase();
const hex = Object.hasOwn(colors, key) ? colors[key] : null;

CSS names ignore ASCII case, but the 148 stored keys are lowercase and whitespace is not removed by the package.

Reject inherited object properties validate-membership

const colors = require('css-color-names');

function isNamedColor(value) {
  return typeof value === 'string' &&
    Object.hasOwn(colors, value.trim().toLowerCase());
}

console.log(isNamedColor('constructor')); // false

A truthiness lookup is unsafe because the parsed JSON object inherits properties such as `constructor`.

Return a fixed fallback resolve-fallback

const colors = require('css-color-names');

function resolveName(name, fallback = '#000000') {
  const key = String(name).trim().toLowerCase();
  return Object.hasOwn(colors, key) ? colors[key] : fallback;
}

Inputs such as `#fff`, `rgb()`, `transparent`, and CSS variables fall through because this package only stores names.

Build a sorted name list list-names

const colors = require('css-color-names');

const names = Object.keys(colors).sort();
console.log(names.length); // 148

The 148 keys include aliases, so this count exceeds the number of unique hex values.

Find every name for one hex value find-aliases

const colors = require('css-color-names');

function aliasesFor(hex) {
  const target = hex.toLowerCase();
  return Object.entries(colors)
    .filter(([, value]) => value === target)
    .map(([name]) => name);
}
console.log(aliasesFor('#00ffff'));

The result includes both `aqua` and `cyan`; version 1.0.1 does not mark either spelling as canonical.

Split a stored hex value into channels convert-rgb

const colors = require('css-color-names');

function namedRgb(name) {
  const hex = colors[name.toLowerCase()];
  if (!hex) return null;
  return {
    r: parseInt(hex.slice(1, 3), 16),
    g: parseInt(hex.slice(3, 5), 16),
    b: parseInt(hex.slice(5, 7), 16),
  };
}

This works for package values because all are `#rrggbb`; it is not a general CSS color parser.

Add a local CommonJS declaration declare-types

declare module 'css-color-names' {
  const colors: Record<string, `#${string}`>;
  export = colors;
}

The package ships no TypeScript declarations. This local shape does not enumerate the 148 literal keys, so callers still need runtime membership checks.

Alternatives

PackageRegistryPick it when
color-namenpmUse it when RGB channel arrays fit better than hex strings and you want a more recently maintained table.
colordnpmUse it for typed parsing, validation, conversions, alpha values, and optional plugins.
colornpmUse it when code needs a color object with conversion, mixing, lightening, and serialization methods.
parse-colornpmUse it in CommonJS code that must accept several color syntaxes rather than names alone.

More web frontend guides

postcss · react · react-dom · tailwindcss · htmlparser2 · tailwind-merge · the whole shelf →

How this guide is made: grounded in the library's documentation, release notes, changelog, and issue history, on a fixed rubric — not a hands-on install of every release. The 50 most-downloaded entries are additionally install-verified in clean containers. Corrections: contact the desk.