RGB and RGBA let you pick colors by mixing red, green, and blue light. RGBA adds transparency so you can see through colors.
RGB and RGBA in CSS
rgb(red, green, blue) rgba(red, green, blue, alpha)
Red, green, and blue values go from 0 to 255.
Alpha in rgba is a number from 0 (fully transparent) to 1 (fully opaque).
background-color: rgb(255, 0, 0);color: rgba(0, 128, 0, 0.5);
border-color: rgb(0, 0, 255);background-color: rgba(255, 165, 0, 0.3);
This page shows three colored boxes. The first uses rgb for a solid red color. The second uses rgba for a green color that is half see-through. The third uses rgba for a blue color that is mostly see-through. Each box has some padding and rounded corners for a neat look.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>RGB and RGBA Example</title> <style> body { font-family: Arial, sans-serif; margin: 2rem; } .box1 { background-color: rgb(255, 0, 0); color: white; padding: 1rem; margin-bottom: 1rem; border-radius: 0.5rem; } .box2 { background-color: rgba(0, 128, 0, 0.5); color: black; padding: 1rem; margin-bottom: 1rem; border-radius: 0.5rem; } .box3 { background-color: rgba(0, 0, 255, 0.3); color: black; padding: 1rem; border-radius: 0.5rem; } </style> </head> <body> <section class="box1" aria-label="Bright red background"> This box has a bright red background using rgb(255, 0, 0). </section> <section class="box2" aria-label="Semi-transparent green background"> This box has a semi-transparent green background using rgba(0, 128, 0, 0.5). </section> <section class="box3" aria-label="Light transparent blue background"> This box has a light transparent blue background using rgba(0, 0, 255, 0.3). </section> </body> </html>
Use rgb when you want solid colors without transparency.
Use rgba when you want to add see-through effects to colors.
Values outside 0-255 for rgb or 0-1 for alpha will be ignored or cause unexpected colors.
RGB mixes red, green, and blue light to create colors.
RGBA adds an alpha value for transparency.
Use these to control colors and see-through effects in your webpage design.