CSS AdvancedLesson #121

Background Clip

The CSS `background-clip` property

CSS background-clip Property

The CSS background-clip property defines how far the background (color, image, or gradient) should extend within an element.

This property can have one of the following values:

  • border-box - The background extends behind the border. This is default
  • padding-box - The background extends to the inside edge of the border
  • content-box - The background extends to the edge of the content box

Example

Example Code

css
Try it Yourself
#div1 {
  border: 5px dotted black;
  padding: 35px;

   background-image: url(paper.gif);
  background-clip: border-box;

   }

#div2 {

   border: 5px dotted black;
  padding: 35px;

   background-image: url(paper.gif);
  background-clip: padding-box;

   }

#div3 {

   border: 5px dotted black;
  padding: 35px;

   background-image: url(paper.gif);
  background-clip: content-box;

   }

Example

Example Code

css
Try it Yourself
#div1 {
  border: 5px dotted black;
  padding: 35px;

   background-color: lightblue;
  background-clip: border-box;

   }

#div2 {

   border: 5px dotted black;
  padding: 35px;

   background-color: lightblue;
  background-clip: padding-box;

   }

#div3 {

   border: 5px dotted black;
  padding: 35px;

   background-color: lightblue;
  background-clip: content-box;

   }

CSS Advanced Background Properties

PropertyDescription
backgroundA shorthand property for setting all the background properties in one declaration
background-clipSpecifies the painting area of the background
background-imageSpecifies one or more background images for an element
background-originSpecifies where the background image(s) is/are positioned
background-sizeSpecifies the size of the background image(s)

Interactive Code Examples

CSS Example 1

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview:

CSS Example 2

css
Try it Yourself
Interactive runnable CSS example from EA Academy.
Live Output Preview: