Thanks to visit codestin.com
Credit goes to www.cssportal.com

CSS Portal

CSS background-origin Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The CSS property background-origin controls the positioning area of a background image relative to an element’s box model. Essentially, it determines from which box the background image’s positioning is calculated: the content-box, padding-box, or border-box. This distinction is crucial when working with elements that have significant padding or border values, as it affects how the image aligns within the element. By adjusting the origin, designers can create visually precise layouts and control how background images interact with other visual elements inside the box.

When using background-origin, the positioning of the image may seem subtle but can have a noticeable impact on design. For example, if the property is set to content-box, the background will begin from the innermost box, ignoring padding and borders, making the image tightly aligned with the content. On the other hand, choosing padding-box includes the padding area in the positioning, which often allows for a more balanced visual spacing between the content and the edges of the image. Using border-box positions the background relative to the entire element, including borders, which can be especially useful for full-coverage effects or when a decorative border is present.

Another key consideration is how background-origin interacts with the background-clip property. While background-origin determines the starting point for positioning, background-clip controls the visible area of the background image. This means that designers can independently control where the image begins and how much of it is displayed, giving them granular control over layering effects, gradients, and complex patterns. Mastery of background-origin can elevate design precision, particularly in cases involving multiple background images or when combining images with semi-transparent borders and padding.

Definition

Initial value
padding-box
Applies to
All elements
Inherited
No
Computed value
As specified
Animatable
No
JavaScript syntax
object.style.backgroundOrigin

Interactive Demo

This is the content of the element.

Syntax

background-origin: <box> [ , <box> ]* 

Values

<box> = border-box | padding-box | content-box
  • border-boxThe position is relative to the border box.
  • padding-boxThe position is relative to the padding box.
  • content-boxThe position is relative to the content box. Useful for having background images automatically follow the padding.

Example

<div class="container">
<div class="box box-border" data-origin="border-box">
border-box
</div>
<div class="box box-padding" data-origin="padding-box">
padding-box
</div>
<div class="box box-content" data-origin="content-box">
content-box
</div>
</div>
.container {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  padding: 24px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  background: #f7fafc;
}

.box {
  width: 220px;
  height: 120px;
  border: 12px solid #2b6cb0;
  padding: 20px;
  box-sizing: border-box;
  color: #0f172a;
  position: relative;
  background-image: radial-gradient(circle at 0 0, rgba(99,102,241,0.95) 0 44px, transparent 45px);
  background-repeat: no-repeat;
  background-position: 0 0;
  background-size: 88px 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  border-radius: 8px;
}

.box::after {
  content: attr(data-origin);
  position: absolute;
  right: 8px;
  bottom: 8px;
  font-size: 12px;
  color: rgba(0,0,0,0.6);
  background: rgba(255,255,255,0.6);
  padding: 4px 6px;
  border-radius: 4px;
}

/* background-origin examples */
.box-border {
  background-origin: border-box;
}

.box-padding {
  background-origin: padding-box;
}

.box-content {
  background-origin: content-box;
}

Browser Support

The following information will show you the current browser support for the CSS background-origin property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!