Categories: CSSScriptWeb Design

Tiny Random Color Generator In JavaScript – randomColor.js

randomColor.js is a plain JavaScript library for generating random colors (rgb, rgba, rgbArray, hsl, hsla, hslArray, or hex) from a specific Hue and Saturation.

The random colors generated from randomColor.js are attractive and beautiful and can be used to colorize backgrounds, create buttons, or really anything that stands out. It takes the guesswork out of creating a nice color scheme for your next project.

Table of Contents

Toggle

How to use it:

1. Install & import the randomColor.js.

# NPM
$ npm i randomcolor
// CommonJS
var randomColor = require('randomcolor');

// CDN
<script src="https://cdn.jsdelivr.net/npm/randomcolor@0.6.2/randomColor.min.js"></script>

2. Generate a random color (hex).

randomColor();
// => #ff0000

3. Specify the number of colors to generate.

randomColor({
  count: 20
});

4. Set the hue of the colors: red, orange, yellow, green, blue, purple, pink, or monochrome.

randomColor({
  hue: 'red',
});

5. Set the luminosity of the colors: bright, light, or dark.

randomColor({
  luminosity: 'dark',
});

6. Set the color format: rgb, rgba, rgbArray, hsl, hsla, hslArray, or hex

randomColor({
  format: 'rgba',
});

7. Set the alpha channel, which specifies the opacity for an RGBA or HSLA color.

randomColor({
  alpha: 0.5,
});

8. Set the seed (seed) that will cause randomColor to return the same color each time.

randomColor({
  seed: 3,
});

Changelog:

v0.6.2 (12/03/2025)

  • Fix the seeded serie
  • refactor: move to ES module
  • Dart port for randomColor
  • Adding Ruby Gem to the list of ports
  • Add Kotlin Port
  • Adding TypeScript Definition
  • Fixing unstable generation from the same seed
  • Rewrote the HexToHSB function
  • fix issue with negative hues

The post Tiny Random Color Generator In JavaScript – randomColor.js appeared first on CSS Script.

rssfeeds-admin

Share
Published by
rssfeeds-admin

Recent Posts

Witnesses report racing before fatal crash at McKinney and Lafayette

FORT WAYNE IND. (WOWO) One man is dead following a fiery early-morning crash at Lafayette…

25 minutes ago

The Hunt for Ben Solo Fan Campaign Takes the Fight to The Mandalorian and Grogu Premiere in Hollywood

The Hunt For Ben Solo fan campaign is still going, and its latest stunt saw…

43 minutes ago

10 Anime Worth Watching This Spring

Daemons, seasonal powers, and giants are what you can expect this spring anime season. There's…

44 minutes ago

This website uses cookies.