Bootstrap 5.3 Layout System
Bootstrap's layout system is built on flexbox and provides a powerful 12-column grid for creating responsive layouts. This skill covers containers, the grid system, breakpoints, and layout utilities.
Breakpoints
Bootstrap's responsive design uses six default breakpoints:
Breakpoint Class infix Dimensions Extra small None <576px Small sm ≥576px Medium md ≥768px Large lg ≥992px Extra large xl ≥1200px Extra extra large xxl ≥1400px
Breakpoints apply at the specified width and up (mobile-first).
Containers
Containers are the fundamental building block for layouts.
Container Types
Container Max-Widths xs<576px sm≥576px md≥768px lg≥992px xl≥1200px xxl≥1400px .container 100% 540px 720px 960px 1140px 1320px .container-sm 100% 540px 720px 960px 1140px 1320px .container-md 100% 100% 720px 960px 1140px 1320px .container-lg 100% 100% 100% 960px 1140px 1320px .container-xl 100% 100% 100% 100% 1140px 1320px .container-xxl 100% 100% 100% 100% 100% 1320px .container-fluid 100% 100% 100% 100% 100% 100% Grid System
The grid uses a series of containers, rows, and columns.
Basic Structure
Equal-Width Columns
Specific Column Widths
Use .col-{number} for specific widths (1-12):
Responsive Columns
Combine breakpoint infixes for responsive behavior:
Auto-Layout Columns
Row Columns
Control the number of columns per row:
Gutters
Gutters are the gaps between columns. Default is 1.5rem (24px).
Horizontal Gutters (gx-*)
Vertical Gutters (gy-*)
Both Gutters (g-*)
Responsive Gutters
Column Alignment Vertical Alignment
Horizontal Alignment
Column Ordering Order Classes
Offset Classes
Nesting
Columns can be nested:
Advanced Grid Behaviors Column Wrapping
When more than 12 columns are placed within a single row, the extra columns wrap onto a new line as one unit:
Column Breaks
Force columns to a new line by inserting a full-width element:
Apply breaks at specific breakpoints using display utilities:
Standalone Column Classes
Use .col-* classes outside a .row to give elements a specific width. When used outside a row, column padding is omitted:
Combine with float utilities for responsive floated images:
Text wraps around the floated image...
Handling Gutter Overflow
Large gutters (like .gx-5) can cause horizontal overflow. Two solutions:
Add matching padding to the container:
Or use an overflow-hidden wrapper:
CSS Grid (Alternative)
Note: Bootstrap's CSS Grid system is experimental and opt-in as of v5.1.0. It's disabled by default and requires enabling in your Sass configuration.
Bootstrap 5.3 also supports CSS Grid:
Z-Index Utilities
Bootstrap provides z-index utility classes for controlling stacking order.
Utility Classes Class Value .z-n1 -1 .z-0 0 .z-1 1 .z-2 2 .z-3 3
These low single-digit values (1, 2, 3) are useful for controlling component states like default, hover, and active within the same stacking context.
Component Stacking Order
Bootstrap components use a standardized z-index scale with large gaps to prevent conflicts:
Component z-index Dropdown 1000 Sticky 1020 Fixed 1030 Offcanvas backdrop 1040 Offcanvas 1045 Modal backdrop 1050 Modal 1055 Popover 1070 Tooltip 1080 Toast 1090
Warning: Avoid customizing individual z-index values. The scale is designed as a cohesive system—if you change one value, you likely need to adjust others to maintain proper layering. Use Sass variables ($zindex-dropdown, $zindex-modal, etc.) to customize these values consistently.
See references/grid-reference.md for position utilities that work with z-index.
Common Layout Patterns Sidebar Layout
Card Grid
Sass Customization
When compiling Bootstrap from source, you can customize the layout system through Sass variables and mixins.
Key Variables // Override before importing Bootstrap $grid-columns: 12; // Change to 16 or 24 for finer control $grid-gutter-width: 1.5rem; // Adjust column gaps $enable-cssgrid: true; // Enable CSS Grid classes
Media Query Mixins // Mobile-first (applies at breakpoint and UP) @include media-breakpoint-up(md) { ... }
// Desktop-first (applies BELOW breakpoint) @include media-breakpoint-down(lg) { ... }
// Range (applies BETWEEN two breakpoints) @include media-breakpoint-between(sm, xl) { ... }
// Single breakpoint only @include media-breakpoint-only(md) { ... }
Grid Mixins
Create semantic grid layouts without utility classes:
.blog-layout { @include make-row(); }
.blog-main { @include make-col-ready(); @include make-col(8); // 8 of 12 columns }
.blog-sidebar { @include make-col-ready(); @include make-col(4); // 4 of 12 columns }
See references/sass-customization.md for complete variable reference and mixin documentation.
Additional Resources Reference Files references/grid-reference.md - Complete grid class reference references/sass-customization.md - Sass variables and mixins for layout customization Example Files examples/responsive-layouts.html - Responsive layout patterns examples/sass-customization.scss - Sass customization examples