CSS Flex Box Layout

CSS flex-box layout is a CSS3 web layout model. It is in the W3C's candidate recommendation (CR) stage.[1] The flex layout allows responsive elements within a container to be automatically arranged depending upon screen size (or device).


One of the most defining features of the flex layout is its ability to form-fit, based on its viewing environment. Flex boxes can adjust in size--either decreasing, to avoid unnecessarily monopolizing space, or increasing to make room for contents to be constrained within its boundaries. Moreover, the flex layout is less restrictive in terms of content flow than those, for example, of the block and inline display types, which are generally uni-directional. Indeed, not only can flex directional flow be specified, at the style level, as rightwards, leftwards, upwards, or downwards; individual items within a flex container may also be automatically reordered and rearranged to suit the available layout space.[2]


In the 2000s the intensive internet access by mobile agents motivated "liquid layouts" and responsive elements for the growing variety of screen sizes. In the 2010s, the intensive use of popular JavaScript layout frameworks, such as Bootstrap, inspired CSS flex-box and grid layout specifications.[3][4]


Following are a few terms associated with the flex layout model

Flex container

Parent element that holds all flex items. Using the CSS display property, the container can be defined as either flex or inline-flex.

Flex item

Any child element held within the flex container is considered a flex item. Any text within the container element is wrapped in an unknown flex item.


Each flex box contains two axes: the main and cross axes. The main axis is the axis on which the items align with each other. The cross axis is perpendicular to the main axis.


Establishes main axis. Optional arguments: row (default), row-reverse, column, column-reverse.


Determines how content gets placed on the main axis on the current line. Optional arguments: left, right, center, space-between, space-around.


Determines the default for how flex items get placed on the cross axis on each line.


Determines the default for how cross axis lines are aligned.


Determines how a single item is placed along the cross axis. This overrides any defaults set by align-items.


The main-start/main-end sides determine where to start placing flex items within the flex container, starting from the main-start end and going to the main-end end. The cross-start/cross-end sides determine where flex lines get filled with flex items from cross-start to cross-end.


Places elements in groups and determines which order they are to be placed in within the container.


Shorthands flex-direction and flex-wrap to place the flex content.


Flex items can either be placed on a singular line or on multiple lines as defined by the flex-wrap property, which controls both the direction of the cross axis and how lines stack within the container.


Main size and cross size are essentially the height and width of the flex container, each dealing with the main and cross axes respectively.

Designate a flex box

Designating an element as a flex element is relatively easy. All that is necessary is to set the display property to either flex or inline-flex as follows:

display: flex;


display: inline-flex;

By setting the display to one of the two values above, an element becomes a flex container and its children flex items. Setting the display to flex makes the container a block-level element, while setting the display to inline-flex makes the container an inline-level element.[5]

Align to center

One of flexbox's advantages is the ability to easily align items within the container to the center of a page, both vertically and horizontally.

display: flex;
align-items: center;
justify-content: center;


  This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.



Connect with defaultLogic
What We've Done
Led Digital Marketing Efforts of Top 500 e-Retailers.
Worked with Top Brands at Leading Agencies.
Successfully Managed Over $50 million in Digital Ad Spend.
Developed Strategies and Processes that Enabled Brands to Grow During an Economic Downturn.
Taught Advanced Internet Marketing Strategies at the graduate level.

Manage research, learning and skills at defaultLogic. Create an account using LinkedIn or facebook to manage and organize your IT knowledge. defaultLogic works like a shopping cart for information -- helping you to save, discuss and share.

  Contact Us