×

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:

CSS Order

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:

CSS Order

Related Topics

CSS Word-spacing

Word-spacing The work-spacing property of CSS is applied to manage the space among the words. We can decrease or increase the space among the words by the use of this property. It...

3 minutes read.

CSS Images

Images in CSS: Images are a critical part of a web application. It includes various types of images in the web application that cannot be recommended. However, it is essential...

4 minutes read.

CSS User Interface

Introduction User Interface can be defined as series of visual elements like screens, buttons, forms that help the user interact with the software application or hardware device. CSS User Interface allows the...

6 minutes read.

How to change font size in CSS

How to change font size in CSS? Font Size: - Users may attract attention to content on a website page in various ways. One element in a sentence can be highlighted. You...

5 minutes read.

How to center a table in CSS

The table is used to store and arrange the data in tabular format. The data here can be of any form like text, image, links, etc. The table is made...

3 minutes read.

CSS Inline

What is CSS? CSS is an acronym for Cascading Style Sheets. CSS is the language that we use to style an HTML document. It specifies how HTML components should appear. CSS...

4 minutes read.

What is CSS

CSS stands for Cascading Style Sheet. It gives an additional style to the HTML document. A cascading style sheet is a language that is designed to define the document formatting...

3 minutes read.

CSS Content Property

Content Property The content attribute produces dynamic content. It can be applied with any pseudo-element ::after and ::before. These CSS properties are entirely supported inside every browser and applied to include...

5 minutes read.

CSS Background

CSS Background The properties of CSS background are applied to describe the effects of background on the element. Here are five properties of background that affects various elements of HTML: Background-colorBackground-imageBackground-repeatBackground-attachment Background-position Background-color The color of the background...

7 minutes read.

CSS Line Height

CSS Line Height: This property in CSS can be used to describe the line box’s minimal height inside the element. It sets-up the distinction among two lines in our content. It...

3 minutes read.

CSS Overlay

CSS Overlay: It measures to cover-up something’s surface along with a coating. CSS overlay sets anything over the top area of other things. It creates a web-page more attractive. The...

8 minutes read.

CSS 3D Transform

Introduction To understand 3D transformation property of transform you need to first understand the difference between 2D and 3D transform. 2D transform is a CSS effect which transforms the elements according to...

6 minutes read.

CSS Page-break-after Attribute

Page-break-after Attribute As its name implies, the page-break-before property is applied to include page break after any element, at the time of printing a document. It adds the page break after...

5 minutes read.

CSS Text-decoration

CSS Text-decoration: It is an essential property of CSS that is used to decorate the content of the text. It can add-on the lines above, under, and over the text....

3 minutes read.

Radial-gradient() CSS function

Radial-gradient() CSS function It defines a CSS in-built function, which produces a smooth transition among multiple colors. It is used to set any radial-gradient that is same as a background-image. This...

4 minutes read.

CSS Clip

CSS Clip The Clip property in CSS describes the element’s visible area. It applies over the elements which are absolutely positioned (position: absolute ;). Generally, it is used when an image...

2 minutes read.

How To Use CSS

You can use CSS(Cascading Style Sheet) in four ways. These are given below: The given above CSS type, in which various technique will be used. These are different from each other and...

2 minutes read.

Is CSS a programming language?

 A programming language is a set of grammatical rules and a vocabulary for commanding a machine to accomplish specified tasks. High-level languages like BASIC, C, C++, COBOL, Java, FORTRAN, Ada...

4 minutes read.

CSS Units

CSS Units In CSS, there are so many units available to show the length’s measurement. A single unit of CSS is applied to examine the size of the property, which the...

5 minutes read.

How to include CSS

How to include CSS CSS is included in HTML pages for formatting the documents based on the information inside a style sheet. We can add CSS in HTML documents in the following three ways: Inline...

5 minutes read.