Open In App

HTML DOM Image hspace Property

Last Updated : 28 Feb, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The HTML DOM Image hspace Property is used to set or return the value of the hspace attribute of an Image element. The hspace Attribute  is used to specify the number of whitespaces on the left and the right side of the image.  

Syntax:

It sets the Image hspace Property.

Imageobject.hspace="pixels";

It returns the Image hspace Property.

Imageobject.hspace;

Property Values: It contains the value i.e. pixels that specify the number of white spaces for the left and the right side of the Image. 

Return Value: It returns a numeric value that represents the number of horizontal spaces around an element. 

Note: The <image> hspace Attribute is not supported in HTML 5.

Example 1: Below code example returns the Image hspace Property. 

HTML




<!DOCTYPE html>
<html>
 
<body>
    <center>
        <h1 style="color: green">GeeksforGeeks</h1>
        <h2>HTML DOM Image hspace Property</h2>
 
         
 
 
<p> <img id="GFG" hspace="25" align="middle"
                src=
                alt="GeeksforGeeks logo">
            It is a computer science portal for Geeks.
        </p>
 
 
 
 
        <br>
        <button onclick="Geeks()">Click me!</button>
        <p id="sudo"></p>
 
 
 
    </center>
     
    <script>
        function Geeks() {
            var g = document.getElementById("GFG").hspace;
            document.getElementById("sudo").innerHTML = g + "px";
        }
    </script>
</body>
 
</html>


Output: 

Example 2: In this example, the code sets the Image hspace Property. 

HTML




<!DOCTYPE html>
<html>
 
<body>
    <center>
        <h1 style="color: green">GeeksforGeeks</h1>
        <h2>HTML DOM Image hspace Property</h2>
 
         
 
 
<p> <img id="GFG" hspace="25" align="middle"
                src=
                alt="GeeksforGeeks logo">
            It is a computer science portal for Geeks.
        </p>
 
 
 
 
        <br>
        <button onclick="Geeks()">Click me!</button>
        <p id="sudo"></p>
 
 
 
    </center>
     
    <script>
        function Geeks() {
            var g = document.getElementById("GFG").hspace;
            document.getElementById("sudo").innerHTML = g + "px";
        }
    </script>
</body>
 
</html>


Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads