background-clip
Quick Summary for background-clip
The background-clip CSS property sets whether an element's background extends underneath its border box, padding box, or content box.
Code Usage for background-clip
/* Keyword values */ background-clip: border-box; background-clip: padding-box; background-clip: content-box; background-clip: text;  /* Global values */ background-clip: inherit; background-clip: initial; background-clip: revert; background-clip: unset; 
More Details for background-clip

background-clip

The background-clip CSS property sets whether an element's background extends underneath its border box, padding box, or content box.

If the element has no background-image or background-color, this property will only have a visual effect when the border has transparent regions or partially opaque regions (due to border-style or border-image); otherwise, the border masks the difference.

Note: Because the root element has a different background painting area, the background-clip property has no effect when specified on it. See "The backgrounds of special elements."

Note: For documents whose root element is an HTML element: if the computed value of background-image on the root element is none and its background-color is transparent, user agents must instead propagate the computed values of the background properties from that element's first HTML <body> child element. The used values of that <body> element's background properties are their initial values, and the propagated values are treated as if they were specified on the root element. It is recommended that authors of HTML documents specify the canvas background for the <body> element rather than the HTML element.

Syntax

/* Keyword values */ background-clip: border-box; background-clip: padding-box; background-clip: content-box; background-clip: text;  /* Global values */ background-clip: inherit; background-clip: initial; background-clip: revert; background-clip: unset; 

Values

border-box

The background extends to the outside edge of the border (but underneath the border in z-ordering).

padding-box

The background extends to the outside edge of the padding. No background is drawn beneath the border.

content-box

The background is painted within (clipped to) the content box.

text

The background is painted within (clipped to) the foreground text.

Accessibility concerns

When using background-clip: text check that the contrast ratio between the background color and the color of the text placed over it is high enough that people experiencing low vision conditions will be able to read the content of the page.

If the background image does not load, this could also lead to the text becoming unreadable. Add a fallback background-color to prevent this from happening, and test without the image.

Consider using feature queries with @supports to test for support of background-clip: text and provide an accessible alternative where it is not supported.

Formal definition

Initial valueborder-box
Applies toall elements. It also applies to ::first-letter and ::first-line.
Inheritedno
Computed valueas specified
Animation typediscrete

Formal syntax

<box>#

where <box> = border-box | padding-box | content-box

Examples

HTML

<p class="border-box">The background extends behind the border.</p> <p class="padding-box">The background extends to the inside edge of the border.</p> <p class="content-box">The background extends only to the edge of the content box.</p> <p class="text">The background is clipped to the foreground text.</p> 

CSS

p {   border: .8em darkviolet;   border-style: dotted double;   margin: 1em 0;   padding: 1.4em;   background: linear-gradient(60deg, red, yellow, red, yellow, red);   font: 900 1.2em sans-serif;   text-decoration: underline; }  .border-box { background-clip: border-box; } .padding-box { background-clip: padding-box; } .content-box { background-clip: content-box; }  .text {   background-clip: text;   -webkit-background-clip: text;   color: rgba(0,0,0,.2); } 
Result

Specifications

Specification
CSS Backgrounds and Borders Module Level 4 # background-clip

See also

The clip-path property creates a clipping region that defines what part of an entire element should be displayed. Background properties: background, background-color, background-image, background-origin Introduction to the CSS box model Select your preferred language English (US)DeutschEspañolFrançais日本語한국어Português (do Brasil)Русский中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote

"Olivia, my eldest daughter, caught measles when she was seven years old. As the illness took its usual course I can remember reading to her often in bed and not feeling particularly alarmed about it. Then one morning, when she was well on the road to recovery, I was sitting on her bed showing her how to fashion little animals out of coloured pipe-cleaners, and when it came to her turn to make one herself, I noticed that her fingers and her mind were not working together and she couldn’t do anything. 'Are you feeling all right?' I asked her. 'I feel all sleepy,' she said. In an hour, she was unconscious. In twelve hours she was dead. The measles had turned into a terrible thing called measles encephalitis and there was nothing the doctors could do to save her. That was...in 1962, but even now, if a child with measles happens to develop the same deadly reaction from measles as Olivia did, there would still be nothing the doctors could do to help her. On the other hand, there is today something that parents can do to make sure that this sort of tragedy does not happen to a child of theirs. They can insist that their child is immunised against measles. ...I dedicated two of my books to Olivia, the first was ‘James and the Giant Peach’. That was when she was still alive. The second was ‘The BFG’, dedicated to her memory after she had died from measles. You will see her name at the beginning of each of these books. And I know how happy she would be if only she could know that her death had helped to save a good deal of illness and death among other children."

I just checked google books for BFG, and the dedication is there. 

https://www.google.com.au/books/edition/_/quybcXrFhCIC?hl=en&gbpv=1 


Roald Dahl, 1986
Random CSS Property

unset

The unset CSS keyword resets a property to its inherited value if the property naturally inherits from its parent, and to its initial value if not. In other words, it behaves like the inherit keyword in the first case, when the property is an inherited property, and like the initial keyword in the second case, when the property is a non-inherited property.
unset css reference