CSS right Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Positioning

What You’ll Learn

The right property offsets a positioned element from the right edge of its container. It is one of the four offset properties alongside top, bottom, and left.

01

auto

Default value.

02

px

Fixed offset.

03

%

Responsive.

04

absolute

Common pair.

05

fixed

Viewport UI.

06

0

Flush right.

Introduction

The right property in CSS is used to position an element horizontally from the right edge of its containing block. It is commonly used in conjunction with the position property when absolute, relative, fixed, or sticky positioning is applied.

By using the right property, you can precisely control the horizontal placement of an element in a flexible and responsive manner.

Definition and Usage

Use right when you want an element anchored to the right side of a card, navbar, modal, or the viewport. Combine it with top or bottom to place corners and floating controls.

A relatively positioned parent creates the containing block for absolutely positioned children, which is the most common pattern for badges and overlays aligned from the right.

💡
Beginner Tip

right only affects positioned elements. Set position first, then add your offset value.

📝 Syntax

The syntax for the right property is as follows:

syntax.css
element {
  right: value;
}

Basic Example

right-absolute.css
.box {
  position: absolute;
  right: 20px;
}

Syntax Rules

  • Requires a position value other than static.
  • Length values such as px, rem, and em set a fixed gap from the right edge.
  • Percentages are relative to the containing block width.
  • auto lets the browser calculate placement normally.
  • Pair with top, bottom, or left for full placement control.
  • right: 0 aligns the element flush with the container’s right edge.

🎯 Default Value

The default value of the right property is auto, which means the element is not offset horizontally and follows the normal flow of the document.

⚡ Quick Reference

QuestionAnswer
Default valueauto
Requiresposition other than static
% basisContaining block width
InheritedNo
AnimatableYes (length and percentage)
Common useBadges, FABs, right-aligned overlays

💎 Property Values

ValueExampleDescription
autoright: auto;The browser calculates the right position.
lengthright: 20px;Specifies a fixed right position in units like px, em, rem, etc.
percentageright: 10%;Specifies the right position as a percentage of the containing block’s width.
initialright: initial;Sets the property to its default value.
inheritright: inherit;Inherits the property from its parent element.
auto 20px 10% 0 inherit

When Does right Matter?

right is the right tool when elements should anchor from the right edge:

  • Corner badges — Place labels on product cards with right: 0.
  • Floating buttons — Keep action buttons visible with position: fixed and right.
  • Modal close icons — Pin an × button to the top-right of a dialog.
  • Responsive panels — Use percentages to maintain spacing as containers resize.

For normal document flow alignment, consider Flexbox or Grid before reaching for absolute offsets.

👀 Live Preview

The blue box uses position: absolute and right: 20px inside the dashed container.

20px gap from the container’s right edge.

Examples Gallery

Start with the reference absolute box, try a fixed FAB, use percentage offsets, and anchor a corner badge.

🖱 Right Offsets

Position elements from the right edge — matching the reference example.

Example 1 — Absolute Box 20px from Right

In this example, we’ll position a box 20 pixels from the right edge of its containing block.

right-absolute.html
<style>
  .container {
    position: relative;
    width: 100%;
    height: 200px;
    background-color: lightgray;
  }

  .box {
    position: absolute;
    right: 20px;
    width: 100px;
    height: 100px;
    background-color: blue;
  }
</style>

<div class="container">
  <div class="box"></div>
</div>
Try It Yourself

How It Works

The parent’s position: relative defines the containing block. The child’s right edge sits 20px inward from the parent’s right edge.

Example 2 — Fixed Floating Button

Use position: fixed with right and bottom to keep a button in the viewport corner while scrolling.

right-fixed.html
<style>
  .fab {
    position: fixed;
    right: 20px;
    bottom: 20px;
  }
</style>
Try It Yourself

How It Works

With fixed, the containing block is the viewport, so right measures from the browser window edge.

🔀 Responsive & Decorative

Use percentages and zero offsets for flexible right-side placement.

Example 3 — Percentage Offset

right: 10% keeps spacing proportional when the container width changes.

right-percent.html
<style>
  .label {
    position: absolute;
    right: 10%;
  }
</style>
Try It Yourself

How It Works

Percentages tie placement to container width, which is useful in fluid layouts and banners.

Example 4 — Top-Right Badge

Set right: 0 and top: 0 to anchor a badge to the card corner.

right-badge.html
<style>
  .card { position: relative; }
  .badge {
    position: absolute;
    right: 0;
    top: 0;
  }
</style>
Try It Yourself

How It Works

Zero offsets align the badge’s top-right corner with the card’s top-right corner. A small transform can nudge it outward for a pill effect.

right and the offset properties

right is one of four inset properties. Use it with position, top, bottom, and left to place elements precisely.

Setting both left and right on an absolutely positioned element can stretch it horizontally unless width is also defined.

right-with-position.css
.toolbar {
  position: absolute;
  right: 12px;
  top: 12px;
}

🧠 How right Works

1

Position the element

Set position to relative, absolute, fixed, or sticky.

position
2

Choose the containing block

Absolute children use the nearest positioned ancestor; fixed uses the viewport.

Context
3

Apply the right offset

The element’s right edge moves inward by the specified length or percentage.

right
=

Right-aligned placement

Badges, buttons, and overlays sit exactly where you need them on the right side.

Browser Compatibility

The right property is widely supported across all modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. It has also been supported in older versions of Internet Explorer. However, it is always a good practice to test your website across different browsers to ensure compatibility.

Positioning · Universal support

Reliable right support

Chrome, Firefox, Safari, Edge, and Opera support right with all common length and percentage values.

99% Modern browser support
Google Chrome 1+ · All versions
Full support
Mozilla Firefox 1+ · All versions
Full support
Apple Safari 1+ · macOS & iOS
Full support
Microsoft Edge 12+ · All versions
Full support
Opera 4+ · Modern versions
Full support

Testing tip

Test percentage-based right values when containers change width in responsive layouts.

right property 99% supported

Bottom line: right is one of the most reliable CSS positioning properties across browsers.

Conclusion

The right property is a valuable tool for web developers looking to precisely control the horizontal positioning of elements within a container.

By understanding and utilizing this property, you can create more flexible and responsive layouts. Experiment with different values and see how the right property can enhance the positioning of elements in your web projects.

💡 Best Practices

✅ Do

  • Set position before using right
  • Use position: relative on parents of absolute children
  • Combine right with top or bottom for corners
  • Prefer percentages for fluid right-side spacing
  • Consider Flexbox or Grid for simple right alignment in flow

❌ Don’t

  • Apply right to static elements expecting movement
  • Set conflicting left and right without planning width
  • Forget mobile safe areas for fixed right-side buttons
  • Overlap important content with fixed right UI on small screens
  • Use absolute positioning when normal flow alignment is enough

Key Takeaways

Knowledge Unlocked

Five things to remember about right

Use these points when offsetting from the right edge.

5
Core concepts
02

position

Required pair.

Companion
03

px / rem

Fixed gap.

Pattern
04

%

Fluid layout.

Context
📍 05

right: 0

Flush edge.

Use case

❓ Frequently Asked Questions

right sets how far an element's right edge is offset from the right edge of its containing block. It works with positioned elements such as absolute, relative, fixed, and sticky.
The default value is auto, which means the element is not offset by right and follows normal positioning rules.
right has no effect on static elements. Set position to relative, absolute, fixed, or sticky first.
right positions the element within its containing block when positioned. margin-right adds space outside the element in normal flow or as part of the box model.
Yes. A percentage is calculated relative to the width of the containing block.

Practice in the Live Editor

Open the HTML editor and position a box with right: 20px inside a relative container.

HTML Editor →

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.

5 people found this page helpful