CSS Order
CSS Order
CSS order property in CSS describes the flex item’s order inside the flex or any grid container. It is applied to order any flex item.
Note: If any component is not flexible, then CSS order will not implement.
The components will be shown in the order value’s increasing order. When two components use any same value of the order, these components will be shown according to their occurrence specified inside the code.
This CSS property changes the flex item’s visual order. The lowest order item will come first, and the higher-order item will be positioned afterward. Instead of logical or tab order, it affects only the element’s visual order. It should not be used over any non-visual media like speech.
This property allows the order’s negative values. These values are helpful if we wish to show an element first, and unchanged the other order elements. In case any value is not specified, then the 0 value will be applied, i.e., a default value. Thus, if we wish to show an element first, we may give it any negative value like -1. As -1 value is lesser than 0, any corresponding element will be displayed first always.
Syntax:
order: integer | initial | inherit;
Property Values
This property applies the values as integer to define the item’s order.
integer: It
is applied to describe any flexible item’s order. It has a default value, i.e., 0.
initial: It sets the value of the property to its default value.
inherit: As the name suggests, the component applies any computed value from its parent component.
Let’s take some illustrations to understand this order property.
Example1:
<!DOCTYPE html> <html> <head> <style> body { text-align: center; } .container { display: flex; background-color: yellow; height: 150px; width: auto; flex-wrap: wrap; } div { background-color: aqua; line-height: 40px; color: black; padding: 10px; text-align: center; font-size: 35px; width: 100px; margin: 20px; } </style> </head> <body> <h1> Order Property </h1> <div class= "container"> <div style= "order: 3"> 1 </div> <div style= "order: 0"> 2 </div> <div style= "order: 0"> 3 </div> <div style= "order: 1"> 4 </div> <div style= "order: -1"> 5 </div> <div style= "order: 2"> 6 </div> <div style= "order: 1"> 7 </div> <div style= "order: -2"> 8 </div> </div> </body> </html>
In the above illustration, we applied some negative values and few component similar order values. The component including small values are displayed first and some similar order values are displayed based on the code occurrence.
On the other hand, a div element which contains -2 order value will appear first, and the div element which contains -1 order value will appear. This process will same for all other elements.
Output:

Example2:
<!DOCTYPE html> <html> <head> <style> .container { padding: 0; margin: 0; list-style: none; display: flex; } .list { padding: 5px; width: 100px; height: 100px; margin: 5px; line-height: 100px; color: black; font-size: 30px; text-align: center; } </style> </head> <body> <h2> Order Property </h2> <ul class= "container"> <li class= "list" style= "order: 5; background-color: orange;"> 1 </li> <li class= "list" style= "order: -1; background-color: aqua;"> 2 </li> <li class= "list" style= "order: 1; background-color: pink;"> 3 </li> <li class= "list" style= "order: 2; background-color: violet;"> 4 </li> <li class= "list" style= "order: 0; background-color: tomato;"> 5 </li> </ul> </body> </html>
Output:
