Inset - Property CSS

inset
top
right
bottom
left

Summary of characteristics of the inset property

Quick description
Sets the position of the element when it is positioned other than static. Short hand for top, right, bottom and left.
Status
Standard
Applies to
Positioned elements.
Usable for
HTML
Predefined values
auto
Percentages
Calculated relative to the size of the parent block.
Initial value
auto
Inherited by default
No.
Computed value: during an animation, the inset property gradually changes from one value to another.
Per grammar: serialization in the order of syntax.
W3C Module
CSS Positioned Layout Module
 🡇  
 🡅  
Document status: WD (Working Draft)

Document status: WD (Working Draft)

Syntax diagram of inset.

Inset property - Syntax diagramSyntax diagram of the inset CSS property. See stylescss.free.fr for details. auto auto length | % length | % {1,4} {1,4}inset:;inset:;
Syntax diagram of the inset property.
The links in the diagram provide more details about the values.

In the diagram, the bold terms are the predefined words of CSS, the other terms are described below:

  • length is a numerical value followed by one of CSS dimension units.
  • % is a percentage calculated relative to the corresponding dimension of the parent block.
  • The syntax can be repeated from 1 to 4 times.

Description of the inset property.

The inset property sets the location of an element that is positioned differently than static, that is, those for which the position property has one of the values absolute, fixed, relative, or sticky. It has no effect on non-positioned elements, that is, elements for which the position property has its initial value or static. Refer to the position property for more details on element positioning.

inset is actually a shorthand property for the four properties top, right, bottom, and left. Contrary to what one might think, it is not a shortcut for inset-block and inset-inline, because these two properties are sensitive to writing direction and flow, whereas inset is not.

Language support.

If the positioning needs to be relative to the writing mode, it is better to use the inset-inline and inset-block properties, or the corresponding detailed properties.

top
left
The direction and writing mode of this text adapt to the chosen language.
right
bottom

Values for inset.

  • inset: auto;

    The position of the element is determined by the browser.

  • inset: 15px 25px 30px 50px; a b c d

    From one to four values, separated by spaces, and followed by a unit of measurement (see CSS dimension units). Each of these values defines the distance from one of the element's edges to the reference:
    - The page, if the element is positioned absolutely.
    - The screen, if the element is positioned fixed.
    - Etc.

    Depending on the number of values present in the syntax, the browser will need to handle them as follows:

    Inset property with a single value
    A single value
    It applies to all sides.
    Inset property with two values
    Two values
    The first applies to the top and bottom edges, and the second to the left and right edges.
    Inset property with three values
    Three values
    They are applied according to the above diagram.
    Inset property with four values
    <Four values
    They each apply to one of the 4 sides, starting from the top.

    If the values are expressed as percentages, they are calculated relative to the dimensions of the parent block.

    If the dimensions of the element are not set (values of width and height equal to auto), it can be resized to meet the constraints defined by inset. If the dimensions of the element are fixed, there may be a conflict with the inset property. In this case, the values corresponding to bottom and right will be ignored.

  • inset: initial; (auto) inset: inherit; inset: revert; inset: revertLayer; inset: unset;

    These values ​​are described in more detail on their respective page: initial, inherit, revert, revert-layer, unset.

Animation of the inset property.

Movable elements can easily be created by fixing their position (here as relative) and applying an animation to the inset property.

Target with an animated position

Manipulating the inset property programmatically.

With Javascript, change the value of inset.

Here are two examples of code to modify, in JavaScript, the value of the [inset] property.

Javascript
let el = document.getElementById('id'); el.style['inset'] = '1cm 2%'; // or let el = document.getElementById('id'); el.style.inset = '1cm 2%';

With Javascript, read the value of inset.

And two examples to read the value of the property. Attention! It must have been set in the HTML code via the style attribute, and not through a CSS selector. Both of these codes return the value in the same form and with the same units as when it was defined.

Javascript
let el = document.getElementById('id'); let value = el.style['inset']; // or let el = document.getElementById('id'); let value = el.style.inset;

With Javascript, read the computed value of inset.

To retrieve the computed value of inset, use the code below. The returned value is either the word auto, or one to four pixel values, even if other units were used to set the property in the styles sheet. The computed value is always defined.

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

With JQuery, change the value of inset.

With jQuery, you can find comparable code.

JQuery

$('#id').css('inset', '1cm 2%');

With Javascript, read the value of inset.

JQuery
let value = $('#id').css('inset');

Other code examples.

Other examples of Javascript and JQuery code are provided on the page Javascript and CSS.

Test it yourself.

The buttons below apply the entered value to the inset property and then display either the value as it was applied (first button) or the computed value (second button). This second option allows you to see how the value of inset is stored (serialized). Notably, all other units are converted to pixels, except percentages, which are stored as percentages (see the chapter on inheritance).

Simulator.

The simulator acts on the blue block, which is initially located on the left of its parent block. The blue block is in absolute position and therefore positions itself at the beginning of its parent, which is in relative position. Since the dimensions of the blue block are set to auto, its dimensions can vary to comply with the values provided by inset. However, you can set the width and/or height of the blue block, in which case the 2nd and 3rd values of inset are ignored, as they correspond to positioning from the right and the bottom.

By changing the language, you will notice that the property inset is indeed a physical property (which does not adjust to the writing mode) since the position of the block does not change depending on the language.


Writing mode:

inset :
width :
height :
Parent block, positioned as relative.
This block is
positioned
absolutely
position:absolute;

Browsers compatibility with inset.

The handling of inset is correct, except for Internet Explorer   since, at the time, this property did not exist.

Column 1
Browser support for the inset shorthand property, which sets the position for positioned elements (whose position property is different from static).
Column 2
Support for physical properties (which do not take into account language and writing mode): top, right, bottom, and left.
1
inset
property
2
Properties
top, right,
bottom and left
Estimated overall support.
94%
96%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

KaiOS Browser

Opéra Mobile

Opéra

Firefox pour Androïd

Samsung Internet

Chrome

Edge

Firefox

Androïd Brower

Chrome pour Androïd

Baidu Browser

QQ Browser

Safari

Safari sur IOS

UC Browser pour Androïd

Opéra mini

Historic of the inset property.

See also, regarding the placement of the blocks.

CSS specifications published by the W3C are organized into modules. The inset property is described in the CSS Positioned Layout Module. The following definitions are also described in the same module.

Properties:

bottom
Defines the space between the bottom of the element (if positioned) and the bottom of its parent.
Inset
Sets the position of the element when it is positioned other than static. Short hand for top, right, bottom and left.
inset-block
Defines the position of a positioned element in the block direction. Shorthand for inset-block-start and inset-block-end.
inset-block-end
For a positioned element, sets the location of the end side of the block.
inset-block-start
For a positioned element, sets the location of the edge on the start side of the block.
inset-inline
Defines the position of a positioned element in the inline direction. Shorthand for inset-inline-start and inset-inline-end.
inset-inline-end
On a positioned element, sets the location of the edge at the end of the line.
inset-inline-start
On a positioned element, sets the location of the edge at the starting of the line.
left
For a positioned element, defines the space between the left edge of the element and the left edge of the reference element.
overlay
Langue française
Determine if a positioned element should be displayed above others.
position
Changes the positioning of an element, for example to make it fixed in relation to the page.
right
For a positioned element, defines the space between the right edge of the element and the right edge of the reference element.
top
For a positioned element, defines the space between the top of the element and the top of the reference element (positioned parent or viewport).
z-index
Langue française
Defines on which layer an element should be displayed (top, bottom). Especially useful for positioned elements.