CSS right Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The right property sets the horizontal inset of a positioned element toward or away from the physical right edge. It has no effect when position is static.

For absolute or fixed, it is the distance from the containing block’s right edge. For relative, a positive value moves the box to the left of its normal spot. The initial value is auto. It is not inherited. Prefer inset-inline-end when the offset should follow writing direction.

Baseline for lengths, percentages, and auto.

Not deprecated. Study those values first. Newer anchor() / anchor-size() forms for right have limited support — skip them until you need anchor positioning.

CSS Syntax

syntax.css
right: auto | <length> | <percentage> | initial | inherit;

Examples: right: auto; · right: 20px; · right: 10%; · right: 0;

Property Values

ValueDescriptionTry it
autoBrowser chooses based on left, width, and flow. Initial valueTry it
<length>Fixed offset such as 20px or 2em. May be negativeTry it
<percentage>Percent of the containing block’s widthTry it
0Flush with the right edge (for absolute/fixed)Try it
initialResets to autoTry it
inheritInherits from the parent elementTry it

How to Use right

Position the element first, then set how far it sits from the right.

  1. Set position to relative, absolute, fixed, or sticky.
  2. For absolute children, give a parent position: relative (or another non-static value) as the containing block.
  3. Set right to a length, percentage, or 0.
  4. Add top / left / bottom as needed, or use inset.
PieceRequired?Role
Non-static positionYesWithout it, right does nothing
Containing blockFor absoluteNearest positioned ancestor (or the viewport for fixed)
right valueYes (to control offset)Length, percentage, or auto
left tooOptionalCan stretch the box; if both fight, left wins in LTR

Live Preview

The blue box is position: absolute. Only right changes.

Parent is position: relative. The box also has top: 16px so you can see the horizontal move clearly.

Positioned box

right: 20px

CSS Examples

Each snippet focuses on right. Positioning is only there so the offset can show. Use Try It Yourself for a live editor.

Example 1 — Absolute Offset

Pin a box 20px from the right of a relative parent.

CSS
<style>
  .box {
    position: relative;
  }

  .pin {
    position: absolute;
    right: 20px;
    top: 16px;
  }
</style>

<div class="box">
  <div class="pin">Pinned</div>
</div>
Try It Yourself

How It Works

  1. Make a containing block. position: relative on the parent anchors absolute children.
  2. Take the child out of flow. position: absolute lets insets apply.
  3. Set the offset. right: 20px is the lesson — 20px from the parent’s right edge.
  4. Add top for clarity. Vertical placement is separate from right.

Example 2 — Relative Nudge

Shift an in-flow box to the left of its normal position.

CSS
<style>
  .nudge {
    position: relative;
    right: 24px;
  }
</style>

<p>Before</p>
<p class="nudge">Nudged left</p>
<p>After</p>
Try It Yourself

How It Works

  1. Keep the element in flow. position: relative still reserves the original space.
  2. Offset visually. A positive right moves the painted box to the left.
  3. Neighbors stay put. “Before” and “After” do not close the gap the box left behind.
  4. Mirror of left. Relative left nudges right; relative right nudges left.

Example 3 — Percentage Right

Offset by a fraction of the containing block’s width from the right edge.

CSS
<style>
  .box {
    position: relative;
  }

  .pin {
    position: absolute;
    right: 50%;
    top: 16px;
  }
</style>

<div class="box">
  <div class="pin">50%</div>
</div>
Try It Yourself

How It Works

  1. Same absolute pattern. Parent is relative; child is absolute.
  2. Use a percentage. right: 50% is half the parent’s width from the right edge.
  3. Not centered by itself. The box’s own width still sticks out past the midpoint unless you also translate it.
  4. Scales with the parent. Wider containers move the inset farther in pixels.

Edge Cases & Pitfalls

If right seems ignored, one of these is usually why.

static

Needs a non-static position

right on a static element does nothing. Set position to relative, absolute, fixed, or sticky.

parent

Absolute needs a containing block

Without a positioned ancestor, absolute right is measured from a higher ancestor (often the initial containing block), which surprises beginners.

both

left and right together

Setting both can stretch the element. If width cannot satisfy both, left wins in left-to-right layouts; right wins in right-to-left.

relative

Relative right moves left

On a relatively positioned box, a positive right shifts the element toward the left of its normal position.

logical

Physical right does not flip in RTL

Use inset-inline-end when the end edge should follow writing direction.

Browser Support

right is a browser CSS property for positioned layout. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

right

Lengths, percentages, and auto are widely supported. anchor() values used with right are newer and not part of these numbers.

100% Common values
Google Chrome All versions
Full support
Mozilla Firefox All versions
Full support
Apple Safari All versions
Full support
Microsoft Edge All versions
Full support
Opera All versions
Full support
Samsung Internet All versions
Full support
Internet Explorer All versions
Full support
right Widely supported

Bottom line: Safe for auto, px, em, rem, and percentages on positioned elements. Treat anchor() as progressive. It is not a runtime API.

Key Takeaways

  • Role: inset a positioned element from the physical right edge.
  • Prerequisite: position must not be static.
  • Relative quirk: positive right moves the box left of its normal spot.
  • Logical twin: use inset-inline-end when the end edge should follow writing mode.

One line: set a non-static position, then use right to measure from the physical right edge — absolute pins; relative nudges left.

Frequently Asked Questions

It sets the horizontal inset of a positioned element relative to the physical right edge. Absolute and fixed use the containing block; relative offsets from the normal position toward the left.
The initial value is auto. The browser then follows other rules such as left, width, and normal flow.
No. right has no effect on static elements. Use relative, absolute, fixed, or sticky.
Yes. Percentages refer to the width of the containing block.
right is always the physical right edge. inset-inline-end follows writing direction and can map to the left side in RTL.
It is Baseline and widely available for lengths, percentages, and auto. Newer anchor() values have limited support. It is a browser CSS property, not a Node.js feature.

Next: rotate

Learn how the CSS rotate property turns elements without a full transform list.

rotate tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful