×

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

CSS Math Functions

The CSS math functions permit numerical articulations. These CSS math functions can particularly be utilized in maybe unforeseen ways, for example, inside angles and shading the functions and in the...

3 minutes read.

CSS z-index Property

CSS z-index: CSS z-index permits us to represent any visual hierarchy over a 3D plane that is the z-axis. This index can be applied to describe the positioned element’s stacking...

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 Image Gallery

Image galleries are used to display and store collections of images. Example Let’s discuss an example. CSS was used to create the following image gallery: Code is as follows: <html> <head> <style> div.gallery {   margin: 6px;   border: 1px...

5 minutes read.

CSS Width

CSS Width The width property in CSS sets the content width of area of the element. These properties do not provide margin and border features. It is used to set the...

1 minute read.

Difference between HTML and CSS

HTML HTML stands for HyperText Markup Language and is used to create web pages and websites and web applications, which means we can create static web pages. Html is a scripting...

3 minutes read.

CSS Counters

CSS Counters: The CSS counter property is similar to the variables. CSS counters are controlled via CSS, and its values are incremented via rules of CSS to record how much...

4 minutes read.

CSS Filter

CSS Filter CSS filter is used to apply visual effects on the images, text, and other factors of the webpage. This filter property in CSS allows us to admit the effects like...

7 minutes read.

CSS Page-break-inside Attribute

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

3 minutes read.

CSS Animation

CSS Animation: The animation property of CSS is applied to make animation over any webpage. It is used as the animation replacement made by JavaScript and Flash. Rules of CSS3 @keyframes The...

3 minutes read.

CSS Color

CSS Colors: The CSS color property is used for setting the HTML element’s color. The color of the fonts and the color of the background can be set-up by using...

5 minutes read.

CSS Form

You can create attractive HTML form by using CSS. Style input Fields The Input Field width properties are used to determine the width of the input field. Let us see an example of CSS style...

2 minutes read.

CSS Reference

The CSS Reference lists all of the basic standard CSS properties, pseudo-classes, pseudo-elements, and data types, for all intents and purposes functional notations, and at-rules alphabetically.  The site also includes...

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

CSS Border

CSS Border: The border property of CSS allows us to define the style, color, width, and radius of the element’s border. It is applied to various elements to set-up the...

4 minutes read.

CSS Visibility

Visibility in CSS: This visibility property in CSS is employed to describe whether the components are visible or not. Note: An invisible component also grabs the space over the page. If...

2 minutes read.

How to get rid/remove of bullet pioints in CSS

We include a list of items on the web pages that were sometimes numbered and sometimes bulleted in various styles. In HTML, there are two kinds of lists: ordered and unordered...

3 minutes read.

Radial-gradient() CSS function

Radial-gradient() CSS function It defines a CSS in-built function, which produces a smooth transition among multiple colors. It is used to set any radial-gradient that is same as a background-image. This...

4 minutes read.

CSS Font

CSS Font: CSS has font property, which makes the text more attractive. We can alter the entire look by changing font color, font size, font style, and much more. In...

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