W3cubDocs

/CSS

order

The order CSS property sets the order to lay out an item in a flex or grid container. Items in a container are sorted by ascending order value and then by their source code order.

Syntax

/* <integer> values */
order: 5;
order: -5; 

/* Global values */
order: inherit;
order: initial;
order: unset;

Note: order is only meant to affect the visual order of elements and not their logical or tab order. order must not be used on non-visual media such as speech.

Values

<integer>
Represents the ordinal group to be used by the flex item. May be positive, negative, or 0.

Formal syntax

<integer>

Example

Here is a basic HTML chunk:

<header>...</header>
<main>
  <article>Article</article>
  <nav>Nav</nav>
  <aside>Aside</aside>
</main>
<footer>...</footer>

The following CSS code creates a classic two-sidebar layout surrounding a content block. The Flexible Box Layout Module automatically creates blocks of equal vertical size and uses as much horizontal space as available.

main { display: flex;  text-align:center; }
main > article { flex:1;        order: 2; }
main > nav     { width: 200px;  order: 1; }
main > aside   { width: 200px;  order: 3; }

Result

Accessibility concerns

Using the order property will create a disconnect between the visual presentation of content and DOM order. This will adversely affect users experiencing low vision navigating with the aid of assistive technology such as a screen reader. If the visual (css) order is important, then screen reader users will not have access to the correct reading order.

Specifications

Specification Status Comment
CSS Flexible Box Layout Module
The definition of 'order' in that specification.
Candidate Recommendation Initial definition
Initial value 0
Applies to flex items and absolutely-positioned flex container children
Inherited no
Media visual
Computed value as specified
Animation type an integer
Canonical order the unique non-ambiguous order defined by the formal grammar

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 29
29
21
Prefixed
Prefixed Requires the vendor prefix: -webkit-
12
12
12
Prefixed
Prefixed Requires the vendor prefix: -webkit-
20
20
Since Firefox 28, multi-line flexbox is supported.
49
Prefixed
Prefixed Requires the vendor prefix: -webkit-
48
Prefixed Disabled
Prefixed Requires the vendor prefix: -webkit-
Disabled From version 48: this feature is behind the layout.css.prefixes.webkit preference (needs to be set to true). To change preferences in Firefox, visit about:config.
18 — 28
Disabled
Disabled From version 18 until version 28 (exclusive): this feature is behind the layout.css.flexbox.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
11
11
10
Prefixed
Prefixed Requires the vendor prefix: -ms-
12.1 9
9
7
Prefixed
Prefixed Requires the vendor prefix: -webkit-
Absolutely-positioned flex children Yes 12 No 10 12.1 Yes
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support 4.4
4.4
Yes
Prefixed
Prefixed Requires the vendor prefix: -webkit-
29
29
25
Prefixed
Prefixed Requires the vendor prefix: -webkit-
Yes
Yes
Yes
Prefixed
Prefixed Requires the vendor prefix: -webkit-
20
20
Since Firefox 28, multi-line flexbox is supported.
49
Prefixed
Prefixed Requires the vendor prefix: -webkit-
48
Prefixed Disabled
Prefixed Requires the vendor prefix: -webkit-
Disabled From version 48: this feature is behind the layout.css.prefixes.webkit preference (needs to be set to true). To change preferences in Firefox, visit about:config.
18 — 28
Disabled
Disabled From version 18 until version 28 (exclusive): this feature is behind the layout.css.flexbox.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
12.1 9
9
7
Prefixed
Prefixed Requires the vendor prefix: -webkit-
?
Absolutely-positioned flex children ? ? ? No 12.1 Yes ?

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/order