Favorites

CSS right Property

right
CSS PropertyThis property is supported by all modern browsers.
Updated 22nd November 2026

The right property sets the distance between the right edge of a positioned element and the right of its containing block.

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

Description

The right property controls an element's horizontal offset when that element is participating in CSS positioning. It determines how the element should be offset from the right edge of its containing block, but it does nothing for elements that remain in the normal (static) flow; to take effect it must be used on an element whose positioning is enabled via the position property. Conceptually, right is one side of the pair of horizontal offset controls and is used whenever you need to anchor or nudge an element relative to the right boundary of its reference box.

How the offset created by right is applied depends on the element’s positioning mode. For example, when an element is positioned relatively it is visually shifted while its original document slot is preserved; when it is positioned absolutely or fixed the element is removed from normal flow and located with respect to the appropriate containing block (often the nearest positioned ancestor or the viewport). The final placement also depends on the other offset properties (such as left) or shorthands like inset, which together determine how the box edges relate to the reference box.

In practical layout work, right interacts with other layout mechanisms and context-forming features. Transforms, stacking contexts and certain layout conditions can change which box acts as the reference or can alter coordinate systems, so a transformed ancestor or other layout effects may change how right resolves; see transform for details on one common source of such changes. Because right operates in the positioning layer, it’s commonly used for overlays, tooltips, fixed UI controls, and precise alignment of absolutely-positioned elements, and it should be considered alongside document direction and any logical offset shorthands when aiming for internationalized layouts.

Definition

Initial value
auto
Applies to
Positioned elements
Inherited
No
Computed value
If specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, 'auto'.
Animatable
Yes
JavaScript syntax
object.style.right

Interactive Demo

Box
Demo Code
HTML Code
<div class="demo-area">
	<div class="demo-element">Box</div>
</div>
CSS Code
.demo-area {
	position: relative;
	width: 300px;
	height: 180px;
	background: #f4f4f4 repeating-linear-gradient(0deg, transparent 0 19px, #e2e2e2 19px 20px), repeating-linear-gradient(90deg, transparent 0 19px, #e2e2e2 19px 20px);
	outline: 1px dashed #b0b0b0;
}
.demo-element {
	position: absolute;
	padding: 8px 12px;
	background: #f72585;
	color: #fff;
	font-size: 14px;
	width: 90px;
	height: 50px;
	box-sizing: border-box;
	right: 0;
}

Syntax

right: auto | <length> | <percentage>

Values

  • <length>Floating-point number, followed by an absolute units designator (cm, mm, in, pt, or pc) or a relative units designator (em, ex, or px).
  • <percentage>Integer, followed by a percent sign (%). The value is a percentage of the height of the parent object.
  • autoDefault position, according to the regular HTML layout of the page.

Example

<div class="container">
<div class="box">Positioned box (right: 20px)</div>
<p class="content">This container uses position: relative so the child can be positioned from the right.</p>
</div>
.container {
    position: relative;
    width: 600px;
    height: 200px;
    margin: 40px auto;
    padding: 16px;
    box-sizing: border-box;
    background: linear-gradient(135deg, #f0f4ff, #e6f7ff);
    border-radius: 8px;
    border: 1px solid #dbe9ff;
}

.box {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 180px;
    padding: 12px 16px;
    background-color: #1e90ff;
    color: #ffffff;
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(30, 144, 255, 0.16);
    font-weight: 600;
    text-align: center;
}

.content {
    margin-top: 90px;
    color: #12406a;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS right property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.