
- Bootstrap Tutorial
- Bootstrap - Home
- Bootstrap - Overview
- Bootstrap - Environment Setup
- Bootstrap - RTL
- Bootstrap - CSS Variables
- Bootstrap - Color Modes
- Bootstrap Layouts
- Bootstrap - Breakpoints
- Bootstrap - Containers
- Bootstrap - Grid System
- Bootstrap - Columns
- Bootstrap - Gutters
- Bootstrap - Utilities
- Bootstrap - Z-index
- Bootstrap - CSS Grid
- Bootstrap Content
- Bootstrap - Reboot
- Bootstrap - Typography
- Bootstrap - Images
- Bootstrap - Tables
- Bootstrap - Figures
- Bootstrap Components
- Bootstrap - Accordion
- Bootstrap - Alerts
- Bootstrap - Badges
- Bootstrap - Breadcrumb
- Bootstrap - Buttons
- Bootstrap - Button Groups
- Bootstrap - Cards
- Bootstrap - Carousel
- Bootstrap - Close button
- Bootstrap - Collapse
- Bootstrap - Dropdowns
- Bootstrap - List Group
- Bootstrap - Modal
- Bootstrap - Navbars
- Bootstrap - Navs & tabs
- Bootstrap - Offcanvas
- Bootstrap - Pagination
- Bootstrap - Placeholders
- Bootstrap - Popovers
- Bootstrap - Progress
- Bootstrap - Scrollspy
- Bootstrap - Spinners
- Bootstrap - Toasts
- Bootstrap - Tooltips
- Bootstrap Forms
- Bootstrap - Forms
- Bootstrap - Form Control
- Bootstrap - Select
- Bootstrap - Checks & radios
- Bootstrap - Range
- Bootstrap - Input Groups
- Bootstrap - Floating Labels
- Bootstrap - Layout
- Bootstrap - Validation
- Bootstrap Helpers
- Bootstrap - Clearfix
- Bootstrap - Color & background
- Bootstrap - Colored Links
- Bootstrap - Focus Ring
- Bootstrap - Icon Link
- Bootstrap - Position
- Bootstrap - Ratio
- Bootstrap - Stacks
- Bootstrap - Stretched link
- Bootstrap - Text Truncation
- Bootstrap - Vertical Rule
- Bootstrap - Visually Hidden
- Bootstrap Utilities
- Bootstrap - Backgrounds
- Bootstrap - Borders
- Bootstrap - Colors
- Bootstrap - Display
- Bootstrap - Flex
- Bootstrap - Floats
- Bootstrap - Interactions
- Bootstrap - Link
- Bootstrap - Object Fit
- Bootstrap - Opacity
- Bootstrap - Overflow
- Bootstrap - Position
- Bootstrap - Shadows
- Bootstrap - Sizing
- Bootstrap - Spacing
- Bootstrap - Text
- Bootstrap - Vertical Align
- Bootstrap - Visibility
- Bootstrap Demos
- Bootstrap - Grid Demo
- Bootstrap - Buttons Demo
- Bootstrap - Navigation Demo
- Bootstrap - Blog Demo
- Bootstrap - Slider Demo
- Bootstrap - Carousel Demo
- Bootstrap - Headers Demo
- Bootstrap - Footers Demo
- Bootstrap - Heroes Demo
- Bootstrap - Featured Demo
- Bootstrap - Sidebars Demo
- Bootstrap - Dropdowns Demo
- Bootstrap - List groups Demo
- Bootstrap - Modals Demo
- Bootstrap - Badges Demo
- Bootstrap - Breadcrumbs Demo
- Bootstrap - Jumbotrons Demo
- Bootstrap-Sticky footer Demo
- Bootstrap-Album Demo
- Bootstrap-Sign In Demo
- Bootstrap-Pricing Demo
- Bootstrap-Checkout Demo
- Bootstrap-Product Demo
- Bootstrap-Cover Demo
- Bootstrap-Dashboard Demo
- Bootstrap-Sticky footer navbar Demo
- Bootstrap-Masonry Demo
- Bootstrap-Starter template Demo
- Bootstrap-Album RTL Demo
- Bootstrap-Checkout RTL Demo
- Bootstrap-Carousel RTL Demo
- Bootstrap-Blog RTL Demo
- Bootstrap-Dashboard RTL Demo
- Bootstrap Useful Resources
- Bootstrap - Questions and Answers
- Bootstrap - Quick Guide
- Bootstrap - Useful Resources
- Bootstrap - Discussion
Bootstrap - Stacks
This chapter discusses about stacks. A stack is an utility class that can be used to control the stacking of content within a container.
The stack utility class controls the stacking order of elements. Stacks offer a quick and easy way of applying the flexbox properties to create layouts in Bootstrap.
Vertical stack
The class .vstack is used to create vertical layouts. The utilities such as .gap-* can be used to add space between items.
By default, the stacked items are full-width.
The example given below shows the usage of .vstack class:
Example
You can edit and try running this code using the Edit & Run option.
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Helper - Stack</title> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script> </head> <body> <h4>Vertical stack example</h4><br> <div class="vstack gap-1"> <div class="text-bg-secondary p-2">Item on First place</div> <div class="text-bg-primary p-2">Item on Second place</div> <div class="text-bg-info p-2">Item on Third place</div> </div> </body> </html>
Stack the buttons or any other elements, using the class .vstack.
Example
You can edit and try running this code using the Edit & Run option.
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Helper - Stack</title> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script> </head> <body> <h4>Vertical stack using buttons</h4><br> <div class="vstack gap-3 col-md-4 mx-auto"> <button type="button" class="btn btn-success">Confirm changes</button> <button type="button" class="btn btn-secondary">Cancel</button> </div> </body> </html>
Horizontal stack
The class .hstack is used to create horizontal layouts. The utilities such as .gap-* can be used to add space between items.
By default, the stacked items are vertically centered and only take up their necessary width.
The example given below shows the usage of .hstack class:
Example
You can edit and try running this code using the Edit & Run option.
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Helper - Stack</title> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script> </head> <body> <h4>Horizontal stack example</h4><br> <div class="hstack gap-3 column-gap-3"> <div class="text-bg-warning p-2">Item one</div> <div class="text-bg-light p-2">Item two</div> <div class="text-bg-secondary p-2">Item three</div> </div> </body> </html>
The horizontal margin utility like .ms-auto can be used to add spaces. The utility class .ms-auto aligns the text to the right of the screen. Let's see an example:
Example
You can edit and try running this code using the Edit & Run option.
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Helper - Stack</title> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script> </head> <body> <h4>Horizontal margin example</h4><br> <div class="hstack gap-3 column-gap-3"> <div class="text-bg-primary p-2">Item one</div> <div class="text-bg-secondary p-2">Item two</div> <div class="text-bg-info p-2 ms-auto">Item three</div> </div> </body> </html>
Vertical rules such as the class .vr is used to create a vertical divider. Let's see an example for the same.
The example given below shows the usage of .vr class:
Example
You can edit and try running this code using the Edit & Run option.
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Helper - Stack</title> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script> </head> <body> <h4>Horizontal stack with vertical rule</h4><br> <div class="hstack gap-3 column-gap-3"> <div class="text-bg-secondary p-3">Item one</div> <div class="vr"></div> <div class="text-bg-warning p-3">Item two</div> <div class="vr"></div> <div class="text-bg-info p-3">Item three</div> </div> </body> </html>
An inline form can be created using the class .hstack.
Example
You can edit and try running this code using the Edit & Run option.
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap - Helper - Stack</title> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script> </head> <body> <h4>Create an inline form</h4><br> <div class="hstack gap-2"> <input class="form-control me-auto" type="text" placeholder="Add text here..." aria-label="Add text here..."> <div class="vr"></div> <button type="button" class="btn btn-success">Submit</button> <div class="vr"></div> <button type="button" class="btn btn-outline-danger">Clear</button> </div> </body> </html>