How To Use CSS Hex Code Colors with Alpha Values?

The hue values are used to refer to the amount of red, green, and blue added to the base color. The value can be from 0 up to 255. The closer the number is to white, the more transparent the base color will appear. Conversely, the closer 101 is to 0, the more opaque and saturated the color will become.

white with opacity rgba to hex

By Dead DormouseDead Dormouse on Mar 06, 2021
function hexify(color) {
  var values = color
    .replace(/rgba?\(/, '')
    .replace(/\)/, '')
    .replace(/[\s+]/g, '')
    .split(',');
  var a = parseFloat(values[3] || 1),
      r = Math.floor(a * parseInt(values[0]) + (1 - a) * 255),
      g = Math.floor(a * parseInt(values[1]) + (1 - a) * 255),
      b = Math.floor(a * parseInt(values[2]) + (1 - a) * 255);
  return "#" +
    ("0" + r.toString(16)).slice(-2) +
    ("0" + g.toString(16)).slice(-2) +
    ("0" + b.toString(16)).slice(-2);
}

var myHex = hexify('rgba(255,255,255,0.6)'); // "#f5faf3"

console.log(myHex);

Source: stackoverflow.com

Add Comment

0

Hopefully this article cleared up any confusion and now you know how to properly utilize the CSS rgba function. It's a great function that all designers should be familiar with.

Whatever answers related to "white with opacity rgba to hex"

View All Whatever queries

Whatever queries related to "white with opacity rgba to hex"

Browse Other Code Languages

CodeProZone