Skip to content
Related Articles

Related Articles

Improve Article

How to tab space instead of multiple non-breaking spaces (nbsp)?

  • Last Updated : 30 Apr, 2019

In CSS property padding and margin can be used to tab space instead of non-breaking spaces (nbsp).

By using padding property :

By using padding property we can give any amount of spaces in any direction of an element (i.e, top, right, bottom, left) from the border of the element. Here we only deal with the spaces so we need only two padding property i.e, padding-left and padding-right.

Syntax :

 
padding-left : value;
or
padding-right : value;

Parameter : No parameter required.



Example :




<!DOCTYPE html>
<html>
  
<head>
<script src=
</script>
    <style>
        div {
            width: 300px;
            height: 100px;
            background-color: red;
        }
          
        P {
            width: 100px;
            height: 100px;
            background-color: green;
            text-align: center;
            font-weight: bold;
        }
    </style>
    <script>
        $(document).ready(function() {
            $("button").click(function() {
                $("#demo").css("padding-left", "30px");
            });
        });
    </script>
</head>
  
<body>
  
    <div id="demo">
  
        <p> Block 1 </p>
  
        <button>Submit</button>
    </div>
  
</body>
  
</html>

Output :
Before Click.

After Click.

By using margin property :

By using margin property we can give any amount of spaces in any direction of an element (i.e, top, right, bottom, left) from the border of the element. Here we only deal with the spaces so we need only two margin property i.e, margin-left and margin-right.

Syntax :

 
margin-left : value;
or
margin-right : value;

Parameter : No parameter required.

Example :




<!DOCTYPE html>
<html>
  
<head>
<script src=
</script>
    <style>
        div {
            width: 300px;
            height: 100px;
            background-color: red;
        }
          
        P {
            width: 100px;
            height: 100px;
            background-color: green;
            text-align: center;
            font-weight: bold;
        }
    </style>
    <script>
        $(document).ready(function() {
            $("button").click(function() {
                $("#demo").css("margin-left", "60px");
            });
        });
    </script>
</head>
  
<body>
  
    <div>
  
        <p id="demo"> Block 1 </p>
  
        <button>Submit</button>
    </div>
  
</body>
  
</html>

Output :
Before Click.

After Click.

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :