/

HTML / CSS / JavaScript Tutorial

CSS Property: background-clip

[this page | pdf | back links]

The CSS (CSS3) background-clip property specifies the painting area of the background.

 

Valid property values (other than inherit and initial) are:

 

Value

Description

border-box

(default value). Background is clipped to the border box

content-box

Background is clipped to the content box

padding-box

Background is clipped to the padding box

 

Default Value:

border-box

JavaScript syntax:

e.g. object.style.backgroundClip="content-box"

Inherited:

No

Animatable:

No

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
p {width: 100px; background-color: yellow; padding: 10px;}
p.x1 {background-clip: content-box;}
</style>
</head>
<body>
1. Element with default property<br>
<p>1</p><br>
2. Element set using in-file HTML style
<p class="x1">2</p><br>
3. Element set using JavaScript
<p id="x2">3</p>

<script>
document.getElementById("x2").style.backgroundClip =
  "content-box";
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyBackgroundClip() {
  var x = document.createElement("DIV"); x.style.backgroundClip = "content-box"; return (window.getComputedStyle(x, null).backgroundClip == "content-box");
}


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile