HTML | DOM Style justifyContent Property

The style justifyContent property in HTML DOM is used to align the items horizontally when they are not able to use all the available space. It is used to set the position of the element. By default, the items are positioned at the beginning of the container.

Syntax:

  • It returns the justifyContent property.
    object.style.justifyContent 
  • It used to set the justifyContent property.
    object.style.justifyContent = "flex-start|flex-end|center|
    space-between|space-around|initial|inherit"

Property Values:

  • flex-start: It is used to align flex items from the start of the container.
  • flex-end: It is used to align flex items at the end of the container.
  • center: It align flex items at the center of container.
  • space-between: The flex items are placed with even spacing where the item is pushed to start and last item is pushed to end.
  • space-around: The flex items are placed with equal spacing from each others, the corners.
  • space-evenly: The items are positioned with equal spacing between them but the spacing from corners differ.
  • initial: The items are placed according to the default value.
  • inherit: The items are placed according to its inherited parent element value.

Return Value: It returns a string that represents the justifyContent property of an element.

Example 1: This example describes space-between property value.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
  
<head
    <title>
        DOM Style justifyContent Property 
    </title
      
    <style>
        #GFG { 
            width:500px;
            display:flex;
            height: 80px;
            border:2px solid black;
            background-color:white;
            justify-content: space-around; 
        }
          
        #GFG div {
            width: 60px;
            height: 80px;
        }
    </style>
</head
      
<body
    <center
        <h1 style = "color:green;width:40%;"
            GeeksForGeeks 
        </h1
          
        <h2>DOM Style justifyContent Property </h2>         
          
        <div id = "GFG">
            <div>
                <img src =
                width = "60px" height = "80px">
            </div>
              
            <div>
                <img src
                width = "60px" height = "80px">
            </div>
              
            <div>
                <img src =
                width = "60px" height = "80px">
            </div>
              
            <div>
                <img src =
                width = "60px" height = "80px">
            </div>
              
        </div>
          
        <button type = "button" onclick = "geeks()"
            Submit 
        </button
          
        <!-- Style script used here -->
        <script
            function geeks() { 
            document.getElementById("GFG").style.justifyContent= "space-between"; 
            
        </script
    </center
</body
  
</html>                    

chevron_right


Output:
Before Click on the button:

After Click on the button:

Example 2: This example describes flex-start property value.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html
  
<head
    <title>
        DOM Style justifyContent Property 
    </title
      
    <style>
        #GFG { 
            width:500px;
            display:flex;
            height: 80px;
            border:2px solid black;
            background-color:white;
            justify-content: space-around; 
        }
          
        #GFG div {
            width: 60px;
            height: 80px;
        }
    </style>
</head
      
<body
    <center
        <h1 style = "color:green;width:40%;"
            GeeksForGeeks 
        </h1
          
        <h2>DOM Style justifyContent Property </h2>         
          
        <div id = "GFG">
            <div>
                <img src =
                width = "60px" height = "80px">
            </div>
              
            <div>
                <img src
                width = "60px" height = "80px">
            </div>
              
            <div>
                <img src =
                width = "60px" height = "80px">
            </div>
              
            <div>
                <img src =
                width = "60px" height = "80px">
            </div>
              
        </div>
          
        <button type = "button" onclick = "geeks()"
            Submit 
        </button
          
        <!-- Style script used here -->
        <script
        function geeks() { 
            document.getElementById("GFG").style.justifyContent= "flex-start"; 
        
        </script
    </center
</body
  
</html>                    

chevron_right


Output:
Before Click on the button:

After Click on the button:

Supported Browsers: The browser supported by DOM Style justifyContent property are listed below:

  • Google Chrome
  • Internet Explorer 12.0
  • Firefox
  • Opera


My Personal Notes arrow_drop_up


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.