background-color
Quick Summary for background-color
The background-color CSS property sets the background color of an element.
Code Usage for background-color
/* Keyword values */ background-color: red; background-color: indigo;  /* Hexadecimal value */ background-color: #bbff00;    /* Fully opaque */ background-color: #bf0;       /* Fully opaque shorthand */ background-color: #11ffee00;  /* Fully transparent */ background-color: #1fe0;      /* Fully transparent shorthand  */ background-color: #11ffeeff;  /* Fully opaque */ background-color: #1fef;      /* Fully opaque shorthand  */  /* RGB value */ background-color: rgb(255, 255, 128);        /* Fully opaque */ background-color: rgba(117, 190, 218, 0.5);  /* 50% transparent */  /* HSL value */ background-color: hsl(50, 33%, 25%);         /* Fully opaque */ background-color: hsla(50, 33%, 25%, 0.75);  /* 75% opaque, i.e. 25% transparent */  /* Special keyword values */ background-color: currentcolor; background-color: transparent;  /* Global values */ background-color: inherit; background-color: initial; background-color: revert; background-color: unset; 
More Details for background-color

background-color

The background-color CSS property sets the background color of an element.

Syntax

/* Keyword values */ background-color: red; background-color: indigo;  /* Hexadecimal value */ background-color: #bbff00;    /* Fully opaque */ background-color: #bf0;       /* Fully opaque shorthand */ background-color: #11ffee00;  /* Fully transparent */ background-color: #1fe0;      /* Fully transparent shorthand  */ background-color: #11ffeeff;  /* Fully opaque */ background-color: #1fef;      /* Fully opaque shorthand  */  /* RGB value */ background-color: rgb(255, 255, 128);        /* Fully opaque */ background-color: rgba(117, 190, 218, 0.5);  /* 50% transparent */  /* HSL value */ background-color: hsl(50, 33%, 25%);         /* Fully opaque */ background-color: hsla(50, 33%, 25%, 0.75);  /* 75% opaque, i.e. 25% transparent */  /* Special keyword values */ background-color: currentcolor; background-color: transparent;  /* Global values */ background-color: inherit; background-color: initial; background-color: revert; background-color: unset; 

The background-color property is specified as a single <color> value.

Values

<color>

The uniform color of the background. It is rendered behind any background-image that is specified, although the color will still be visible through any transparency in the image.

Accessibility concerns

It is important to ensure that the contrast ratio between the background color and the color of the text placed over it is high enough that people experiencing low vision conditions will be able to read the content of the page.

Color contrast ratio is determined by comparing the luminance of the text and background color values. In order to meet current Web Content Accessibility Guidelines (WCAG), a ratio of 4.5:1 is required for text content and 3:1 for larger text such as headings. Large text is defined as 18.66px and bold or larger, or 24px or larger.

WebAIM: Color Contrast Checker MDN Understanding WCAG, Guideline 1.4 explanations Understanding Success Criterion 1.4.3 | W3C Understanding WCAG 2.0

Formal definition

Initial valuetransparent
Applies toall elements. It also applies to ::first-letter and ::first-line.
Inheritedno
Computed valuecomputed color
Animation typea color

Formal syntax

<color>

where <color> = <rgb()> | <rgba()> | <hsl()> | <hsla()> | <hwb()> | <hex-color> | <named-color> | currentcolor | <deprecated-system-color>

where <rgb()> = rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? )<rgba()> = rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? )<hsl()> = hsl( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsl( <hue>, <percentage>, <percentage>, <alpha-value>? )<hsla()> = hsla( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsla( <hue>, <percentage>, <percentage>, <alpha-value>? )<hwb()> = hwb( [<hue> | none] [<percentage> | none] [<percentage> | none] [ / [<alpha-value> | none] ]? )

where <alpha-value> = <number> | <percentage><hue> = <number> | <angle>

Examples

HTML

<div class="exampleone">   Lorem ipsum dolor sit amet, consectetuer </div>  <div class="exampletwo">   Lorem ipsum dolor sit amet, consectetuer </div>  <div class="examplethree">   Lorem ipsum dolor sit amet, consectetuer </div> 

CSS

.exampleone { background-color: transparent; }  .exampletwo {   background-color: rgb(153,102,153);   color: rgb(255,255,204); }  .examplethree {   background-color: #777799;   color: #FFFFFF; } 

Result

Specifications

Specification
CSS Backgrounds and Borders Module Level 4 # background-color

See also

Multiple backgrounds The <color> data type Other color-related properties: color, border-color, outline-color, text-decoration-color, text-emphasis-color, text-shadow, caret-color, and column-rule-color Applying color to HTML elements using CSS Select your preferred language English (US)DeutschEspañolFrançais日本語한국어PolskiPortuguês (do Brasil)Русский中文 (简体)正體中文 (繁體) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

You could also follow me on twitter. I have a couple of youtube channels if you want to see some video related content. RuneScape 3, Minecraft and also a coding channel here Web Dev.

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote

"Olivia, my eldest daughter, caught measles when she was seven years old. As the illness took its usual course I can remember reading to her often in bed and not feeling particularly alarmed about it. Then one morning, when she was well on the road to recovery, I was sitting on her bed showing her how to fashion little animals out of coloured pipe-cleaners, and when it came to her turn to make one herself, I noticed that her fingers and her mind were not working together and she couldn’t do anything. 'Are you feeling all right?' I asked her. 'I feel all sleepy,' she said. In an hour, she was unconscious. In twelve hours she was dead. The measles had turned into a terrible thing called measles encephalitis and there was nothing the doctors could do to save her. That was...in 1962, but even now, if a child with measles happens to develop the same deadly reaction from measles as Olivia did, there would still be nothing the doctors could do to help her. On the other hand, there is today something that parents can do to make sure that this sort of tragedy does not happen to a child of theirs. They can insist that their child is immunised against measles. ...I dedicated two of my books to Olivia, the first was ‘James and the Giant Peach’. That was when she was still alive. The second was ‘The BFG’, dedicated to her memory after she had died from measles. You will see her name at the beginning of each of these books. And I know how happy she would be if only she could know that her death had helped to save a good deal of illness and death among other children."

I just checked google books for BFG, and the dedication is there. 

https://www.google.com.au/books/edition/_/quybcXrFhCIC?hl=en&gbpv=1 


Roald Dahl, 1986
Random CSS Property

min()

The min() CSS function lets you set the smallest (most negative) value from a list of comma-separated expressions as the value of a CSS property value. The min() function can be used anywhere a <length>, <frequency>, <angle>, <time>, <percentage>, <number>, or <integer> is allowed.
min() css reference