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

topMargin property (body)

Browser support:
Specifies or returns the thickness of the top margin in the document body.
This property is deprecated. Use the marginTop style property instead.

Syntax:

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

Possible values:

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

Example HTML code 1:

This example illustrates the use of the topMargin attribute:
<body topmargin="130">
    Some HTML content
</body>
Did you find this example helpful? yes no

Example HTML code 2:

Recommendation:
<body style="margin-top:230px">
    Some HTML content
</body>
Did you find this example helpful? yes no

Example HTML code 3:

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

            if ('topMargin' in document.body) {
                document.body.topMargin = input.value;
            } else {
                alert ("Your browser doesn't support this example!");
            }
        }
    </script>
</head>
<body topmargin="130">
    Some HTML content

    <input id="myInput" type="text" value="200" />
    <button onclick="SetTopMargin ();">Set topMargin!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content