right

Term side of the Card.
Topic: Positioning
Unit title: right
Categories: Property
Explanation side of the Card

Explanation: The property that sets the distance between the right edge of an element and the right edge of its containing block. With 'absolute' or 'fixed' `position` it places the element in its nearest positioned ancestor or the viewport, while with 'relative' it shifts it from its normal place.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 1.
  • The safari browser supports this feature starting from version 1.
Availability: 

Example

Wrongcss
.dialog {
  position: relative;
}
.close {
  position: absolute;
  right: 8px;
}
Rightcss
.dialog {
  position: relative;
}
.close {
  position: absolute;
  inset-inline-end: 8px;
}

inset-inline-end sits on the right in left-to-right text and flips to the left in right-to-left text.

Common mistakes

  • The element sticks to the page's right edge because the parent isn't positioned.
  • A close button stays on the right in right-to-left layouts where it should flip.

Key points

  • Corner placement uses position: absolute with a positioned parent and top plus right.
  • Layouts that support right-to-left text use inset-inline-end instead of right.
  • Fixed elements on the right account for the scrollbar and safe area insets.

Interview questions

Why is right: 0 not working?

The element needs a position other than 'static', and for 'absolute' an ancestor that is positioned.

What happens if I set both left and right?

With 'auto' width the element stretches between both; with a fixed width, the start side wins, which is left in left-to-right text.

What is the logical version of right?

inset-inline-end, which follows the text direction.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy