
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS - Border Images
- CSS3 - Rounded Corner
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS - Order
The CSS Order Property
The CSS order property is used to specify the order in which flex or grid items appear within a container. The order of the flex or grid items is determined by the values of their order property. The flex/grid items with the lower order value will be displayed first and the items with highest value will be displayed in the last.
Following are all possible values that can be used for property order:
- integer: Represents the ordinal group to be used by the item.
- inherit: Uses the same value of its parent.
- initial: The element uses default value i.e 0.
- unset: The element uses default value i.e 0.
Here are some additional things to keep in mind:
- The order property is not inherited by child elements.
- The order property only affects flex items.
- Items in a container are sorted by ascending order value.
- The default value of the order property is 0.
CSS Order - Demo
Try to select different values for CSS order property and see the result in right box.
CSS Order - Integer Value
The CSS order property can be set to an integer value which can be any positive or negative integer. A positive value means that the item with the highest positive order value will be displayed last and the item with maximum negative value will be displayed as the first item.
Example
Here is an example −
<html> <head> <style> .flex_container { display: flex; background-color: #0ca14a; height: 90px; } .flex_container div { background-color: #FBFF22; padding: 10px; margin: 10px; height: 50px; text-align: center; } </style> </head> <body> <div class="flex_container"> <div style="order: 2">Item 1</div> <div style="order: 6">Item 2</div> <div style="order: 4">Item 3</div> <div style="order: -1">Item 4</div> <div style="order: 5">Item 6</div> <div style="order: -2">Item 7</div> </div> </body> </html>
CSS Order - Initial Value
The order: initial value simply sets the order property of the item back to its initial value, which is usually 0.
Example
Here is an example −
<html> <head> <style> .flex_container { display: flex; background-color: #0ca14a; height: 90px; } .flex_container div { background-color: #FBFF22; padding: 10px; margin: 10px; height: 50px; text-align: center; } </style> </head> <body> <div class="flex_container"> <div style="order: 5">Item 1</div> <div style="order: 3">Item 2</div> <div style="order: 1">Item 3</div> <div style="order: 6">Item 4</div> <div style="order: initial">Item 5</div> <div style="order: 4">Item 6</div> </div> </body> </html>
CSS Order - Unset Value
If you set the order property to unset, the flex item will be displayed in it's default order based on the HTML markup.
Example
Here is an example where order property is set to unset to the flex item 1st and 3rd. Then order of these flex items will be displayed in the default order −
<html> <head> <style> .flex_container { display: flex; background-color: #0ca14a; height: 90px; } .flex_container div { background-color: #FBFF22; padding: 10px; margin: 10px; height: 50px; text-align: center; } </style> </head> <body> <div class="flex_container"> <div style="order: unset">Item 1</div> <div style="order: 4">Item 2</div> <div style="order: unset">Item 3</div> <div style="order: 1">Item 4</div> <div style="order: 3">Item 5</div> <div style="order: 5">Item 6</div> </div> </body> </html>
CSS Order - Revert Value
When we set the order property to the revert value, the flex item will be displayed in the order it appears like as if the webpage had not included any CSS.
Example
Here is an example where Order property is set to revert for the first and fifth flex-items. Now they will appear in the same order as they have been formatted with HTML code.
<!DOCTYPE html> <html> <head> <style> .flex_container { display: flex; background-color: #0ca14a; height: 90px; } .flex_container div { background-color: #FBFF22; padding: 10px; margin: 10px; height: 50px; text-align: center; } </style> </head> <body> <div class="flex_container"> <div style="order: revert">Item 2</div> <div style="order: 3">Item 1</div> <div style="order: 1">Item 3</div> <div style="order: 6">Item 4</div> <div style="order: revert">Item 5</div> <div style="order: 4">Item 6</div> </div> </body> </html>