English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules

All CSS Properties

CSS right attribute usage and examples

The right CSS attribute specifies the offset of the right edge of the positioned element relative to the box of the reference element or the right edge of the browser window.

  • ForAbsolutely positionedelements, the right attribute specifies the distance from the right edge of the element's box to the right edge of its containing block.

  • ForRelatively positionedElement, the right attribute specifies the offset of the element's box relative to its own right edge (i.e., the box is positioned in the normal flow, and then offset from this position according to these properties).

The following table provides usage instructions and version history for this attribute, as well as the syntax of using this attribute in JavaScript scripts.

Default value:auto
Applies to:Positioned element
Inheritance:No
An animatable:Yes.Please refer to Animation properties.
Version:CSS 2,3
JavaScript syntax:object.style.right="150px"

The syntax of right usage

The syntax of this attribute is as follows:

right: length | percentage | auto | initial | inherit

The following example demonstrates how to use the right attribute.

  p {
   position: absolute;
   right: 150px;
  }
Test and see‹/›

Attribute value

The following table describes the value of this attribute.

ValueDescription
lengthA numerical value in units such as px, pt, cm, em, etc., negative values are allowed.
percentageSpecify a percentage offset. The percentage is calculated relative to the width of the element's containing block. Negative percentage values are allowed.
autoThe browser calculates the right edge position. This is the default value.
initialSet this attribute to its default value.
inheritIf specified, the associated elements will adopt the value of the parent element's right attribute.

Browser compatibility

The compatibility of the right attribute in browsers, the numbers in the following table represent the minimum version number of the browsers that support this attribute; all mainstream browsers support this attribute.

  • Firefox 1+

  • Google Chrome1+

  • Internet Explorer 4+

  • Apple Safari 1+

  • Opera 6+

For further reading

Please refer to the following tutorial:CSS position,CSS layer.

Related attributes:position,top,left,bottom,z-index.