Search code examples
htmlcsscolors

How to set CSS RGB colors using numeric values?


I'm in new to HTML/CSS. I can see that there are various ways of setting color code in a CSS style description i.e. by name e.g. yellow or by hex code #ffff00. I see there are also numeric equivalents of each color e.g. yellow has numeric equivalent as 255,255,0 but applying the below style on my body element has no effect at all:

My CSS:

body {
background-color: 255,255,0;
color: black !important;
}

Can someone help me on this?


Solution

  • Like this

    body {
        background-color: rgb(255,255,0);
    }
    

    To add opacity, use rgba. Where 1 is 100% opacity.

    body {
        background-color: rgba(255,255,0, 1);
    }