Esta tradução está incompleta. Por favor, ajude a traduzir este artigo.

A propriedade 

A propriedade CSS background-color define a cor de fundo de um elemento, usando tanto um valor  <color> ou a palavra-chave transparent.

/* Valores de palavra-chave */
background-color: red;

/* Valores hexadecimais */
background-color: #bbff00;

/* Valor hexadecimal com um canal  alpha */
background-color: #11ffee00; /* 00 - totalmente transparente */
background-color: #11ffeeff; /* ff - totalmente opaco */

/* Valores RGB */
background-color: rgb(255, 255, 128);

/* Valores RGBA ou RGB com canal alpha */
background-color: rgba(117, 190, 218, 0.0); /* 0.0 - totalmente transparente */
background-color: rgba(117, 190, 218, 0.5); /* 0.5 - semi-transparente */
background-color: rgba(117, 190, 218, 1.0); /* 1.0 - totalmente opaco */

/* Valor HSLA */
background-color: hsla(50, 33%, 25%, 0.75);

/* Valores de palavra-chave Especiais */
background-color: currentcolor;
background-color: transparent;

/* Valores Globais */
background-color: inherit;
background-color: initial;
background-color: unset;

Initial valuetransparent
Aplica-se aall elements. It also applies to ::first-letter and ::first-line.
Inheritednão
Midiavisual
Computed valuecomputed color
Animation typea color
Canonical orderthe unique non-ambiguous order defined by the formal grammar

Sintaxe

A propriedade background-color é especificada como um único valor de <color> .

Valores

<color>
É uma cor CSS <color> que descreve a cor uniforme do plano de fundo. Mesmo se um ou vários background-image são definidos, essa cor pode afetar a renderização, por trânsparência se as imagens não forem opacas. No CSS, transparent é uma cor.

Sintaxe Formal

<color>

where
<color> = <rgb()> | <rgba()> | <hsl()> | <hsla()> | <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>? )

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

Exemplos

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: teal;
  color: white;
}

.exampletwo {
  background-color: rgb(153,102,153);
  color: rgb(255,255,204);
}

.examplethree {
  background-color: #777799;
  color: #FFFFFF;
}

Resultado

Especificações

Specification Status Comment
CSS Backgrounds and Borders Module Level 3
The definition of 'background-color' in that specification.
Candidata a Recomendação Though technically removing the transparent keyword, this doesn't change anything as it has been incorporated as a true <color>
CSS Level 2 (Revision 1)
The definition of 'background-color' in that specification.
Recomendação No change
CSS Level 1
The definition of 'background-color' in that specification.
Recomendação Initial definition

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 4
Notes
Full support 4
Notes
Notes In Internet Explorer 8 and 9, there is a bug where a computed background-color of transparent causes click events to not get fired on overlaid elements.
Opera Full support 3.5Safari Full support 1WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
Alpha channel for hex values
Experimental
Chrome Full support 52Edge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android Full support 52Chrome Android Full support 52Edge Mobile No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android Full support 6.0

Legend

Full support  
Full support
No support  
No support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.

See also

Etiquetas do documento e colaboradores

Colaboradores desta página: alinedmelo
Última atualização por: alinedmelo,