CSS margin-right Property

Margin is the spacing outside an element.

The margin-right property specifies the right margin of an element.

Example

#

An element with a 100-pixel margin-right.

An element with a 100px right margin
<div style="margin-right: 100px; background: aliceblue;">
  An element with a 100px right margin
</div>

Using margin-right

The margin-right property accepts any length value, such as, px, %, em, etc.

Margin values can be positive or negative.

Syntax

margin-right: length | auto | initial | inherit;

Values

#

Value Description
length Sets the right margin using any CSS length value. Negative values are allowed.
% Sets right margin in percent.
auto Browser calculates a right margin.
initial Sets the value to its default value.
inherit Inherits the value from its parent element.

More Examples

Click the buttons to see the different margin-right values.

margin-right: 15%
<style>
  .margin-example {
    background: aliceblue;
    margin-right: 15%;
    padding: 10px;
  }
</style>

<div class="margin-example">
  margin-right: 15%
</div>

Browser support

This table shows when margin-right support started for each browser.

Chrome
1.0 Dec 2008
Firefox
1.0 Nov 2004
IE/Edge
6.0 Aug 2001
Opera
3.5 Nov 1998
Safari
1.0 Jun 2003

You may also like

Guides