Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Positioning and Stacking

The right property

Reference for the CSS right property: how it offsets positioned elements from the right edge, percentages, conflicts with left, and logical alternatives.

The right property sets the horizontal offset of a positioned element from the right edge of its reference box. For an absolute element the reference is the padding edge of the nearest positioned ancestor; for fixed, the viewport. For a relative element, a positive value shifts the box to the left, because it pushes the element away from the right edge.

It has no effect on position: static elements.

CSS
.close-button {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
}

Try it

Right offsets

Syntax

CSS
right: auto | <length> | <percentage> | <anchor()> | <anchor-size()>;
  • Initial value: auto
  • Applies to: positioned elements
  • Inherited: no
  • Percentages: refer to the width of the containing block
  • Animatable: yes, as a length or percentage
  • Computed value: for positioned elements, an absolute length or a percentage as specified; auto where it cannot be resolved; for static elements, auto

Values

Value Description
auto No offset from the right side.
<length> A fixed distance from the right edge; negative values push the element beyond it.
<percentage> A percentage of the containing block's width.
anchor(...) A position taken from an anchor element (see anchor positioning).

Usage notes

  • Common uses: close buttons, badges, floating action buttons and anything pinned to the right corner.
  • Scrollbars. For fixed elements, right: 0 sits against the viewport edge, usually inside any visible classic scrollbar.
  • Conflict with left. When left, width and right are all set on an absolutely positioned box, right is ignored in left-to-right text.
  • Writing direction. right does not flip in right-to-left languages. Use inset-inline-end when the badge should follow the reading direction.
  • Relative positioning is counter-intuitive. right: 20px moves the box left. Prefer transform: translateX() for visual nudges.

Browser support

Supported in every browser for many years.