ArticleslgStudy

science

Flexbox

Flexbox is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Flexbox rather than just read about it. In short: CSS Flexible Box Layout, commonly known as Flexbox, is a CSS web layout model. It is in the W3C's candidate recommendation (CR) stage.

Key takeaways

  • Flexbox belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Flexbox to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Flexbox from memory before moving on to harder problems.

Reference excerpt

CSS Flexible Box Layout, commonly known as Flexbox, is a CSS web layout model. It is in the W3C's candidate recommendation (CR) stage. The flex layout allows responsive elements within a container to be automatically arranged depending on viewport (device screen) size.

Concepts Most web pages are written in a combination of HTML (Hypertext Markup Language), JavaScript and CSS (Cascading Style Sheets). In short, HTML specifies the content and logical structure of the page, while the CSS specifies how it looks: its colors, fonts, formatting, layout, and styling. CSS flex-box layout is a particular way to specify the layout of HTML pages. 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 fit within its boundaries. Moreover, the flex layout is less restrictive in terms of content flow than that of other CSS layout models, which are generally uni-directional. The flex directional flow can be specified rightwards, leftwards, upwards, or downwards. Individual items within a flex container may also be automatically rearranged to suit the available layout space.

History From the late 2000s onward, the intensive use of the Web 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. CSS modules included solutions akin to this, like flexbox and grid. Flexbox is originally based on a similar feature available in XUL, the user interface toolkit from Mozilla, used in Firefox. As of December 2022, 99.68% of installed browsers (99.59% of desktop browsers and 100% of mobile browsers) support CSS Flexible Box Layout.

Terminology The following terms are associated with the flexbox 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 direct 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. Axes 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. Flex-direction Establishes main axis. Possible arguments: row (default), row-reverse, column, column-reverse. Justify-content Determines how content gets placed on the main axis on the current line. Optional arguments: left, right, center, space-between, space-around. Align-items Determines the default for how flex items get placed on the cross axis on each line. Align-content Determines the default for how cross axis lines are aligned. Align-self Determines how a single item is placed along the cross axis. This overrides any defaults set by align-items.

Directions cross-start cross-end The cross-start/cross-end sides determine where flex lines get filled with flex items from cross-start to cross-end. main-start main-end 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. Order Places elements in groups and determines which order they are to be placed in within the container. Flex-flow Shorthands flex-direction and flex-wrap to place the flex content.

Lines Lines 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.

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

Usage Designating an element as a flex element requires setting the element's CSS display property to either flex or inline-flex, as follows:

Or:

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.

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.

References

Worked examples

Example 1 — a first encounter with Flexbox

Start with the simplest possible case. Write down what Flexbox claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Flexbox before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Flexbox ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Flexbox

In research
Flexbox appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Flexbox in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Flexbox is common in secondary-school and first-year university syllabi. It links to neighbouring topics Cascading Style Sheets layouts, Web design, World Wide Web Consortium standards, so understanding it makes those chapters shorter.
In everyday life
Look for Flexbox outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Flexbox” →

How to study Flexbox in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Flexbox means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Flexbox out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Flexbox in simple terms?

CSS Flexible Box Layout, commonly known as Flexbox, is a CSS web layout model. It is in the W3C's candidate recommendation (CR) stage.

Why does Flexbox matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Flexbox?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Flexbox.

Tags

  • Cascading Style Sheets layouts
  • Web design
  • World Wide Web Consortium standards

Keep exploring