Lighten Color

Lighten a hex color by a percentage.

Code

General
const num = parseInt(hex.replace('#', ''), 16);
const amt = Math.round(2.55 * percent);
const R = Math.min(255, (num >> 16) + amt);
const G = Math.min(255, ((num >> 8) & 0x00FF) + amt);
const B = Math.min(255, (num & 0x0000FF) + amt);
return '#' + [R, G, B].map(x => x.toString(16).padStart(2, '0')).join('');

Parameters

The hex color to lighten

Percentage to lighten (0-100)

Browser·fetch() may be limited by CORS

More JavaScript Snippets