@chriscodesthings/rgba-color-to-css-hex
TypeScript icon, indicating that this package has built-in type declarations

1.1.4 • Public • Published

rgba-color-to-css-hex
Test workflow status NPM Version License: MIT

Converts an RGB or RGBA color to a CSS hex color code

Description

Converts a color given as red, green and blue values to a CSS hex color code.

See...


Install

npm install --save @chriscodesthings/rgba-color-to-css-hex

Usage

import rgbaColorToCSSHex from '@chriscodesthings/rgba-color-to-css-hex';

console.log(rgbaColorToCSSHex([100, 149, 237, 0.5])); // cornflowerblue with 50% transparency
// => #6495ed7f

Types

This package uses types from:

Syntax

rgbaColorToCSSHex([r, g, b, (a)]);

Parameters

  • r, g, b: red, green and blue values in the range 0-255
  • a (optional): alpha value in the range 0-1

Return Value

Returns a string containing a CSS hex color code converted from the RGBA values.

Examples

// from user input
function setBackground(r, g, b) {
    document.body.style.background = rgbaColorToCSSHex([r, g, b]);
} 

See Also...

Readme

Keywords

Package Sidebar

Install

npm i @chriscodesthings/rgba-color-to-css-hex

Weekly Downloads

176

Version

1.1.4

License

MIT

Unpacked Size

9.74 kB

Total Files

8

Last publish

Collaborators

  • chriscodesthings