- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Selectors
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- 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 - Hyphenate Character
- 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 - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- 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
What is an order?
CSS order property is used to specify the order in which flex items appear within a flex container.
The order of the flex items is determined by the values of their order property. The flex items with the lower order value will be displayed first.
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.
-
The default value of the order property is 0.
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.
CSS Order Integer
The CSS order property is set to an integer value. The value of the order property can be any positive or negative integer.
We can use order property with positive integer value. A positive value means that the item with the highest positive order value will be displayed last.
Example
Here is an example −
<html> <head> <style> .my_flex_container { display: flex; background-color: #0ca14a; height: 90px; } .my_flex_container div { background-color: #FBFF22; padding: 10px; margin: 10px; height: 50px; text-align: center; } </style> </head> <body> <div class="my_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: 3">Item 5</div> <div style="order: 5">Item 6</div> </div> </body> </html>
The CSS order property can be set to a negative integer value. A negative value means that the items with the highest negative order value will be displayed first.
Example
Here is an example −
<html> <head> <style> .my_flex_container { display: flex; background-color: #0ca14a; height: 90px; } .my_flex_container div { background-color: #FBFF22; padding: 10px; margin: 10px; height: 50px; text-align: center; } </style> </head> <body> <div class="my_flex_container"> <div style="order: 4">Item 1</div> <div style="order: 6">Item 2</div> <div style="order: -3">Item 3</div> <div style="order: 1">Item 4</div> <div style="order: -5">Item 5</div> <div style="order: 2">Item 6</div> </div> </body> </html>
CSS Order Initial
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> .my_flex_container { display: flex; background-color: #0ca14a; height: 90px; } .my_flex_container div { background-color: #FBFF22; padding: 10px; margin: 10px; height: 50px; text-align: center; } </style> </head> <body> <div class="my_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
If you set the order property to unset value, the flex item will be displayed in it's default orde based on the HTML markup.
Example
Here is an example where order property is set to unset to the flex item 3. Then order of the flex item 3 will be displayed in the default order −
<html> <head> <style> .my_flex_container { display: flex; background-color: #0ca14a; height: 90px; } .my_flex_container div { background-color: #FBFF22; padding: 10px; margin: 10px; height: 50px; text-align: center; } </style> </head> <body> <div class="my_flex_container"> <div style="order: 2">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
When we set the order property to the revert value, the flex item will be displayed in the order it appears in the HTML markup, but with the order reversed.
Example
Here is an example where Order property is set to revert for the fifth flex-item. Then order of the fifth flex-item will be reversed, so it will be displayed first −
<!DOCTYPE html> <html> <head> <style> .my_flex_container { display: flex; background-color: #0ca14a; height: 90px; } .my_flex_container div { background-color: #FBFF22; padding: 10px; margin: 10px; height: 50px; text-align: center; } </style> </head> <body> <div class="my_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: revert">Item 5</div> <div style="order: 4">Item 6</div> </div> </body> </html>