Get started with color-hash CDN

MIT licensed

The ColorHash library generates a unique hash code based on given RGB, HEX, HSL, or named color values.

Tags:
  • Color Hash
  • String

Stable version

Copied!

How to start using color-hash CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with color-hash CDN - cdnhub.io</title>
  <script src="https://cdn.cdnhub.io/color-hash/2.0.2/color-hash.js"></script>
</head>
<body>
  <button id="generate">Generate Hash</button>
  <script>
    const generateButton = document.getElementById('generate');
    const colorInput = document.createElement('input');
    colorInput.type = 'color';
    document.body.appendChild(colorInput);

    generateButton.addEventListener('click', () => {
      const color = colorInput.value;
      const hash = ColorHash.hexToRgb(color).map(component => component.toString(16)).join('');
      alert(`The hash for color "${color}" is: #${hash}`);
    });
  </script>
  <style>
    body > input {
      position: fixed;
      top: 0;
      left: 0;
      width: 1px;
      height: 1px;
      margin: -1px;
      padding: 0;
      border: none;
      overflow: hidden;
      clip: rect(0, 0, 0, 0);
    }
  </style>
</body>
</html>
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!

All versions