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.
Fundamentals
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.
Foundation
📝 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.
Defaults
🎯 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.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Default value
auto
Requires
position other than static
% basis
Containing block width
Inherited
No
Animatable
Yes (length and percentage)
Common use
Badges, FABs, right-aligned overlays
Reference
💎 Property Values
Value
Example
Description
auto
right: auto;
The browser calculates the right position.
length
right: 20px;
Specifies a fixed right position in units like px, em, rem, etc.
percentage
right: 10%;
Specifies the right position as a percentage of the containing block’s width.
initial
right: initial;
Sets the property to its default value.
inherit
right: inherit;
Inherits the property from its parent element.
auto20px10%0inherit
Context
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.
Preview
👀 Live Preview
The blue box uses position: absolute and right: 20px inside the dashed container.
20px gap from the container’s right edge.
Hands-On
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.
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.
Companion
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.
Compatibility
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 Chrome1+ · All versions
Full support
Mozilla Firefox1+ · All versions
Full support
Apple Safari1+ · macOS & iOS
Full support
Microsoft Edge12+ · All versions
Full support
Opera4+ · Modern versions
Full support
Testing tip
Test percentage-based right values when containers change width in responsive layouts.
right property99% supported
Bottom line:right is one of the most reliable CSS positioning properties across browsers.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about right
Use these points when offsetting from the right edge.
5
Core concepts
★01
auto Default
No offset.
Default
⚙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.