Easy Tutorial
❮ Pr Pos Vertical Align Sel Attribute Value Lang ❯

CSS margin-right Property

Example

Set the right margin of a paragraph element:

p {
    margin-right: 2cm;
}

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

Property
margin-right 1.0 6.0 1.0 1.0 3.5

Property Values

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

More Examples

Example

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

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

Example

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

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

Related Articles

CSS Tutorial: CSS Margin

❮ Pr Pos Vertical Align Sel Attribute Value Lang ❯