Html colors backgrounds codes

Содержание
  1. HTML Colors
  2. Color Names
  3. Background Color
  4. Example
  5. Hello World Lorem ipsum. Text Color You can set the color of text: Hello World Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Example Hello World Lorem ipsum. Ut wisi enim. Border Color You can set the color of borders: Hello World Hello World Hello World Example Hello World Hello World Hello World Color Values In HTML, colors can also be specified using RGB values, HEX values, HSL values, RGBA values, and HSLA values. The following three elements have their background color set with RGB, HEX, and HSL values: The following two elements have their background color set with RGBA and HSLA values, which add an Alpha channel to the color (here we have 50% transparency): Источник background-color The background-color CSS property sets the background color of an element. Try it 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 : rgb ( 117 190 218 / 0.5) ; /* 50% transparent */ /* HSL value */ background-color : hsl ( 50 33% 25%) ; /* Fully opaque */ background-color : hsl ( 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 : revert-layer; background-color : unset; The background-color property is specified as a single value. Values 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. Formal definition Formal syntax Examples HTML div class = " exampleone" > Lorem ipsum dolor sit amet, consectetuerdiv > div class = " exampletwo" > Lorem ipsum dolor sit amet, consectetuerdiv > div class = " examplethree" > Lorem ipsum dolor sit amet, consectetuerdiv > 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 Browser compatibility BCD tables only load in the browser See also Found a content problem with this page? This page was last modified on Jul 18, 2023 by MDN contributors. Your blueprint for a better internet. MDN Support Our communities Developers Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation. Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license. Источник CSS Backgrounds The CSS background properties are used to add background effects for elements. In these chapters, you will learn about the following CSS background properties: background-color background-image background-repeat background-attachment background-position background (shorthand property) CSS background-color The background-color property specifies the background color of an element. Example The background color of a page is set like this: With CSS, a color is most often specified by: a valid color name — like «red» a HEX value — like «#ff0000» an RGB value — like «rgb(255,0,0)» Look at CSS Color Values for a complete list of possible color values. Other Elements You can set the background color for any HTML elements: Example Here, the , , and elements will have different background colors: div background-color: lightblue; > Opacity / Transparency The opacity property specifies the opacity/transparency of an element. It can take a value from 0.0 — 1.0. The lower value, the more transparent: Example Note: When using the opacity property to add transparency to the background of an element, all of its child elements inherit the same transparency. This can make the text inside a fully transparent element hard to read. Transparency using RGBA If you do not want to apply opacity to child elements, like in our example above, use RGBA color values. The following example sets the opacity for the background color and not the text: You learned from our CSS Colors Chapter, that you can use RGB as a color value. In addition to RGB, you can use an RGB color value with an alpha channel (RGBA) — 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 (fully opaque). Tip: You will learn more about RGBA Colors in our CSS Colors Chapter. Example The CSS Background Color Property Источник
  6. Text Color
  7. Hello World
  8. Example
  9. Hello World Lorem ipsum. Ut wisi enim. Border Color You can set the color of borders: Hello World Hello World Hello World Example Hello World Hello World Hello World Color Values In HTML, colors can also be specified using RGB values, HEX values, HSL values, RGBA values, and HSLA values. The following three elements have their background color set with RGB, HEX, and HSL values: The following two elements have their background color set with RGBA and HSLA values, which add an Alpha channel to the color (here we have 50% transparency): Источник background-color The background-color CSS property sets the background color of an element. Try it 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 : rgb ( 117 190 218 / 0.5) ; /* 50% transparent */ /* HSL value */ background-color : hsl ( 50 33% 25%) ; /* Fully opaque */ background-color : hsl ( 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 : revert-layer; background-color : unset; The background-color property is specified as a single value. Values 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. Formal definition Formal syntax Examples HTML div class = " exampleone" > Lorem ipsum dolor sit amet, consectetuerdiv > div class = " exampletwo" > Lorem ipsum dolor sit amet, consectetuerdiv > div class = " examplethree" > Lorem ipsum dolor sit amet, consectetuerdiv > 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 Browser compatibility BCD tables only load in the browser See also Found a content problem with this page? This page was last modified on Jul 18, 2023 by MDN contributors. Your blueprint for a better internet. MDN Support Our communities Developers Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation. Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license. Источник CSS Backgrounds The CSS background properties are used to add background effects for elements. In these chapters, you will learn about the following CSS background properties: background-color background-image background-repeat background-attachment background-position background (shorthand property) CSS background-color The background-color property specifies the background color of an element. Example The background color of a page is set like this: With CSS, a color is most often specified by: a valid color name — like «red» a HEX value — like «#ff0000» an RGB value — like «rgb(255,0,0)» Look at CSS Color Values for a complete list of possible color values. Other Elements You can set the background color for any HTML elements: Example Here, the , , and elements will have different background colors: div background-color: lightblue; > Opacity / Transparency The opacity property specifies the opacity/transparency of an element. It can take a value from 0.0 — 1.0. The lower value, the more transparent: Example Note: When using the opacity property to add transparency to the background of an element, all of its child elements inherit the same transparency. This can make the text inside a fully transparent element hard to read. Transparency using RGBA If you do not want to apply opacity to child elements, like in our example above, use RGBA color values. The following example sets the opacity for the background color and not the text: You learned from our CSS Colors Chapter, that you can use RGB as a color value. In addition to RGB, you can use an RGB color value with an alpha channel (RGBA) — 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 (fully opaque). Tip: You will learn more about RGBA Colors in our CSS Colors Chapter. Example The CSS Background Color Property Источник
  10. Border Color
  11. Hello World
  12. Hello World
  13. Hello World
  14. Example
  15. Hello World Hello World Hello World Color Values In HTML, colors can also be specified using RGB values, HEX values, HSL values, RGBA values, and HSLA values. The following three elements have their background color set with RGB, HEX, and HSL values: The following two elements have their background color set with RGBA and HSLA values, which add an Alpha channel to the color (here we have 50% transparency): Источник background-color The background-color CSS property sets the background color of an element. Try it 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 : rgb ( 117 190 218 / 0.5) ; /* 50% transparent */ /* HSL value */ background-color : hsl ( 50 33% 25%) ; /* Fully opaque */ background-color : hsl ( 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 : revert-layer; background-color : unset; The background-color property is specified as a single value. Values 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. Formal definition Formal syntax Examples HTML div class = " exampleone" > Lorem ipsum dolor sit amet, consectetuerdiv > div class = " exampletwo" > Lorem ipsum dolor sit amet, consectetuerdiv > div class = " examplethree" > Lorem ipsum dolor sit amet, consectetuerdiv > 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 Browser compatibility BCD tables only load in the browser See also Found a content problem with this page? This page was last modified on Jul 18, 2023 by MDN contributors. Your blueprint for a better internet. MDN Support Our communities Developers Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation. Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license. Источник CSS Backgrounds The CSS background properties are used to add background effects for elements. In these chapters, you will learn about the following CSS background properties: background-color background-image background-repeat background-attachment background-position background (shorthand property) CSS background-color The background-color property specifies the background color of an element. Example The background color of a page is set like this: With CSS, a color is most often specified by: a valid color name — like «red» a HEX value — like «#ff0000» an RGB value — like «rgb(255,0,0)» Look at CSS Color Values for a complete list of possible color values. Other Elements You can set the background color for any HTML elements: Example Here, the , , and elements will have different background colors: div background-color: lightblue; > Opacity / Transparency The opacity property specifies the opacity/transparency of an element. It can take a value from 0.0 — 1.0. The lower value, the more transparent: Example Note: When using the opacity property to add transparency to the background of an element, all of its child elements inherit the same transparency. This can make the text inside a fully transparent element hard to read. Transparency using RGBA If you do not want to apply opacity to child elements, like in our example above, use RGBA color values. The following example sets the opacity for the background color and not the text: You learned from our CSS Colors Chapter, that you can use RGB as a color value. In addition to RGB, you can use an RGB color value with an alpha channel (RGBA) — 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 (fully opaque). Tip: You will learn more about RGBA Colors in our CSS Colors Chapter. Example The CSS Background Color Property Источник
  16. Hello World Hello World Color Values In HTML, colors can also be specified using RGB values, HEX values, HSL values, RGBA values, and HSLA values. The following three elements have their background color set with RGB, HEX, and HSL values: The following two elements have their background color set with RGBA and HSLA values, which add an Alpha channel to the color (here we have 50% transparency): Источник background-color The background-color CSS property sets the background color of an element. Try it 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 : rgb ( 117 190 218 / 0.5) ; /* 50% transparent */ /* HSL value */ background-color : hsl ( 50 33% 25%) ; /* Fully opaque */ background-color : hsl ( 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 : revert-layer; background-color : unset; The background-color property is specified as a single value. Values 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. Formal definition Formal syntax Examples HTML div class = " exampleone" > Lorem ipsum dolor sit amet, consectetuerdiv > div class = " exampletwo" > Lorem ipsum dolor sit amet, consectetuerdiv > div class = " examplethree" > Lorem ipsum dolor sit amet, consectetuerdiv > 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 Browser compatibility BCD tables only load in the browser See also Found a content problem with this page? This page was last modified on Jul 18, 2023 by MDN contributors. Your blueprint for a better internet. MDN Support Our communities Developers Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation. Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license. Источник CSS Backgrounds The CSS background properties are used to add background effects for elements. In these chapters, you will learn about the following CSS background properties: background-color background-image background-repeat background-attachment background-position background (shorthand property) CSS background-color The background-color property specifies the background color of an element. Example The background color of a page is set like this: With CSS, a color is most often specified by: a valid color name — like «red» a HEX value — like «#ff0000» an RGB value — like «rgb(255,0,0)» Look at CSS Color Values for a complete list of possible color values. Other Elements You can set the background color for any HTML elements: Example Here, the , , and elements will have different background colors: div background-color: lightblue; > Opacity / Transparency The opacity property specifies the opacity/transparency of an element. It can take a value from 0.0 — 1.0. The lower value, the more transparent: Example Note: When using the opacity property to add transparency to the background of an element, all of its child elements inherit the same transparency. This can make the text inside a fully transparent element hard to read. Transparency using RGBA If you do not want to apply opacity to child elements, like in our example above, use RGBA color values. The following example sets the opacity for the background color and not the text: You learned from our CSS Colors Chapter, that you can use RGB as a color value. In addition to RGB, you can use an RGB color value with an alpha channel (RGBA) — 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 (fully opaque). Tip: You will learn more about RGBA Colors in our CSS Colors Chapter. Example The CSS Background Color Property Источник
  17. Hello World Color Values In HTML, colors can also be specified using RGB values, HEX values, HSL values, RGBA values, and HSLA values. The following three elements have their background color set with RGB, HEX, and HSL values: The following two elements have their background color set with RGBA and HSLA values, which add an Alpha channel to the color (here we have 50% transparency): Источник background-color The background-color CSS property sets the background color of an element. Try it 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 : rgb ( 117 190 218 / 0.5) ; /* 50% transparent */ /* HSL value */ background-color : hsl ( 50 33% 25%) ; /* Fully opaque */ background-color : hsl ( 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 : revert-layer; background-color : unset; The background-color property is specified as a single value. Values 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. Formal definition Formal syntax Examples HTML div class = " exampleone" > Lorem ipsum dolor sit amet, consectetuerdiv > div class = " exampletwo" > Lorem ipsum dolor sit amet, consectetuerdiv > div class = " examplethree" > Lorem ipsum dolor sit amet, consectetuerdiv > 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 Browser compatibility BCD tables only load in the browser See also Found a content problem with this page? This page was last modified on Jul 18, 2023 by MDN contributors. Your blueprint for a better internet. MDN Support Our communities Developers Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation. Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license. Источник CSS Backgrounds The CSS background properties are used to add background effects for elements. In these chapters, you will learn about the following CSS background properties: background-color background-image background-repeat background-attachment background-position background (shorthand property) CSS background-color The background-color property specifies the background color of an element. Example The background color of a page is set like this: With CSS, a color is most often specified by: a valid color name — like «red» a HEX value — like «#ff0000» an RGB value — like «rgb(255,0,0)» Look at CSS Color Values for a complete list of possible color values. Other Elements You can set the background color for any HTML elements: Example Here, the , , and elements will have different background colors: div background-color: lightblue; > Opacity / Transparency The opacity property specifies the opacity/transparency of an element. It can take a value from 0.0 — 1.0. The lower value, the more transparent: Example Note: When using the opacity property to add transparency to the background of an element, all of its child elements inherit the same transparency. This can make the text inside a fully transparent element hard to read. Transparency using RGBA If you do not want to apply opacity to child elements, like in our example above, use RGBA color values. The following example sets the opacity for the background color and not the text: You learned from our CSS Colors Chapter, that you can use RGB as a color value. In addition to RGB, you can use an RGB color value with an alpha channel (RGBA) — 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 (fully opaque). Tip: You will learn more about RGBA Colors in our CSS Colors Chapter. Example The CSS Background Color Property Источник
  18. Color Values
  19. background-color
  20. Try it
  21. Syntax
  22. Values
  23. Accessibility concerns
  24. Formal definition
  25. Formal syntax
  26. Examples
  27. HTML
  28. CSS
  29. Result
  30. Specifications
  31. Browser compatibility
  32. See also
  33. Found a content problem with this page?
  34. MDN
  35. Support
  36. Our communities
  37. Developers
  38. CSS Backgrounds
  39. CSS background-color
  40. Example
  41. Other Elements
  42. Example
  43. Opacity / Transparency
  44. Example
  45. Transparency using RGBA
  46. Example
  47. The CSS Background Color Property
Читайте также:  Php ini log errors to file

HTML Colors

HTML colors are specified with predefined color names, or with RGB, HEX, HSL, RGBA, or HSLA values.

Color Names

In HTML, a color can be specified by using a color name:

Background Color

You can set the background color for HTML elements:

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

Example

Hello World

Lorem ipsum.

Text Color

You can set the color of text:

Hello World

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.

Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

Example

Hello World

Lorem ipsum.

Ut wisi enim.

Border Color

You can set the color of borders:

Hello World

Hello World

Hello World

Example

Hello World

Hello World

Hello World

Color Values

In HTML, colors can also be specified using RGB values, HEX values, HSL values, RGBA values, and HSLA values.

The following three elements have their background color set with RGB, HEX, and HSL values:

The following two elements have their background color set with RGBA and HSLA values, which add an Alpha channel to the color (here we have 50% transparency):

Источник

background-color

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

Try it

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: rgb(117 190 218 / 0.5); /* 50% transparent */ /* HSL value */ background-color: hsl(50 33% 25%); /* Fully opaque */ background-color: hsl(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: revert-layer; background-color: unset; 

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

Values

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.

Formal definition

Formal syntax

Examples

HTML

div class="exampleone">Lorem ipsum dolor sit amet, consectetuerdiv> div class="exampletwo">Lorem ipsum dolor sit amet, consectetuerdiv> div class="examplethree">Lorem ipsum dolor sit amet, consectetuerdiv> 

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

Browser compatibility

BCD tables only load in the browser

See also

Found a content problem with this page?

This page was last modified on Jul 18, 2023 by MDN contributors.

Your blueprint for a better internet.

MDN

Support

Our communities

Developers

Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.

Источник

CSS Backgrounds

The CSS background properties are used to add background effects for elements.

In these chapters, you will learn about the following CSS background properties:

  • background-color
  • background-image
  • background-repeat
  • background-attachment
  • background-position
  • background (shorthand property)

CSS background-color

The background-color property specifies the background color of an element.

Example

The background color of a page is set like this:

With CSS, a color is most often specified by:

  • a valid color name — like «red»
  • a HEX value — like «#ff0000»
  • an RGB value — like «rgb(255,0,0)»

Look at CSS Color Values for a complete list of possible color values.

Other Elements

You can set the background color for any HTML elements:

Example

Here, the ,

, and elements will have different background colors:

div background-color: lightblue;
>

Opacity / Transparency

The opacity property specifies the opacity/transparency of an element. It can take a value from 0.0 — 1.0. The lower value, the more transparent:

Example

Note: When using the opacity property to add transparency to the background of an element, all of its child elements inherit the same transparency. This can make the text inside a fully transparent element hard to read.

Transparency using RGBA

If you do not want to apply opacity to child elements, like in our example above, use RGBA color values. The following example sets the opacity for the background color and not the text:

You learned from our CSS Colors Chapter, that you can use RGB as a color value. In addition to RGB, you can use an RGB color value with an alpha channel (RGBA) — 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 (fully opaque).

Tip: You will learn more about RGBA Colors in our CSS Colors Chapter.

Example

The CSS Background Color Property

Источник

Оцените статью