CSS right Property

If this site has been useful, we’d love your support! Running this site takes time and resources, and every small contribution helps us keep creating valuable content. Consider buying us a coffee to keep things going strong!

Description

The right property determines the distance from the right edge of the parent element, not including the indent, margin, and border width, to the right edge of the child element. The coordinate count depends on the value of the position property. If it is absolute, the browser window acts as the parent and the position of the element is determined from its right edge. In the case of a relative value, right is counted from the right edge of the initial position of the element. If position: relative is specified for the parent element, then the absolute positioning of the child elements determines their position from the right edge of the parent.

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

I am absolutely positioned.
The rusty swing set creaked a lonely lullaby in the twilight, shadows lengthening like grasping fingers across the dew-kissed grass. A lone dandelion seed, adrift on the breeze, whispered secrets of faraway fields, of dandelion suns and galaxies spun from fluff.

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="leftcol">Column 1</div> <div class="centercol">Column 2</div> <div class="rightcol">Column 3</div> 
.leftcol { 
   position: absolute;
   top: 20px;
   left: 10px;
   width: 100px;
   background: #fc3; 
   border: 1px solid #000;
   padding: 10px; 
} 
.centercol { 
   position: relative;
   background: maroon;
   padding: 10px;
   color: white; 
   border: 1px solid #000; 
   margin: 20px 240px 0 140px;
} 
.rightcol { 
   position: absolute;
   top: 20px;
   right: 10px;
   width: 200px;
   background: #ccc; 
   border: 1px solid black; 
   padding: 10px; 
}

Browser Support

The following table will show you the current browser support for the CSS right property.

Desktop
Edge Chrome Firefox Opera Safari
121151
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
18414114.4

Last updated by CSSPortal on: 1st January 2024