Share via


margin-left

Sets the height of the left margin of the object.

Syntax

{ margin-left: sWidth}

Possible values

sWidth

Variant that specifies or receives one of the following values:

auto

Default. Left margin is set equal to the right margin.

width

Floating-point number, followed by an absolute units designator (cm, mm, in, pt, or pc) or a relative units designator (em, ex, or px).

For more information about the supported length units, see Length units reference.

percentage

Integer, followed by a percent sign (%). The value is a percentage of the height of the parent object.

The property has a default value of auto and is not inherited.

Remarks

For inline elements, the value of this property is used to compute the border area of a surrounding inline element, if it is present. This value does not contribute to the height of a line.

Negative margins are supported, except for top and bottom margins on inline objects.

Examples

The following example uses the margin-left property to change the margin of the object. This example uses the HR element as a selector and margin1 as a class in an embedded style sheet to set the top margin of the horizontal rule:

<style>
    hr { margin-left: 2cm; }
    .margin1 { margin-left: 4cm; }
</style>
</head>
<body>
<hr onclick="this.className='margin1'" ondblclick="this.className=''">
</style>

This example uses inline scripting to set and reset the margin when the onclick and ondblclick events occur, respectively:

<hr onclick="this.style.margin-left='2cm'" 
ondblclick="this.style.margin-left =''">

Standards information

This property is defined in Cascading Style Sheets (CSS), Level 1 (CSS1) Ee371308.xtlink_newWindow(en-us,Expression.40).png.

Applies to

a, abbr, acronym, b, bdo, big, blockquote, body, button, caption, center, cite, code, custom, dd, defaults, del, dfn, div, dl, dt, em, embed, fieldset, font, form, hn, hr, i, iframe, img, input type=button, input type=checkbox, input type=file, input type=image, input type=password, input type=radio, input type=reset, input type=submit, input type=text, ins, li, object, ol, p, q, s, span, sub, table, td, th, tt, u, ul, var, xmp

See also

Concepts

margin
padding

Send feedback about this topic to Microsoft. © 2011 Microsoft Corporation. All rights reserved.