- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Selectors
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS - background-clip Property
The background-clip CSS property is used to specify how the background image or color should be displayed within an element's padding box, border box or content box. It determines the area of an element to which the background will be applied.
In the absence of a background-image or background-color, the background-clip property will have a visual effect when border is either partially opaque or transparent.
Since the root element has a canvas background and its background painting area extends covering the entire canvas, the property background-clip has no effect when specified on root element.
Possible Values
border-box − Background is applied to the entire element, i.e. outside edge of the border, including the padding and border.
padding-box − Background is applied to the padding area of the element, i.e. outside edge of padding, excluding the border.
content-box − Background is applied to the content area of the element, i.e. within the content box, excluding the padding and border.
text − Background is clipped to the foreground text characters of the element.
Check the contrast ratio of background color and foreground color, while using the background-clip property, as it should be clear enough for people experiencing low vision conditions. Also, add a fallback background-color in case the background image fails to load.
Applies to
All the HTML elements.
DOM Syntax
object.style.backgroundClip = "border-box | padding-box | content-box | text";
CSS background-clip Example
The following example demonstrates how to use different background-clip values (border-box, padding-box, content-box, text) to the paragraph elements to clipped the background −
<html> <head> <style> p { border: 10px rgb(13, 7, 190); border-style: dashed double; margin: 5px; padding: 1cm; background: linear-gradient(60deg, rgb(208, 233, 143), rgb(216, 238, 243), rgb(197, 190, 241), rgb(220, 174, 119), rgb(237, 111, 189)); font: 700 1em sans-serif; } .border-area { background-clip: border-box; } .padding-area { background-clip: padding-box; } .content-area { background-clip: content-box; } .text-area { background-clip: text; -webkit-background-clip: text; color: gray; } </style> </head> <body> <p class="border-area">Background applied to the entire element.</p> <p class="padding-area">Background applied to the padding area.</p> <p class="content-area">Background applied only to the content area.</p> <p class="text-area">Background is clipped to the foreground text.</p> </body> </html>
CSS background-clip - Using Background Image
The following example demonstrates how to clipped background image using background-clip property −
<html> <head> <style> div { border: 10px rgb(13, 7, 190); border-style: dashed; margin: 5px; padding: 1cm; font: 700 1em sans-serif; display: inline-block; background-image: url('images/white-flower.jpg'); height: 200px; width: 200px; } .border-area { background-clip: border-box; } .padding-area { background-clip: padding-box; } .content-area { background-clip: content-box; } </style> </head> <body> <div class="border-area">background applied to complete element</div> <div class="padding-area">background applied to padding box</div> <div class="content-area">background applied to content only</div> </body> </html>
To Continue Learning Please Login
Login with Google