CSS margin-right property

Definition and Usage

The marginRight property sets the right outer margin of the element.

Note:Negative values are allowed.

See Also:

CSS Tutorial:CSS Margin

HTML DOM Reference Manual:marginRight Property

Example

Set the right outer margin of the p element:

p
  {
  margin-right:2cm;
  }

Try It Yourself

(More examples can be found at the bottom of the page)

CSS Syntax

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

Property Value

Value Description
auto Right outer margin set by the browser.
length Define a fixed right outer margin. The default value is 0.
% Specify the right outer margin as a percentage of the containing element's width.
inherit Specifies that the right outer margin should be inherited from the parent element.

Technical Details

Default Value: 0
Inheritance: no
Version: CSS1
JavaScript Syntax: object.style.marginRight="10px"

More Examples

Set the right outer margin of text 1
This example demonstrates how to set the right outer margin of text using centimeter values.
Set the right outer margin of text 2
This example demonstrates how to set the right outer margin of text using percentage values.

Browser Support

The numbers in the table indicate the first browser version that fully supports this attribute.

Chrome IE / Edge Firefox Safari Opera
1.0 6.0 1.0 1.0 3.5