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

HTML DOM Style marginRight Property

Style marginRight Property

Style Object Reference The Style object


Definition and Usage

The marginRight property sets or returns the right margin of an element.

Syntax

Sets the marginRight property:

Object.style.marginRight="

%

|

length

|auto|inherit"

Returns the marginRight property:

Object.style.marginRight

Value Description
% Defines a percentage right margin based on the width of the parent element.
length Defines the width of the right margin using units such as px, cm, etc.
auto The right margin set by the browser.
inherit The right margin is inherited from the parent element.

Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the marginRight property.

**Note:** IE7 and earlier versions do not support the "inherit" value. IE8 supports "inherit" only if a !DOCTYPE is specified. IE9 supports "inherit".


Tips and Notes

Both the margin property and the padding property insert space around an element. However, they differ: margin inserts space outside the border, while padding inserts space inside the border.


Example

Example

Changes the right margin of a div element:

Runoob Tutorial(runoob.com)
This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.



This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.

Try it »


Style Object Reference The Style object