Bootstrap 5 Cheat Sheet
Every Bootstrap 5 class, component, and utility in one searchable reference. 58 entries across 8 categories with copy-paste code snippets.
Search or browse by category
Find the class you need
Copy the code snippet
Container
Fixed-width responsive container with max-width at each breakpoint.
<div class="container">
<!-- Content here -->
</div>Container Fluid
Full-width container spanning the entire viewport.
<div class="container-fluid">
<!-- Full-width content -->
</div>Row
Flex container for columns with negative margins for gutters.
<div class="row">
<div class="col">Column 1</div>
<div class="col">Column 2</div>
</div>Column Sizing
Equal-width or specific-width columns spanning 1-12 grid units.
<div class="row">
<div class="col-8">Main (8/12)</div>
<div class="col-4">Sidebar (4/12)</div>
</div>Responsive Columns
Column width that applies at a specific breakpoint (sm, md, lg, xl, xxl) and up.
<div class="row">
<div class="col-12 col-md-6 col-lg-4">
Responsive column
</div>
</div>Gutters
Set gap between columns. g for both axes, gx horizontal, gy vertical. Scale: 0-5.
<div class="row g-3">
<div class="col-6">Gapped col</div>
<div class="col-6">Gapped col</div>
</div>Offset
Move columns to the right by a specified number of grid columns.
<div class="row">
<div class="col-4 offset-4">
Centered column
</div>
</div>Order
Change the visual order of columns. Values: 0-5, first, last.
<div class="row">
<div class="col order-3">Third</div>
<div class="col order-1">First</div>
<div class="col order-2">Second</div>
</div>Headings
Apply heading styles to any element without using heading tags.
<p class="h1">Heading 1 style</p>
<p class="h3">Heading 3 style</p>Display Headings
Larger, more opinionated heading styles for hero sections and landing pages.
<h1 class="display-1">Display 1</h1>
<h1 class="display-4">Display 4</h1>Lead Paragraph
Make a paragraph stand out with larger, lighter text.
<p class="lead">
This is a lead paragraph for introductions.
</p>Font Size
Responsive font size utility from largest (1) to smallest (6).
<p class="fs-1">Font size 1</p>
<p class="fs-4">Font size 4</p>
<p class="fs-6">Font size 6</p>Font Weight
Set the font weight of text from bold to light.
<p class="fw-bold">Bold text</p>
<p class="fw-light">Light text</p>Italic
Set font style to italic or reset to normal.
<p class="fst-italic">Italic text</p>
<p class="fst-normal">Normal style</p>Text Decoration
Control text decoration on links and text elements.
<a href="#" class="text-decoration-none">
Link without underline
</a>
<p class="text-decoration-line-through">Strikethrough</p>Text Truncate
Truncate text with an ellipsis. Requires display: inline-block or block.
<div class="text-truncate" style="max-width: 200px;">
Long text that will be truncated with ellipsis
</div>Text Colors
Apply theme color variants to text content.
<p class="text-primary">Primary text</p>
<p class="text-success">Success text</p>
<p class="text-danger">Danger text</p>Background Colors
Apply theme colors as background. Pair with text-white for contrast.
<div class="bg-primary text-white p-3">Primary</div>
<div class="bg-success text-white p-3">Success</div>Muted Text
Gray text color for secondary or de-emphasized content.
<p class="text-muted">This is secondary text</p>Background Gradient
Add a subtle gradient overlay to any background color.
<div class="bg-primary bg-gradient text-white p-3">
Gradient background
</div>Background Opacity
Adjust background color opacity without affecting child elements.
<div class="bg-primary bg-opacity-25 p-3">
25% opacity background
</div>
<div class="bg-primary bg-opacity-50 p-3">
50% opacity background
</div>Text Colors (B/W)
Set text to white, black, or the default body color.
<p class="text-white bg-dark p-2">White on dark</p>
<p class="text-black bg-light p-2">Black on light</p>Margin
Set margin on all sides. Scale: 0=0, 1=0.25rem, 2=0.5rem, 3=1rem, 4=1.5rem, 5=3rem.
<div class="m-3">Margin on all sides</div>
<div class="mx-auto" style="width:200px">Centered</div>Padding
Set padding on all sides using the spacing scale.
<div class="p-4">Padding all sides</div>
<div class="p-0">No padding</div>Top & Bottom Margin
Set margin-top or margin-bottom individually.
<h2 class="mt-5 mb-3">Section heading</h2>Horizontal & Vertical Padding
Set horizontal (left + right) or vertical (top + bottom) padding.
<button class="px-4 py-2">Padded button</button>Start & End Margin
Set margin-start (left in LTR) or margin-end (right in LTR).
<div class="ms-auto">Pushed to the right</div>
<div class="me-3">Right margin</div>Gap
Set gap between flex or grid children. Use with d-flex or d-grid.
<div class="d-flex gap-3">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>Flex Container
Create a flex or inline-flex container.
<div class="d-flex">
<div>Flex item 1</div>
<div>Flex item 2</div>
</div>Direction
Set the direction of flex items: horizontal or vertical.
<div class="d-flex flex-column">
<div>Stacked item 1</div>
<div>Stacked item 2</div>
</div>Wrap
Allow or prevent flex items from wrapping to new lines.
<div class="d-flex flex-wrap">
<!-- Items wrap when space runs out -->
</div>Justify Content
Align flex items along the main axis.
<div class="d-flex justify-content-between">
<div>Left</div>
<div>Right</div>
</div>Align Items
Align flex items along the cross axis.
<div class="d-flex align-items-center" style="height:100px">
<div>Vertically centered</div>
</div>Flex Grow
Control whether a flex item grows to fill available space.
<div class="d-flex">
<div class="flex-grow-1">Takes remaining space</div>
<div>Fixed width</div>
</div>Flex Shrink
Control whether a flex item shrinks when space is limited.
<div class="d-flex">
<div class="flex-shrink-0">Will not shrink</div>
<div class="flex-shrink-1">Can shrink</div>
</div>Align Self
Override align-items for an individual flex item.
<div class="d-flex" style="height:100px">
<div class="align-self-start">Top</div>
<div class="align-self-center">Middle</div>
<div class="align-self-end">Bottom</div>
</div>Button
Styled button with theme color variants. Add btn-lg or btn-sm for sizing.
<button class="btn btn-primary">Primary</button>
<button class="btn btn-danger">Danger</button>
<button class="btn btn-success btn-lg">Large</button>Outline Button
Outlined button with transparent background that fills on hover.
<button class="btn btn-outline-primary">Outline</button>
<button class="btn btn-outline-danger">Outline Danger</button>Card
Flexible content container with optional header, body, and footer.
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Card content here.</p>
<a href="#" class="btn btn-primary">Action</a>
</div>
</div>Navbar
Responsive navigation header with branding, links, and collapse toggle.
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Brand</a>
<div class="navbar-nav">
<a class="nav-link active" href="#">Home</a>
<a class="nav-link" href="#">About</a>
</div>
</div>
</nav>Badge
Small label for status indicators, counts, or tags.
<span class="badge bg-primary">New</span>
<span class="badge bg-danger">3</span>
<span class="badge rounded-pill bg-success">Active</span>Alert
Contextual feedback message with optional dismiss button.
<div class="alert alert-success" role="alert">
Operation completed successfully!
</div>
<div class="alert alert-danger alert-dismissible fade show">
Error occurred.
<button class="btn-close" data-bs-dismiss="alert"></button>
</div>Table
Styled HTML table with optional stripes, hover highlight, and borders.
<table class="table table-striped table-hover">
<thead>
<tr><th>Name</th><th>Role</th></tr>
</thead>
<tbody>
<tr><td>Alice</td><td>PM</td></tr>
<tr><td>Bob</td><td>Engineer</td></tr>
</tbody>
</table>Form Control
Styled text input with optional sizing variants.
<input type="text" class="form-control" placeholder="Default input">
<input type="text" class="form-control form-control-lg" placeholder="Large input">Form Select
Styled dropdown select element with sizing options.
<select class="form-select">
<option selected>Choose...</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>Form Check
Styled checkboxes, radios, and toggle switches.
<div class="form-check">
<input class="form-check-input" type="checkbox" id="check1">
<label class="form-check-label" for="check1">Checkbox</label>
</div>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="switch1">
<label class="form-check-label" for="switch1">Toggle</label>
</div>Display None
Hide an element completely. Removes it from the document flow.
<div class="d-none">Hidden element</div>Responsive Display
Show or hide elements at specific breakpoints. Values: none, block, flex, inline, grid, table.
<div class="d-none d-md-block">
Hidden on mobile, visible on md+
</div>
<div class="d-block d-lg-none">
Visible below lg only
</div>Position
Set CSS position property for element placement.
<div class="position-relative">
<div class="position-absolute top-0 end-0">
Top-right corner
</div>
</div>Sizing
Set width or height as a percentage of the parent element.
<div class="w-50">50% width</div>
<div class="w-100">Full width</div>Overflow
Control how content that exceeds the element box is handled.
<div class="overflow-auto" style="height: 100px;">
Scrollable content area...
</div>Visibility
Toggle visibility without changing layout. Unlike d-none, invisible elements still take up space.
<div class="visible">Visible element</div>
<div class="invisible">Hidden but takes space</div>Border
Add borders on all or specific sides with optional width control.
<div class="border p-3">Default border</div>
<div class="border border-3 p-3">3px border</div>
<div class="border-bottom p-3">Bottom only</div>Border Color
Set border color using theme color variants.
<div class="border border-primary border-2 p-3">
Primary border
</div>
<div class="border border-danger border-2 p-3">
Danger border
</div>Rounded
Set border-radius with preset values, circle, or pill shapes.
<img src="avatar.jpg" class="rounded-circle" width="80">
<span class="rounded-pill bg-primary text-white px-3 py-1">
Pill badge
</span>Shadow
Add or remove box-shadow from small to large.
<div class="shadow-sm p-3 mb-3">Small shadow</div>
<div class="shadow p-3 mb-3">Regular shadow</div>
<div class="shadow-lg p-3">Large shadow</div>Opacity
Set the opacity of an entire element including its children.
<div class="opacity-100">Full opacity</div>
<div class="opacity-50">Half opacity</div>
<div class="opacity-25">Quarter opacity</div>Border Remove
Remove borders from all or specific sides of an element.
<div class="border border-top-0 p-3">
No top border
</div>Get More Developer Resources
Join our newsletter for cheat sheets, code snippets, and developer tools delivered weekly.
Get this + weekly PM tools and templates.