margin

The margin property is a shorthand property for setting margin-top, margin-right, margin-bottom, and margin-left.

Syntax

margin: [ <length> | <percentage> | auto ]{1,4} | inherit
Initial: 0
Applies To: all elements except elements with table display types other than table-caption, table and inline-table
Inherited: no
Percentages: refer to width of containing block
Media: visual

Values

margin: value
Value Initial Description
auto Specifies an automatically generated value
length 0 Specifies a fixed length
percentage Specifies a percentage of the containing block

DOM

[window.]document.getElementById("element-id").style.margin = "margin-top margin-right margin-bottom margin-left";

Example | auto

Example | length

Example | percentage

Example | DOM

External

W3C Cascading Style Sheets, level 1

W3C Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification

W3C CSS basic box model