You are here: Reference > JavaScript > client-side > HTML DOM > properties > leftMargin (body)

leftMargin property (body)

Browser support:
Sets or retrieves the left margin for the document body in pixels.
This property is deprecated. Use the marginLeft style property instead.

Syntax:

object.leftMargin;
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: leftMargin

Possible values:

String that sets or retrieves the width of the margin, with an integer optionally followed by a 'px' (pixel) unit designator.
Default: 10.

Example HTML code 1:

This example illustrates the use of the leftMargin attribute:
<body leftmargin="100px">
    The left margin is 100px.
</body>
Did you find this example helpful? yes no

Example HTML code 2:

Recommendation:
<body style="margin-left:100px">
    The left margin is set with <i>margin-left</i> style property.
</body>
Did you find this example helpful? yes no

Example HTML code 3:

This example illustrates the use of the leftMargin property:
<head>
    <script type="text/javascript">
        function SetLeftMargin () {
            var input = document.getElementById ("myInput");

            if ('leftMargin' in document.body) {
                document.body.leftMargin = input.value;
            } else {
                alert ("Your browser doesn't support this example!");
            }
        }
    </script>
</head>
<body leftmargin="100px">
    leftMargin=100px
    
    <input id="myInput" type="text" value="40" />
    <button onclick="SetLeftMargin ();">Set leftMargin!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content