Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS margin-right property

CSS margin-right property

Example

Set the right margin of a p element:

p

{

margin-right:

2

cm

;

}

Try it »


Property definition and usage

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

Note: Negative values are allowed.

Default value: 0
Inherited: no
Version: CSS1
JavaScript syntax: object.style.marginRight="10px"

Browser support

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

property
margin-right 1.0 6.0 1.0 1.0 3.5

Attribute values

Value Description
auto The browser sets the right margin.
length Defines a fixed right margin. The default value is 0.
% Defines a right margin as a percentage of the parent element's total width.
inherit Specifies that the right margin should be inherited from the parent element.

More examples

Example

Set the right margin of a p element to 50% of the container's width:

p

.ex1

{

margin-right:

50

%

;

}

Try it »

Example

Set the right margin of a p element to 15em:

p

.ex1

{

margin-right:

15

em

;

}

Try it »


Related Articles

CSS Tutorial: CSS Margin