CSS margin-rightProperty


Example

Set the right margin of a p element:

p { margin-right:2cm; }

Try it Yourself »

Property definition and usage instructions

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 specify the first browser version number that supports the property.

Property
margin-right 1.0 6.0 1.0 1.0 3.5

Property value

Value Description
auto The right margin set by the browser.
length Defines a fixed right margin. The default value is 0.
% Defines a percentage right margin based on the total width of the parent object.
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 width:

p.ex1 { margin-right: 50%; }

Try it Yourself »

Example

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

p.ex1 { margin-right: 15em; }

Try it Yourself »


Related Articles

CSS Tutorial:CSS Margin

other extensions