Background-origin - Property CSS

background-origin

Summary of characteristics of the background-origin property

Quick description
Defines a reference to position the background image.
Status
Standard
Usable for
HTML
Predefined values
padding-box | border-box | content-box
Percentages
Not applicable.
Initial value
padding-box
Inherited by default
No.
Animation type
Repeatable list.
W3C Module
CSS Backgrounds and Borders Module
References (W3C)
Document status: CR (Candidate Recommendation)

Syntax diagram of background-origin.

background-origin - Syntax DiagramSyntax diagram of the background-origin CSS property. border-box border-box padding-box padding-box content-box content-box , ,background-origin:;background-origin:;
Syntax diagram of the background-origin property.
The links in the diagram provide more details about the values.
  • In the case of multiple backgrounds, several values are listed separated by a comma.

Description of the background-origin property.

background-origin defines the reference for positioning the background image. The property background-position positions the background image based on this reference.

This does not prevent the background from extending beyond this reference. To limit the background to a certain area of the element, refer to the property background-clip .

background-origin is ineffective if the property background-attachment has the value fixed.

For a general presentation of backgrounds in CSS, refer to the page background.

Values for background-origin.

  • background-origin: padding-box; background-origin: border-box; background-origin: content-box;

    padding-box is the default value. Each of these values corresponds to a point that will serve as a reference for positioning the background with the property background-position .

    background-origin property

  • background-origin: border-box, border-box, ...;

    In the case of multiple backgrounds, several values can be provided for background-origin by separating them with a comma.
    For more information on multiple backgrounds, refer to the page Multiple backgrounds.

  • background-origin: initial; (padding-box) background-origin: inherit; background-origin: revert; background-origin: revertLayer; background-origin: unset;

    See the following pages for more details: initial, inherit, revert, revert-layer, unset.

Manipulating the background-origin property programmatically.

Change the value of background-origin in Javascript.

In JavaScript, depending on the chosen syntax, the property name can be written in kebab-case (a dash between words) or in camel-case (an uppercase letter to separate words). The value, however, must always be written according to the CSS syntax, that is to say in kebab-case.

Javascript
let el = document.getElementById('id'); el.style['background-origin'] = 'border-box'; // or let el = document.getElementById('id'); el.style.backgroundOrigin = 'border-box';

Read in Javascript the value of background-origin.

The code below works when the property has been directly assigned to the element itself, via the style attribute of the HTML, and not by using a CSS selector.

Javascript
let el = document.getElementById('id'); let value = el.style['background-origin']; // or let el = document.getElementById('id'); let value = el.style.backgroundOrigin;

Read the computed value of background-origin in Javascript.

The computed value is the one resulting from the evaluation of the inheritance cascade and the resolution of any conflicts (see the Priorities). The calculated value can therefore be the value assigned to the element via the style attribute of the HTML, a value assigned via a CSS selector, an inherited value, or if not, the initial value of the property: padding-box in the case of background-origin.

Javascript
let el = document.getElementById('id'); let value = window.getComputedStyle(el).getPropertyValue('background-origin');

Modify the value of the property background-origin with jQuery.

The name of the property can be written interchangeably in kebab-case notation or in camel-case notation.

JQuery

$('#id').css('background-origin', 'border-box');
// or
$('#id').css('backgroundOrigin', 'border-box');

Read the computed value of the property background-origin with JQuery.

JQuery
let value = $('#id').css('background-origin');

Test it yourself.

The buttons below apply the entered value to the property background-origin and then display either the value as it was applied or the computed value.

Simulator.

The simulator applies the chosen value to the two elements below. For the first, the background image is not repeated; for the second, it is.

background-origin :
Donec dolor mi, iaculis a enim a, pellentesque hendrerit arcu. Nam nec urna eget lacus ornare lacinia a in velit. Suspendisse nec lacus nec elit viverra commodo ut nec sapien. Nunc vitae lorem quam. Ut in dictum sapien, quis maximus urna.
Donec dolor mi, iaculis a enim a, pellentesque hendrerit arcu. Aliquam bibendum eu enim ut tempor. Nam nec urna eget lacus ornare lacinia a in velit. Suspendisse nec lacus nec elit viverra commodo ut nec sapien. Nunc vitae lorem quam. Ut in dictum sapien, quis maximus urna. Aliquam at libero odio. Ut nisl metus, dictum ac varius in, porta at risus. Nam posuere est fringilla pretium rutrum. Aenean in magna ipsum. In nulla enim, pellentesque id tincidunt cursus, ultricies quis ligula.

Browsers compatibility with background-origin.

The property background-origin does not have any compatibility issues with current browsers.

Column 1
Support for the background-origin property that defines the reference for background-position.
1
background-origin
property
Estimated overall support.
96%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

KaiOS Browser

Opéra Mobile

Chrome

Edge

Opéra

Safari

Safari sur IOS

Androïd Brower

Chrome pour Androïd

Firefox pour Androïd

Samsung Internet

Firefox

Baidu Browser

QQ Browser

UC Browser pour Androïd

Opéra mini

Historic of the background-origin property.

See also, regarding the backgrounds.

Everything concerning backgrounds and borders is described in the specification of W3C CSS Backgrounds and Borders Module. Here is the list of the main properties described in this standard.

Properties:

background
Summary of background properties.
background-attachment
Langue française
Background image scrolling mode.
background-clip
Langue française
Defines the extent of the background, especially in relation to the border and padding.
background-color
Sets the background color.
background-image
Defines the background image or gradient (multiple images or gradients can coexist).
background-position
Langue française
Defines how the background image is positioned.
background-position-x
Langue française
Définit comment se positionne l'image d'arrière-plan dans le sens horizontal.
background-position-y
Langue française
Defines how the background image is positioned in the vertical direction,
background-repeat
Langue française
Defines how the background image is repeated.
background-size
Langue française
Sizing the background image.
border
Langue française
A shorthand property that defines the set of border parameters.
border-bottom-left-radius
Langue française
Sets the radius of the rounded corner at the bottom left.
border-bottom-right-radius
Langue française
Sets the radius of the rounded corner in the lower right.
border-color
Langue française
Sets the color of the borders.
border-image
Langue française
Shorthand of border properties made with images.
border-image-outset
Langue française
Sets the overflow of the border image.
border-image-repeat
Langue française
Defines how the border image is repeated or expanded to cover the desired area.
border-image-slice
Langue française
Defines how the border image is clipped.
border-image-source
Langue française
Defines the image used to construct the border.
border-image-width
Langue française
Sets the thickness of the border when the border is made with an image.
border-radius
Radius of rounded corners.
border-style
Langue française
Type of border (solid, double, dotted...).
border-top-left-radius
Langue française
Sets the radius of the rounded corner at the top left.
border-top-right-radius
Langue française
Sets the radius of the rounded corner in the upper-right.
border-width
Langue française
Sets the thickness of the element's border.
box-shadow
Applies a shading effect to the frames by indicating all the parameters: color, shadow shift, blur, etc.