Skip to content
Related Articles

Related Articles

CSS | order property

View Discussion
Improve Article
Save Article
  • Last Updated : 30 Jun, 2022
View Discussion
Improve Article
Save Article

This property is used to specify the order of each flexible item in relation to other items inside the flexible container. It only gives the position to the items present in the container and categorized into a different order as desired by the user. If the element is not the flexible item then this property does not exist anymore.

Syntax: 

order: number|initial|inherit;

Property values: 

1. number: This property is used to specify the order for the flexible item and it gives a number to each item according to the requirement for the user.

Syntax: 

order:number;

Example: 

HTML




<!DOCTYPE html>
<html>
    <head>
        <title>order property</title>
        <style>
            #main {
                width: 400px;
                height: 260px;
                border: 5px solid black;
                display: flex;
                flex-wrap: nowrap;
                margin-left:70px;
                margin-bottom:70px;
            }
             
            #main div {
                width: 100px;
                height: 50px;
            }
            h1 {
                color:#009900;
                font-size:42px;
                margin-left:50px;
                margin-top:50px;
            }
            h2{
                color:green;
                margin-left:100px;
            }
            }
            h3 {
                margin-top:-20px;
                margin-left:50px;
            }
            div#gfg{order:4;}
            div#geeks{order:5;}
            div#sudo{order:6;}
            div#for{order:1;}
            div#geek{order:2;}
            div#g{order:3;}
            div{
                color:white;}
            }
        </style>
    </head>
    <body>
        <center>
        <h1>GeeksforGeeks</h1>
        <h2>order:number;</h2>
        <div id="main">
            <div style="background-color:#009900;"id="gfg">
               geeks</div>
            <div style="background-color:#00cc99;"id="geeks">
               for</div>
            <div style="background-color:#0066ff;"id="sudo">
               geeks3</div>
            <div style="background-color:#66ffff;color:black;"
                    id="for">
               sudo</div>
            <div style="background-color:#660066;"id="geek">
               placement</div>
            <div style="background-color:#663300;"id="g">
               GFG</div>
        </div>
        </center>
    </body>
</html>                               

Output: 

 

2. initial: It sets the property to its default value.

Syntax: 

order:initial;

Example: 

HTML




<!DOCTYPE html>
<html>
    <head>
        <title>order property</title>
        <style>
            #main {
                width: 400px;
                height: 260px;
                border: 5px solid black;
                display: flex;
                flex-wrap: nowrap;
                margin-left:70px;
                margin-bottom:70px;
            }
              
            #main div {
                width: 100px;
                height: 50px;
            }
            h1 {
                color:#009900;
                font-size:42px;
                margin-left:50px;
                margin-top:50px;
            }
            h2{
                color:green;
                margin-left:100px;
            }
            }
            h3 {
                margin-top:-20px;
                margin-left:50px;
            }
            div{
                order:initial;}
            }
        </style>
    </head>
    <body>
        <center>
        <h1>GeeksforGeeks</h1>
        <h2>order:initial;</h2>
        <div id="main">
            <div style="background-color:#009900;">
              geeks</div>
            <div style="background-color:#00cc99;">
              for</div>
            <div style="background-color:#0066ff;">
              geeks3</div>
            <div style="background-color:#66ffff;color:black;"
                    id="for">
              sudo</div>
            <div style="background-color:#660066;">
              placement</div>
            <div style="background-color:#663300;">
              GFG</div>
        </div>
        </center>
    </body>
</html>              

Output: 
 

Supported Browsers: The browser supported by order property are listed below: 

  • Google Chrome 29
  • Edge 12
  • Internet Explorer 11
  • Firefox 20
  • Opera 12.1
  • Safari 9

 


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!