How to use Flexbox in HTML
Flexbox
Flexbox is a module in HTML/CSS that is used to style a number of
A flexbox has several properties:
displayis used to define the flex-container and to specify that something is going to be a flex-container. Thedisplayproperty should be given the value offlex.flex-directiondefines the main axis. The default value isrow, i.e., horizontal left to right. Other options includerow-reverse,column(i.e., top to bottom), andcolumn-reverse.flex-wrapdefines how to wrap items in lines. By default, this property has thenowrapvalue, which tries to fit everything in a single line. Other options includewrap, which overflows items into other lines, andreversewrap, which starts from the bottom and overflows items to the lines above.orderdefines the order of individual items in the list. By default, items are placed in the order of the source code, but integer numbers can be used with theorderproperty to order items in flex-containers.flex-growandflex-shrinkdefine, using a ratio, how many individual items could grow or shrink if required.
Usage
The following example demonstrates how flexbox can be used.
This example shows a few properties of flexbox in use. For instance, using the order property, 2 has been placed after 1 despite being out of position in the HTML file. Also, using the flex-grow property, 3 and 4 have been given double the space the others received. A reverse list has also been produced using flex-direction.
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved