Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML DOM Image hspace Property

  • Last Updated : 01 Oct, 2021

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:

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

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. 

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:




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!