HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
An RGB color value represents RED, GREEN, and BLUE light sources
In CSS, a color can be specified as an RGB value, using this formula:
rgb(red, green, blue)
Each parameter (red, green, and blue) defines the intensity of the color between 0 and 255.
For example, rgb(255, 0, 0) is displayed as red, because red is set to its highest value (255) and the others are set to 0.
To display black, set all color parameters to 0, like this: rgb(0, 0, 0).
To display white, set all color parameters to 255, like this: rgb(255, 255, 255).
Experiment by mixing the RGB values below:
RED
GREEN
BLUE
Shades of gray are often defined using equal values for all the 3 light sources:
RGBA color values are an extension of RGB color values with an alpha channel - which specifies the opacity for a color.
An RGBA color value is specified with:
rgba(red, green, blue, alpha)
The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (not transparent at all):
Experiment by mixing the RGBA values below:
RED
GREEN
BLUE
ALPHA
//changeRed(255) //changeGreen(0) //changeBlue(0) changeRGB("r"); function changeRGB(x) { var col, r, g, b; r = document.getElementById("slideRed").value; g = document.getElementById("slideGreen").value; b = document.getElementById("slideBlue").value; col = w3color("rgb(" + r + "," + g + "," + b + ")"); document.getElementById('valRed2').innerHTML = r; document.getElementById('valGreen2').innerHTML = g; document.getElementById('valBlue2').innerHTML = b; document.getElementById('rgbresult').style.backgroundColor = col.toRgbString(); document.getElementById('rgbresulttext').innerHTML = col.toRgbString(); if (col.isDark(150)) { document.getElementById('rgbresulttext').style.color = "#ffffff"; } else { document.getElementById('rgbresulttext').style.color = "#1f2d3d"; } } //function changeGreen(value) { // document.getElementById('valGreen').innerHTML = value; //} //function changeBlue(value) { // document.getElementById('valBlue').innerHTML = value; //} changeRGBA("r"); function changeRGBA(x) { var col, r, g, b, a; r = document.getElementById("slideRedA").value; g = document.getElementById("slideGreenA").value; b = document.getElementById("slideBlueA").value; a = document.getElementById("slideAlphaA").value/10; col = w3color("rgba(" + r + "," + g + "," + b + "," + a + ")"); document.getElementById('valRed2A').innerHTML = r; document.getElementById('valGreen2A').innerHTML = g; document.getElementById('valBlue2A').innerHTML = b; document.getElementById('valAlpha2A').innerHTML = a; document.getElementById('rgbaresult').style.backgroundColor = col.toRgbaString(); document.getElementById('rgbaresulttext').innerHTML = col.toRgbaString(); if (col.isDark(150) && a > 0.2) { document.getElementById('rgbaresulttext').style.color = "#ffffff"; } else { document.getElementById('rgbaresulttext').style.color = "#1f2d3d"; } }