×

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 center a button in CSS

How to center a button in CSS? In the tutorial, we will learn how to center a button in CSS. CSS (Cascading Style Sheets) gives an HTML web page the greatest possible...

4 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.

CSS Float

CSS Float: The float property of CSS is the positioning property. This property is applied to elements to push them either to left or right. It permits for wrapping facility...

4 minutes read.

What is Bootstrap CSS?

Bootstrap: - Bootstrap is a CSS framework that is free to use and is used for the front-end development of the website in a faster and easier way. Bootstrap was released as...

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 Ellipsis

The CSS ellipsis kind of is the value that mostly is used by the property: text-overflow. Here, we will discuss the following: What is CSS Ellipsis? Syntax for CSS ellipsis How to...

3 minutes read.

What is a CSS File?

What is a CSS File and How to use it in Html? CSS: - CSS stands for Cascading Style Sheet. CSS is a file of style sheets that describe the presentation of...

4 minutes read.

CSS Specificity

CSS Specificity: If one or more conflicting rules of CSS express a similar element, a browser will pursue a few rules to examine the specific one. Specificity can be specified...

3 minutes read.

How to edit CSS in WordPress

Developing a new website or blog is a difficult undertaking. We want to create something that the consumers will adore, but we might not want the setting to take months and...

7 minutes read.

CSS Text-stroke

Text-stroke Text-stroke CSS property inserts the stroke to any text and gives a decoration option to them also. It describes the stroke’s width and color for various text characters. It is...

2 minutes read.

CSS 2d Transform

Transform property in CSS is used mainly for enhancing the effects and to animate the elements. Transform is an effect that changes the shape, size and position of an element. It helps...

6 minutes read.

CSS Page-break-after Attribute

Page-break-after Attribute As its name implies, the page-break-before property is applied to include page break after any element, at the time of printing a document. It adds the page break after...

5 minutes read.

How to center a table in CSS

The table is used to store and arrange the data in tabular format. The data here can be of any form like text, image, links, etc. The table is made...

3 minutes read.

Create a 3D text effect using HTML and CSS

A3D text effect is a beautiful and attractive part of a webpage. As a web page developer, it is crucial to know how to create a 3D text effect with...

3 minutes read.

Divi in CSS

Divi is popular WordPress themes due to its versatility and user-friendly interface. It includes a built-in page builder for sophisticated design options and an assortment of customization features to help...

9 minutes read.

CSS Text-align

Text-align The text-align property of CSS sets the table-cell box’s horizontal alignment or any block element. The text-align property is the same as the CSS property vertical-align but towards any horizontal...

1 minute read.

CSS :root selector

CSS :root selector This CSS pseudo-class matches any document’s root element. It chooses the parent of the highest-level inside the document DOM or tree. An element of <html> is always a...

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 Table

CSS table provides better look and feel. There are various properties of CSS table that are given below. border border-collapse padding width height text-align color background-color CSS Table Border You can set...

4 minutes read.