Tailwind CSS Layout Classes
Tailwind CSS provides a rich set of layout-related classes, allowing developers to control every aspect of a page in an extremely flexible way.
Next, we will explain some key layout-related classes in detail.
1. Aspect Ratio
The Aspect Ratio classes can help you set the aspect ratio of elements, avoiding stretching or compression in responsive design.
** Main Classes:**
| Class Names | CSS Property and Value | Description |
|---|---|---|
aspect-auto |
aspect-ratio: auto; |
This class keeps an element at its natural aspect ratio without any forced adjustment. It is suitable when you want the element to size automatically according to its content rather than being forced to fill or shrink to a specific aspect ratio. |
aspect-square |
aspect-ratio: 1 / 1; |
This class forces an element's aspect ratio to 1:1, meaning width and height are equal, commonly used to create square or circular elements. |
aspect-video |
aspect-ratio: 16 / 9; |
This class forces an element's aspect ratio to 16:9, a common video aspect ratio, suitable for elements that display video or simulate a video player. |
Example
Try it »
2. Container
The Container class can make a container element adapt responsively to different screen sizes, commonly used to set the maximum width of content.
** Main Classes:**
container: Make an element a responsive container.mx-auto: Center the container horizontally.
| Class Names | CSS Property and Value | Description |
|---|---|---|
container |
width: 100%; |
The container width defaults to 100%, occupying the entire width of the parent element. |
sm:container |
max-width: 640px; |
When the screen width is greater than or equal to 640px, the container's maximum width is 640px. |
md:container |
max-width: 768px; |
When the screen width is greater than or equal to 768px, the container's maximum width is 768px. |
lg:container |
max-width: 1024px; |
When the screen width is greater than or equal to 1024px, the container's maximum width is 1024px. |
xl:container |
max-width: 1280px; |
When the screen width is greater than or equal to 1280px, the container's maximum width is 1280px. |
2xl:container |
max-width: 1536px; |
When the screen width is greater than or equal to 1536px, the container's maximum width is 1536px. |
When using these classes, you can create containers with responsive maximum widths, which is very useful when creating layouts, especially when you want to limit content width for better readability.
Example
In these examples, the first The Columns classes are used to implement multi-column layouts. You can control the number of columns and the spacing between them. Main Classes: Column 1 Column 2 Column 3 Try it » The following classes can help developers better control the pagination and column layout of documents to improve the readability and aesthetics of printed output. Main Classes: The above classes are used to control the page or column break behavior of content in print or column layouts: The above classes are used to control the page or column break behavior of content in print or column layouts. The above classes are used to control whether content in print or column layouts is allowed to break inside an element into a new page or column. Well, let me tell you something,... Of course, continuing with our content... Maybe we can... If you think this is... In this example, The following are utility classes in Tailwind CSS for controlling how fragments of an element are rendered across multiple lines, columns, or pages, and their corresponding CSS properties: The above classes are used to control how an element's decorations (such as borders and backgrounds) behave in multi-column layouts or when paginating. These utility classes can help developers better control the visual effects of elements in complex layouts. Hello World Hello World Try it » Tailwind CSS provides two utility classes to control an element's box model (box-sizing): 1、box-border CSS Property: Use the box-border utility class to set an element's box-sizing property to border-box. This means when you specify a height or width for the element, the browser includes the element's border and padding. If an element's size is 100px × 100px with a 2px border and 4px padding, the element's total rendered size will be 112px × 112px. 2、box-content CSS Property: Use the box-content utility class to set an element's box-sizing property to content-box. This means the browser adds the border and padding outside the element's specified width or height. If an element's size is 100px × 100px with a 2px border and 4px padding, the element's actual rendered size will be 112px × 112px, with an inner content area of 100px × 100px. Try it » The display property is used to control an element's display type, determining how the element is presented on the page. When controlling text flow, use the CSS property display: inline to make the text inside the element wrap normally. while using the property display: inline-block will wrap the element, preventing its inner text from expanding beyond its parent element. Finally, using the property display: block will make the element occupy a line by itself and fill its parent element. Try it » Use the table, table-row, table-cell, table-caption, table-column, table-column-group, table-header-group, table-row-group, and table-footer-group utility classes to create elements that behave like their corresponding table elements. Song Artist Year The Sliding Mr. Bones (Next Stop, Pottersville) Malcolm Lockyer 1961 Witchy Woman The Eagles 1972 Shining Star Earth, Wind, and Fire 1975 Try it » float-* controls the position of an element's float, commonly used for wrapping text. Main Classes: Try it » Utility classes in Tailwind CSS for controlling how elements clear floats and their corresponding CSS properties: Test text content... Try it » The following are utility classes for controlling stacking contexts These utility classes allow developers to control an element's stacking context behavior, thereby affecting how the element and its descendants participate in stacking order. The isolate class helps create an isolated environment in which an element's stacking order is not affected by external elements, while isolation-auto allows the browser to handle stacking contexts according to default rules. Use the isolate and isolation-auto utility classes to control whether an element should explicitly create a new stacking context. The following are utility classes for controlling how the content of replaced elements is scaled and their corresponding CSS properties: Use object-cover to resize an element's content to cover its container: Try it »lg) and larger screen sizes, its maximum width will be limited to 1024px.mx-autoclass is used to center a container horizontally.
3. Columns
columns-{n}: Set the number of columns.space-x-{size}: Set the spacing between columns.
Class Names
CSS Property and Value
Description
columns-1columns: 1;Set the number of columns of an element to 1.
columns-2columns: 2;Set the number of columns of an element to 2.
columns-3columns: 3;Set the number of columns of an element to 3.
columns-4columns: 4;Set the number of columns of an element to 4.
columns-5columns: 5;Set the number of columns of an element to 5.
columns-6columns: 6;Set the number of columns of an element to 6.
columns-7columns: 7;Set the number of columns of an element to 7.
columns-8columns: 8;Set the number of columns of an element to 8.
columns-9columns: 9;Set the number of columns of an element to 9.
columns-10columns: 10;Set the number of columns of an element to 10.
columns-11columns: 11;Set the number of columns of an element to 11.
columns-12columns: 12;Set the number of columns of an element to 12.
columns-autocolumns: auto;Set the element's column count to automatic, adjusting column widths automatically based on content.
columns-3xscolumns: 16rem; /* 256px */Set the element's column width to 16rem (256px).
columns-2xscolumns: 18rem; /* 288px */Set the element's column width to 18rem (288px).
columns-xscolumns: 20rem; /* 320px */Set the element's column width to 20rem (320px).
columns-smcolumns: 24rem; /* 384px */Set the element's column width to 24rem (384px).
columns-mdcolumns: 28rem; /* 448px */Set the element's column width to 28rem (448px).
columns-lgcolumns: 32rem; /* 512px */Set the element's column width to 32rem (512px).
columns-xlcolumns: 36rem; /* 576px */Set the element's column width to 36rem (576px).
columns-2xlcolumns: 42rem; /* 672px */Set the element's column width to 42rem (672px).
columns-3xlcolumns: 48rem; /* 768px */Set the element's column width to 48rem (768px).
columns-4xlcolumns: 56rem; /* 896px */Set the element's column width to 56rem (896px).
columns-5xl`columns: 64rem; /*
Example
4. Pagination
break-after-{value}: Control the behavior after a page or column break.break-before-{value}: Control the behavior before a page or column break.break-inside-{value}: Control the behavior of page or column breaks inside an element.
Class Names
CSS Property and Value
Description
break-after-autobreak-after: auto;Allow content to break naturally after this element into a new page or column.
break-after-avoidbreak-after: avoid;Try to avoid breaking after this element into a new page or column.
break-after-allbreak-after: all;Force a page or column break after this element, even if it is not a natural break point.
break-after-avoid-pagebreak-after: avoid-page;Try to avoid a page break after this element, but allow a column break.
break-after-pagebreak-after: page;Force a page break after this element, but do not allow a column break.
break-after-leftbreak-after: left;Force a page or column break after this element, preferring the left page.
break-after-rightbreak-after: right;Force a page or column break after this element, preferring the right page.
break-after-columnbreak-after: column;Force a column break after this element, but do not allow a page break.
Class Names
CSS Property and Value
Description
break-before-autobreak-before: auto;Allow content to break naturally before this element into a new page or column.
break-before-avoidbreak-before: avoid;Try to avoid breaking before this element into a new page or column.
break-before-allbreak-before: all;Force a page or column break before this element, even if it is not a natural break point.
break-before-avoid-pagebreak-before: avoid-page;Try to avoid a page break before this element, but allow a column break.
break-before-pagebreak-before: page;Force a page break before this element, but do not allow a column break.
break-before-leftbreak-before: left;Force a page or column break before this element, preferring the left page.
break-before-rightbreak-before: right;Force a page or column break before this element, preferring the right page.
break-before-columnbreak-before: column;Force a column break before this element, but do not allow a page break.
Class Names
CSS Property and Value
Description
break-inside-autobreak-inside: auto;Allow content inside this element to break naturally into a new page or column.
break-inside-avoidbreak-inside: avoid;Try to avoid breaking inside this element into a new page or column.
break-inside-avoid-pagebreak-inside: avoid-page;Try to avoid a page break inside this element, but allow column breaks.
break-inside-avoid-columnbreak-inside: avoid-column;Try to avoid a column break inside this element, but allow page breaks.
Example
columns-2), which contains four paragraphs. The second paragraph has a break-after-column class, which forces a column break after that paragraph but does not allow a page break. This means if there is enough content, the content after the second paragraph will start a new column rather than continuing on the next line of the same column. The other paragraphs have no special column-break instructions and will flow naturally according to the content.
5. Text Wrapping and Breaking
Class Names
CSS Property and Value
Description
box-decoration-clonebox-decoration-break: clone;Specify that when a box is split into multiple boxes (for example, at column or page boundaries), each box should clone the original box's decorations (borders, background, etc.).
box-decoration-slicebox-decoration-break: slice;Specify that when a box is split into multiple boxes, each box should "slice" the original box's decorations so that the decorations appear continuous in each box.
Example
6. Box Sizing
box-border: Include padding and border when calculating the element's total size.box-content: Exclude padding and border when calculating the element's size.box-sizing: border-box;

Example
box-sizing: content-box;

Example
display property
Tailwind Class Name
CSS Property and Value
Description
blockdisplay: block;Display an element as a block-level element; it occupies a line by itself.
inline-blockdisplay: inline-block;Display an element as an inline-block element; it can be displayed inline and have its own width and height.
inlinedisplay: inline;Display an element as an inline element; it is displayed side by side with other inline elements.
flexdisplay: flex;Display an element as a flex container, allowing the use of Flexbox layout.
inline-flexdisplay: inline-flex;Display an element as an inline flex container, allowing the use of Flexbox layout.
tabledisplay: table;Display an element as a table element.
inline-tabledisplay: inline-table;Display an element as an inline table element.
table-captiondisplay: table-caption;Display an element as a table caption.
table-celldisplay: table-cell;Display an element as a table cell.
table-columndisplay: table-column;Display an element as a table column.
table-column-groupdisplay: table-column-group;Display an element as a table column group.
table-footer-groupdisplay: table-footer-group;Display an element as a table footer group.
table-header-groupdisplay: table-header-group;Display an element as a table header group.
table-row-groupdisplay: table-row-group;Display an element as a table row group.
table-rowdisplay: table-row;Display an element as a table row.
flow-rootdisplay: flow-root;Display an element as a flow-root element, which is a BFC (block formatting context).
griddisplay: grid;Display an element as a grid container, allowing the use of CSS Grid layout.
inline-griddisplay: inline-grid;Display an element as an inline grid container, allowing the use of CSS Grid layout.
contentsdisplay: contents;Remove an element's box model so that its child elements are displayed directly in its place.
list-itemdisplay: list-item;Display an element as a list item.
hiddendisplay: none;Hide an element so that it is not displayed on the page.
Example
Example
Floats
Tailwind Class Name
CSS Property and Value
Description
float-startfloat: inline-start;Float an element to the start of its containing block. In LTR (left-to-right) languages, this is usually the left; in RTL (right-to-left) languages, this is usually the right.
float-endfloat: inline-end;Float an element to the end of its containing block. In LTR (left-to-right) languages, this is usually the right; in RTL (right-to-left) languages, this is usually the left.
float-rightfloat: right;Float an element to the right of its containing block.
float-leftfloat: left;Float an element to the left of its containing block.
float-nonefloat: none;Prevent an element from floating so that it does not leave the normal document flow.
Example
Clear floats
Class Names
CSS Property and Value
Description
clear-startclear: inline-start;Clear floated elements on the start side of an element. In LTR (left-to-right) languages, this is usually the left; in RTL (right-to-left) languages, this is usually the right.
clear-endclear: inline-end;Clear floated elements on the end side of an element. In LTR (left-to-right) languages, this is usually the right; in RTL (right-to-left) languages, this is usually the left.
clear-leftclear: left;Clear floated elements on the left side of an element.
clear-rightclear: right;Clear floated elements on the right side of an element.
clear-bothclear: both;Clear floated elements on both sides of an element.
clear-noneclear: none;Do not clear any floated elements, allowing floated elements to follow the element.
Example
isolate
Tailwind Class Name
CSS Property and Value
Description
isolateisolation: isolate;This element will create a new stacking context, which means its descendant elements will not overlap with external elements, even if they have a higher
z-index values.
isolation-autoisolation: auto;The element's stacking context will be determined by the user agent, usually the same as when no
isolation property is set, and descendant elements may overlap with external elements.Example
object-fit
Class Names
CSS Property and Value
Description
object-containobject-fit: contain;Keep the element's aspect ratio and resize it to fit entirely within the container, possibly leaving blank space inside the container.
object-coverobject-fit: cover;Keep the element's aspect ratio and resize it to completely cover the container, possibly cropping some parts of the element.
object-fillobject-fit: fill;Ignore the element's aspect ratio and stretch or compress it to completely fill the container.
object-noneobject-fit: none;Keep the element's original size without scaling.
object-scale-downobject-fit: scale-down;Keep the element's aspect ratio, similar to
contain but choose the smaller size to fit the container, leaving no blank space.Example