The CSS background properties are used to add background effects for elements. Show
In these chapters, you will learn about the following CSS background properties:
CSS background-colorThe ExampleThe background color of a page is set like this: body { Try it Yourself » With CSS, a color is most often specified by:
Look at CSS Color Values for a complete list of possible color values. Other ElementsYou can set the background color for any HTML elements: ExampleHere, the <h2>, <p>, and <div> elements will have different background colors: h2 { div { p
{ Try it Yourself » Opacity / TransparencyThe Note: When using the Transparency using RGBAIf 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 div { Try it Yourself » The CSS Background Color Property
ExampleSet the background color for a page: body {background-color: coral;} Try it Yourself » More "Try it Yourself" examples below. Definition and UsageThe The background of an element is the total size of the element, including padding and border (but not the margin). Tip: Use a background color and a text color that makes the text easy to read. Show demo ❯
Browser SupportThe numbers in the table specify the first browser version that fully supports the property.
CSS Syntaxbackground-color: color|transparent|initial|inherit; Property Values
More ExamplesExampleSpecify the background color with a HEX value: body {background-color: #92a8d1;} Try it Yourself » ExampleSpecify the background color with an RGB value: body {background-color: rgb(201, 76, 76);} Try it Yourself » ExampleSpecify the background color with an RGBA value: body {background-color: rgba(201, 76, 76, 0.3);} Try it Yourself » ExampleSpecify the background color with a HSL value: body {background-color: hsl(89, 43%, 51%);} Try it Yourself » ExampleSpecify the background color with a HSLA value: body {background-color: hsla(89, 43%, 51%, 0.3);} Try it Yourself » ExampleSet background colors for different elements: body { h2 { div { span { Try it Yourself » Related PagesCSS tutorial: CSS Background HTML DOM reference: backgroundColor property How do you get a full background color in CSS?The CSS background properties are used to add background effects for elements.. a valid color name - like "red". a HEX value - like "#ff0000". an RGB value - like "rgb(255,0,0)". What is HTML code for background color?HTML <body> bgcolor Attribute
color_name: It specifies the name of the Background color of the Document. hex_number: It specifies the hex code of the Background color in the Document. rgb_number: It specifies the rgb value of the Background color in the Document.
What are the colors in CSS?Basic Colors. |