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

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 :

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


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 :

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output :
Before Click.

After Click.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.