The margin-right property sets the margin area on the right of an element. A positive value moves neighbors farther away on the right; a negative value pulls them closer.
It is part of the box model (outside the border), is not inherited, and always targets the physical right edge. Prefer margin-inline-end when spacing should follow text direction (LTR/RTL).
Baseline · Widely available.
Not deprecated. Core length, percentage, and auto values work across modern browsers.
Syntax
CSS Syntax
syntax.css
margin-right:<length> | <percentage> | auto | inherit;
Example: margin-right: 1.5rem;. Values may be positive, zero, or negative.
Give the box a width so free space exists in the parent.
Set margin-right: auto. Unused space goes to the right.
The box stays on the left inside the container.
Both sides auto (margin-left and margin-right) centers the box instead.
Edge Cases & Pitfalls
If the right gap looks wrong or missing, check these first.
physical
Always the physical right
In RTL, margin-right still means right — not the end of the text. Use margin-inline-end for direction-aware spacing.
percent
% is based on width
Percentage margins resolve against the containing block’s inline size (width in horizontal writing modes).
vs
margin-right vs padding-right
Use padding-right for inner space (backgrounds extend into padding). Use margin for space between separate boxes.
collapse
Horizontal margins do not collapse
Unlike top/bottom, left and right margins between siblings do not merge into one gap.
auto
auto alone vs both sides
margin-right: auto with a fixed width keeps the box left-aligned. Pair with margin-left: auto to center.
Compatibility
Browser Support
margin-right is a browser CSS property for the box model. Node.js, Deno, and Bun do not apply it.
✓ Baseline · Widely available
margin-right
Length, percentage, and auto values work in all modern browsers and older engines.
99%Browser support
Google ChromeAll modern versions
Full support
Mozilla FirefoxAll modern versions
Full support
Apple SafariAll modern versions
Full support
Microsoft EdgeAll modern versions
Full support
OperaAll modern versions
Full support
Samsung InternetSupported
Full support
Internet ExplorerSupported
Full support
margin-rightWidely supported
Bottom line: Safe for everyday right spacing. Remember RTL vs logical properties. It is not a runtime API.
Remember
Key Takeaways
Role: outer space on an element’s physical right edge.
Initial:0. Not inherited.
Percentages use containing-block width.
auto can keep a box left or help center with margin-left: auto.
One line:margin-right adds outer space on the right — outside the border, before the next neighbor.
Frequently Asked Questions
It sets the outer space on the right of an element, outside its border. A positive value pushes neighbors farther away on the right; a negative value pulls them closer.
The initial value is 0. There is no right margin until you set one.
margin-right is outside the border, between elements. padding-right is inside the border, between the border and the content.
margin-right always targets the physical right edge. margin-inline-end follows writing mode and direction, so it maps to the left in RTL.
It absorbs leftover horizontal space on the right. Alone on a block it can push the box to the left; with margin-left: auto it centers a block that has a defined width.
It is Baseline Widely available. It is a browser CSS box-model property, not a Node.js runtime feature.