CSS Inset Property

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered

Overview

Inset is a shorthand way of denoting the top, right, bottom, and/or left CSS properties. Regardless of the element's writing style, directionality, or text orientation, it defines physical offsets.

We will learn how to use the inset CSS property in this article with the help syntax and examples.

Syntax

With the help of length, percentage, keyword values, and global values, we can define the inset values. It adheres to the same padding and margin multi-value syntax.

In order to declare offsets for the top, right, bottom, and left, we can take just one value, two value, three value or four values. These values run clockwise, beginning at top, just like padding and margin do.

Syntax:

inset in CSS

Length

The length takes a fixed sets of value defined in px, cm, pt etc. We can also take negative values and its default value is 0px.

Example:

Percentage

The <percentage> value is same as length but it sets the size in terms of percentage of the containing block.

Example:

Auto

It's the default value. When applied, the browser calculates the inset values.

Example:

Inherit

When inherit is used, the inset property inherits the property of its parent element. It may or may not be its containing block.

Once this value is inherited, it is handled as if it were a <length>, <percentage>, or the auto keyword.

Similar to inherit we have some more properties like initial, revert, revert-layer, unset. Initial is used to set the value of the inset property to its default value, and Unset is used to unset the inset property and it is the default value.

Inset Logical Properties

When we discuss "logical" concepts, we are referring to the point at which the writing of the material begins.

inset-logical-properties

The following are four inset logical sub-properties:

Logical PropertyHorizontal Flow EquivalentWhat it Does
inset-block-starttopDescribes the offset for the starting edge in the direction opposite to the writing direction.
inset-inline-endrightIndicates the offset for the writing-direction termination edge.
inset-block-endbottomIndicates the offset for the finishing edge in the direction that is orthogonal to the writing direction.
inset-inline-startleftThe starting edge offset is specified, and based on the writing mode, direction, and text orientation of the element, it corresponds to a physical offset.

The four sub-properties mentioned above can also be combined into two more shorthand properties:

Logical PropertyShorthand ForWhat it Does
inset-inlineinset-inline-start inset-inline-endboth inset-inline-start and inset-inline-end can be specified with this single value. It takes two values: one defines inset-inline-start and the other inset-inline-end.
inset-blockinset-block-start inset-block-endboth inset-block-start and inset-block-end can be set with this single value. It takes two values, the first one indicates the beginning of the inset block, and the second value specifies its finish.

Examples

Setting Offsets for an Element

Using length:

using-length-property-to-set-offset

Using percentage:

using-percentage-property-to-set-offset

Browser Support

The following browsers fully supports the CSS property:

browser-support-css-inset-property

Conclusion

  • Inset property values are the same as box offsets like top, left, right and bottom properties, only the directions are logical.
  • Inset property is applicable to the positioned elements. It is not an inherited property.
  • The percentage value is relative to the size of the containing block in the corresponding axis.

Similar to inset CSS property, you can check and read more about the following CSS topics: