×

CSS Background Color

  • It is one of the CSS properties to apply styling to html elements.
  • This property is used to apply the background color to any HTML element.
  • The background of an element includes everything except margin. It includes its total size, border, and padding.

Syntax

html_tag_element{
   background-color: colorName | initial | transparent | inherit;  
}  

Explanation:

  1. colorName: color name can be specified in many formats like
    1. standard color name - It specifies standard color name like red, blue, cyan, etc.
    2. rgb() value -  It takes the color in rgb format like rgb(value1, value2, vlaue3) like rgb(0, 0, 0) for black color
    3. hexadecimal value - It takes the color in hexadecimal value of format #xxxxxx like use #000000 for black color. This color format gives wide varierty of colors to user
    4. rgba() value – It is extended from rgb(). It stands for red green blue alpha. Here, alpha represents the opacity of color. The range of alpha parameter varies from 0.0 to 1.0 where 0.0 is fully transparent and 1.0 not transparent. Like for black color we specified rgba(0, 0, 0, 1) where rgba(0,0,0,0) represents the white color.
    5. hsl() – It stands for hue, saturation, and lightness. It is also a type of color-defining technique. Hue defines the color from a color wheel of 360 degrees. Saturation represents the shade of grey, and lightness represents the lightness of color like 0% is black while 100% is white.
    6. hsla() – It is extended from hsl(). Here also “a” stands for alpha and represemts the opacity for color.
  2. transparent: It specifies the default background color for an element.
  3. initial: It is a keyword that applies the default value of an element to it. It applies to all HTML elements.
  4. Inherit: It inherits the background-color property from its parent.

Examples

Let’s discuss some coding examples.

Example 1:

<html>
<head>
<title> CSS background color property example</title>
</head>
<body style="background-color: red">
<p>CSS background color</p>
</body>
</html>

Output:

CSS Background Color

In above code, same red color can be represented using rgb(), hsl() and hexadecimal as below:
rgb(255, 0, 0)
hsl(0, 1, 0.50)
#FF0000


Related Topics

How To Use CSS

You can use CSS(Cascading Style Sheet) in four ways. These are given below: The given above CSS type, in which various technique will be used. These are different from each other and...

2 minutes read.

Css Box Model

Introduction The Box Model property of CSS is used for design and layout of an html page. In CSS, all the elements has a rectangular box around it, you have to...

5 minutes read.

CSS White Space Property

White Space in CSS The white-space CSS property describes how to show the content inside an element. This property is applied to manage a white space within an element. Values of White-space...

2 minutes read.

CSS Line Height

CSS Line Height: This property in CSS can be used to describe the line box’s minimal height inside the element. It sets-up the distinction among two lines in our content. It...

3 minutes read.

CSS: nth-selector

CSS nth selector can be used to match an element according to its position regardless of its parent’s type. Here, n can be any number, formula, or a keyword. These selectors...

2 minutes read.

CSS Background Color

It is one of the CSS properties to apply styling to html elements.This property is used to apply the background color to any HTML element.The background of an element includes...

2 minutes read.

CSS Order

CSS Order CSS order property in CSS describes the flex item’s order inside the flex or any grid container. It is applied to order any flex item. Note: If any component is...

3 minutes read.

CSS @keyframes rule

CSS @keyframes rule It describes the rule of animation that depicts the properties of CSS for the components at every state along with the timeline. We may make the properties of complex...

4 minutes read.

CSS Padding

CSS Padding: The padding property in CSS is addressed to describe the space among the element border and the element content.This property is quite different from the margin property of...

2 minutes read.

CSS Sticky

CSS Sticky The position property in CSS is applied to set an element’s position. This property is also applied to position an element behind the other element. It is useful for...

1 minute read.

CSS Margin

CSS Margin: The CSS margin property is employed to describe the space throughout the elements. It clears the range throughout the element. These properties do not have a background color...

2 minutes read.

CSS Navigation bar

CSS Navigation bar: A navigation system or navigation bar comes upon GUI that can help many visitors to access the information. A Navigation bar is a UI component on the...

11 minutes read.

CSS Word-spacing

Word-spacing The work-spacing property of CSS is applied to manage the space among the words. We can decrease or increase the space among the words by the use of this property. It...

3 minutes read.

CSS Important

CSS Important: CSS !important property is used to provide more importance, as compared to other CSS properties. The meaning of this property is “This is important.” This property enables CSS...

2 minutes read.

CSS Background-blend-mode

Background-blend-mode The background-blend-mode property sets a blend mode of the component’s every background layer (color/image). It illustrates how the element background image blends well with the element background color. We can...

9 minutes read.

CSS Tutorial

CSS refers to the Cascading Style Sheet. CSS is a form of a programming language. In other words, CSS is a language of the style sheet that is utilised for...

9 minutes read.

CSS translate() Function

Translate() CSS function This function in CSS is a CSS in-built function. It relocates the element in the horizontal direction or in the vertical direction. It can move the items from...

2 minutes read.

CSS Images

Images in CSS: Images are a critical part of a web application. It includes various types of images in the web application that cannot be recommended. However, it is essential...

4 minutes read.

How to create blinking text using CSS

The blinking effect is used in HTML and CSS to take the attraction towards a particular word or section. If you need such a blinking effect, we need to take...

2 minutes read.

CSS Transition

CSS Transition The transitions in CSS are influenced, included to modify the component from one design to another, without the use of the JavaScript or Flash. We should describe two of the...

2 minutes read.