You are here: Reference > JavaScript > client-side > HTML DOM > properties > marginWidth (frame, iframe)

marginWidth property (frame, iframe)

Browser support:
Sets or retrieves the left and right margins for a frame element.


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

Possible values:

String that sets or retrieves the width of the margin, with an integer optionally followed by a 'px' (pixel) unit designator. Negative values are not allowed.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the marginWidth attribute:
<iframe src="frame.htm" width="250px" height="250px" marginwidth="200px"></iframe>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the marginWidth property:
    <script type="text/javascript">
        function SetMarginWidth () {
            var input = document.getElementById ("myInput");
            var iframe = document.getElementById ("myFrame");
            iframe.marginWidth = input.value;

            // To solve the refresh problems
            // Internet Explorer
            iframe.src = iframe.src;
            // Firefox
            var nextElem = iframe.nextSibling;
            var paren = iframe.parentNode;
            paren.removeChild (iframe);
            paren.insertBefore (iframe, nextElem);
    <iframe id="myFrame" src="frame.htm" width="250px" height="210px" marginheight="140px"></iframe>
    <br />

    <input id="myInput" type="text" value="20" />
    <button onclick="SetMarginWidth ();">Set marginWidth!</button>
Did you find this example helpful? yes no

Supported by objects:

External links:

User Contributed Comments

Post Content

Post Content