Curriculum
Course: CSS Advanced
Login

Curriculum

CSS Advanced

CSS Rounded Corners

0/1

CSS Border Images

0/1

CSS Color Keywords

0/1

CSS Text Effects

0/1

CSS 2D Transforms

0/1

CSS 3D Transforms

0/1

CSS Transitions

0/1

CSS Animations

0/1

CSS Tooltip

0/1

CSS Style Images

0/1

CSS Image Reflection

0/1

CSS Masking

0/1

CSS Buttons

0/1

CSS Multiple Columns

0/1

CSS User Interface

0/1

CSS Box Sizing

0/1

CSS Media Queries

0/1
Text lesson

CSS Color Keywords

This page will provide an explanation of the transparent, currentcolor, and inherit keywords.

The transparent Keyword

The transparent keyword is utilized to create a color with transparency, commonly employed to establish a transparent background color for an element.

Example 

In this instance, the background color of the <div> element will be completely transparent, allowing the background image to be visible.

body {
  background-image: url(“paper.gif”);
}

div {
  background-color: transparent;
}

Note: The transparent keyword is synonymous with rgba(0,0,0,0). RGBA color values extend RGB color values by incorporating an alpha channel, determining the opacity level for a color. Further details can be found in our CSS RGB and CSS Colors chapters.

The currentcolor Keyword

The currentcolor keyword functions akin to a variable, retaining the current value of the color property assigned to an element.

Its utility is notable when aiming to maintain consistency of a specific color within an element or across a webpage.

Example 

In this example, the border color of the <div> element will be blue, as it inherits the text color of the <div> element, which is blue.

div {
  color: blue;
  border: 10px solid currentcolor;
}

 

Example 

In this example, the background color of the <div> is assigned the current color value of the body element.

body {
  color: purple;
}

div {
  background-color: currentcolor;
}

 

Example 

In this example, the border color and shadow color of the <div> are both assigned the current color value of the body element.

body {
 color: green;
}

div {
  box-shadow: 0px 0px 15px currentcolor;
  border: 5px solid currentcolor;
}

The inherit Keyword

The inherit keyword dictates that a property should derive its value from its parent element.

It can be applied to any CSS property and on any HTML element.

Example 

In this example, the border settings of the <span> element will inherit from its parent element.

div {
  border: 2px solid red;
}

span {
  border: inherit;
}