Category: 1. bootstrap

https://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Bootstrap_logo.svg/2560px-Bootstrap_logo.svg.png

  • CSS Grid

    This chapter will discuss about Bootstrap CSS grid. Bootstrap’s default grid system, developed over a decade, has been widely used and proven effective. It was created without modern CSS features and techniques like the new CSS Grid we see in current browsers.

    How it works

    Bootstrap 5 introduces the ability to use a CSS Grid-based grid system with additional Bootstrap features for creating responsive layouts using different methods.

    • Recompile your Sass after disabling the default grid system by setting $enable-grid-classes to false and enabling CSS Grid with $enable-cssgrid set to true.
    • Replace instance of .row with .grid. The class .grid creates a grid-template by setting display: grid.
    • Instead of using .col-* classes, use .g-col-* classes because CSS Grid columns use the grid-column property instead of width.
    • Customize the column and gutter sizes of the parent .grid using CSS variables –bs-columns and –bs-gap.

    Key differences

    Let us see differences of CSS grid system when compared to the standard grid system as below:

    • The impact of Flex utilities on CSS Grid columns is different.
    • Instead of using gutters, use gap that act like margins and replace the horizontal padding in grid system.
    • Grid gaps are automatically applied horizontally and vertically in. unlike .rows, .grids do not have negative margins and cannot use margin utilities to adjust the gutters. Refer to the customizing section.
    • Modifier classes should be replaced with inline and custom styles (e.g., style=”–bs-columns: 3;” vs class=”row-cols-3″).
    • Nesting requires resetting column counts for each nested .grid instance.

    Three columns

    Use .g-col-4 to create three equal-width columns for all devices. Modify the layout based on viewport size using responsive classes based on viewport size.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - CSS Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-center">Three Columns</h2><div class="container p-3 m-0 border-0 bd-example m-0 bd-example-cssgrid"><div class="row"><div class="grid text-center"><div class="g-col-4 bg-info p-2">First Column</div><div class="g-col-4 bg-light p-2">Second Column</div><div class="g-col-4 bg-warning p-2">Third Column</div></div></div></div></body></html>

    Responsive

    To adjust your layout for different screen sizes, use responsive classes. For example, start with two columns on smaller screens and then expand to three columns on larger screens.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - CSS Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-center">Responsive</h2><div class="container p-3 m-0 border-0 bd-example m-0 bd-example-cssgrid"><div class="row"><div class="grid text-center"><div class="g-col-6 g-col-md-4 bg-info">First Column</div><div class="g-col-6 g-col-md-4 bg-light">Second Column</div><div class="g-col-6 g-col-md-4 bg-warning">Third Column</div></div></div></div></body></html>

    Compare the two-column layout across at all screen sizes.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - CSS Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-center">Two Column Layout</h2><div class="container p-3 m-0 border-0 bd-example m-0 bd-example-cssgrid"><div class="row"><div class="grid text-center"><div class="g-col-6 bg-info">First Column</div><div class="g-col-6 bg-warning">Second Column</div></div></div></div></body></html>

    Wrapping

    Grid items wrap to the next line when there’s no more horizontal space, with gaps applying to both horizontal and vertical spacing.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - CSS Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-center">Wrapping</h2><div class="container p-3 m-0 border-0 bd-example m-0 bd-example-cssgrid"><div class="row"><div class="grid text-center"><div class="g-col-6 bg-info">First Column</div><div class="g-col-6 bg-warning">Second Column</div><div class="g-col-6 bg-info">Third Column</div><div class="g-col-6 bg-warning">Fourth Column</div></div></div></div></body></html>

    Starts

    • Start classes are a shorthand version of CSS Grid’s grid-column-start and grid-column-end properties, used to create grid templates by specifying column starting and ending points.
    • They are used in combination with column classes for column sizing and alignment, starting from 1 as 0 is not a valid value for these properties.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - CSS Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-center">Starts</h2><div class="container p-3 m-0 border-0 bd-example m-0 bd-example-cssgrid"><div class="row"><div class="grid text-center"><div class="g-col-3 g-start-2 bg-info">First Column</div><div class="g-col-4 g-start-6 bg-warning">Second Column</div></div></div></div></div></body></html>

    Auto columns

    Without any classes on grid items, they will automatically be sized to one column within a .grid.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - CSS Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-center">Auto Column</h2><div class="container p-3 m-0 border-0 bd-example m-0 bd-example-cssgrid"><div class="row"><div class="grid text-center"><div class="bg-info">First</div><div class="bg-warning">Second</div><div class="bg-info">Third</div><div class="bg-warning">Four</div><div class="bg-info">Five</div><div class="bg-warning">Six</div><div class="bg-info">Seven</div><div class="bg-warning">Eight</div><div class="bg-info">Nine</div><div class="bg-warning">Ten</div></div></div></div></body></html>

    Grid column classes can be combined with this behaviour.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - CSS Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-center">Auto Column</h2><div class="container p-3 m-0 border-0 bd-example m-0 bd-example-cssgrid"><div class="row"><div class="grid text-center"><div class="g-col-6">First</div><div>Second</div><div>Third</div><div>Four</div><div>Five</div><div>Six</div><div>Seven</div></div></div></div></body></html>

    Nesting

    CSS Grid system enables simple nesting of .grids, and unlike the default grid, it inherits modifications made to rows, columns, and gaps. To implement nesting consider the following scenario:

    • The default number of columns is overridden with a local CSS variable: –bs-columns: 3.
    • The number of columns in the first auto-column is maintained, and each column takes up one-third of the total width.
    • set the nested .grid‘s column count to 12 (our default) in the second auto-column.
    • There are no nested items in the third auto-column.

    In comparison to the basic grid structure, this enables more complex and custom layouts in practice.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - CSS Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-center">Nesting</h2><div class="container p-3 m-0 border-0 bd-example m-0 bd-example-cssgrid"><div class="row"><div class="grid text-center p-3" style="--bs-columns: 3;"><div class="bg-secondary text-white">
    
            First Auto-column
            &lt;div class="grid p-3"&gt;&lt;div class="bg-warning"&gt;1&lt;/div&gt;&lt;div class="bg-info"&gt;2&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="bg-secondary text-white"&gt;
            Second Auto-column
            &lt;div class="grid  p-3" style="--bs-columns: 12;"&gt;&lt;div class="g-col-6 bg-warning"&gt;1&lt;/div&gt;&lt;div class="g-col-4 bg-info"&gt;2&lt;/div&gt;&lt;div class="g-col-2 bg-warning"&gt;3&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="bg-secondary text-white"&gt;Third Auto-column&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Customizing

    Customize column and row count, along with gap width, using local CSS variables.

    VariableFallback valueDescription
    --bs-rows1The number of rows in your grid template
    --bs-columns12The number of columns in your grid template
    --bs-gap1.5remThe size of the gap between columns (vertical and horizontal)

    CSS variables without default values use fallback values until a local instance is specified. For instance, var(--bs-rows, 1) is used for CSS Grid rows, overriding the fallback value of 1 when --bs-rows is defined.

    No grid classes

    The grid items within the .grid element will be sized automatically without using .g-col class.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - CSS Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-center">No Grid Classes</h2><div class="container p-3 m-0 border-0 bd-example m-0 bd-example-cssgrid"><div class="row"><div class="grid text-center" style="--bs-columns: 3;"><div class="bg-info">First Column</div><div class="bg-light">Second Column</div><div class="bg-warning">Third Column</div></div></div></div></body></html>

    Columns and gaps

    Let's modify the column count and spacing as demonstrated below:

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - CSS Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-center">Column and Gaps</h2><div class="container p-3 m-0 border-0 bd-example m-0 bd-example-cssgrid"><div class="row"><div class="grid text-center" style="--bs-columns: 4; --bs-gap: 5rem;"><div class="g-col-2 bg-info">First Column</div><div class="g-col-2 bg-warning">Second Column</div></div></div></div></body></html>

    Change the gap and the number of columns using --bs-columns: 10; and --bs-gap: 1rem;.s.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - CSS Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-center">Column and Gaps</h2><div class="container p-3 m-0 border-0 bd-example m-0 bd-example-cssgrid"><div class="row"><div class="grid text-center" style="--bs-columns: 10; --bs-gap: 1rem;"><div class="g-col-6 bg-info">First Column</div><div class="g-col-4 bg-warning">Second Column</div></div></div></div></body></html>

    Adding rows

    Follwing example demonstartes rearranging of columns and increasing the number of rows:

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - CSS Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-center">Adding Rows</h2><div class="container p-3 m-0 border-0 bd-example m-0 bd-example-cssgrid"><div class="row"><div class="grid text-center" style="--bs-rows: 3; --bs-columns: 3;"><div class="bg-info">First Column</div><div class="g-start-2 bg-light" style="grid-row: 2">Second Column</div><div class="g-start-3 bg-warning" style="grid-row: 3">Third Column</div></div></div></div></body></html>

    Gaps

    Modify only the row-gap to change the vertical gaps in the grids. Use gap on .grids and the row-gap and column-gap can be adjusted as required.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - CSS Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-center">Gaps</h2><div class="container p-3 m-0 border-0 bd-example m-0 bd-example-cssgrid"><div class="row"><div class="grid text-center" style="row-gap: 0;"><div class="g-col-6 bg-info">First Column</div><div class="g-col-6 bg-warning">Second Column</div><div class="g-col-6 bg-info">Third Column</div><div class="g-col-6 bg-warning">Fourth Column</div></div></div></div></body></html>

    You can specify a single or pair of values for vertical and horizontal gaps using inline style or the CSS variable --bs-gap.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - CSS Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-center">Gaps</h2><div class="container p-3 m-0 border-0 bd-example m-0 bd-example-cssgrid"><div class="row"><div class="grid text-center" style="--bs-gap: .25rem 1rem;"><div class="g-col-6 bg-info">First Column</div><div class="g-col-6 bg-warning">Second Column</div><div class="g-col-6 bg-info">Third Column</div><div class="g-col-6 bg-warning">Fourth Column</div></div></div></div></body></html>

    Sass

    One drawback of CSS Grid is that the number of classes generated in the compiled CSS is predetermined by the values of $grid-columns and $grid-gutter-width Sass variables.

    • Recompile your CSS after changing those default Sass variables.
    • To enhance the existing classes, use inline or custom styles.

    You can modify the column count, gap size, and size using inline styles and predefined CSS Grid column classes (e.g., .g-col-4).https://www.tutorialspoint.com/bootstrap/examples/cssgrid_saas.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - CSS Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-center">Saas</h2><div class="container p-3 m-0 border-0 bd-example m-0 bd-example-cssgrid"><div class="row"><div class="grid text-center" style="--bs-columns: 18; --bs-gap: .5rem;"><div class="bg-info" style="grid-column: span 14;">First Column</div><div class="g-col-4 bg-warning">Second Column</div></div></div></div></body></html>

  • Utilities

    This chapter will discuss about Bootstrap utilities. Several utility classes are used for various changes, such as showing, hiding, aligning, and spacing content, these are used to create mobile-friendly and responsive websites.

    Changing display

    Bootstrap display properties can be used to configure the display. Mix it with a grid system, content, or component to display or hide them on particular viewports.

    Flexbox options

    • Bootstrap uses flexbox, but not every element should be to display:flex to avoid overriding and changing browser behaviors. Most of the components are built with flexbox enabled.
    • In order to add display: flex to an element, use .d-flex or responsive variants (like .d-sm-flex). Use this class or value to access flexbox utilities for sizing, alignment, spacing, and more.

    Margin and padding

    • Use margin and padding utilities to modify the element’s spacing and sizing. It has a six-level spacing scale for spacing utilities based on 1rem default $spacer variable.
    • You can select certain viewports (e.g., .me-sm-3 for margin-right: 1rem in LTR starting at the sm breakpoint), or values for the viewports (e.g., .me-3 for margin-right: 1rem in LTR).

    Toggle visibility

    Visibility utilities allow you to toggle an element’s visibility. Invisible elements continue to affectpage layout but are hidden from visitors.

  • Gutters

    This chapter will discuss about Bootstrap gutters. Gutter provides padding between your columns. Gutters are used to responsively space and align content.

    How it works

    • Gutters are generated by horizontal padding, and are spaces between the column content. Align the content using padding-right and padding-left on each column.
    • Gutters begin at a width of 1.5 rem (24px), hence allows us to align grid to the scale of padding and margin spacers.
    • Adjust gutters with breakpoint-specific classes to change horizontal, vertical, and all other gutters.

    Horizontal gutters

    .gx-* classes manage the widths of horizontal gutters, and if larger gutters are used, the parent .container or .container-fluid may require adjustment to prevent overflow. This can be done using a padding utility, such as .px-4 as demonstarted in below example.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Gutters</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container px-4 text-center mt-2"><div class="row gx-5"><div class="col"><div class="p-2 bg-info">First Column</div></div><div class="col"><div class="p-2 bg-warning">Second Column</div></div></div></div></body></html>

    Using overflow functionality

    Adding a wrapper with the .overflow-hidden class to .row is another option.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Gutters</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container overflow-hidden text-center"><div class="row gx-5 mt-2"><div class="col"><div class="p-2 bg-info">First Column</div></div><div class="col"><div class="p-2 bg-warning">Second Column</div></div></div></div></body></html>

    Vertical gutters

    • The vertical gutter is used for responsive spacing, padding between columns, and aligning content with the grid.
    • Use .gy-* classes to control vertical gutter widths in a row when column wrapping occurs.
    • They can cause some overflow below the .row at the end of a page, like the horizontal gutters. To fix this, add a wrapper with .overflow-hidden class around a .row.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Gutters</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container overflow-hidden text-center mt-2"><div class="row gy-5"><div class="col-6"><div class="p-2 bg-info">First Column</div></div><div class="col-6"><div class="p-2 bg-warning">Second Column</div></div><div class="col-6"><div class="p-2 bg-info">Third Column</div></div><div class="col-6"><div class="p-2 bg-warning">Fourth Column</div></div></div></div></body></html>

    Horizontal and vertical gutters

    To control the horizontal and vertical grid gutters, use .g-* classes. Use smaller gutter width. So, we won’t need of .overflow-hidden wrapper class.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Gutters</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><div class="row g-2 mt-2"><div class="col-6"><div class="p-2 bg-info">First Column</div></div><div class="col-6"><div class="p-2 bg-warning">Second Column</div></div><div class="col-6 "><div class="p-2 bg-info">Third Column</div></div><div class="col-6"><div class="p-2 bg-warning">Fourth Column</div></div></div></div></body></html>

    Row columns gutters

    Gutter classes can be added to row columns with responsive design. Responsive row columns and responsive gutter classes are used in the example below:

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Gutters</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><div class="row row-cols-2 row-cols-lg-3 g-2 g-lg-3 mt-2"><div class="col"><div class="p-3 bg-info">First Row column</div></div><div class="col"><div class="p-3 bg-warning">Second Row column</div></div><div class="col"><div class="p-3 bg-info">Third Row column</div></div><div class="col"><div class="p-3 bg-warning">Fourth Row column</div></div><div class="col"><div class="p-3 bg-info">Fifth Row column</div></div><div class="col"><div class="p-3 bg-warning">Sixth Row column</div></div></div></div></body></html>

    No gutters

    • Remove gutters between columns with .g-0 in grid classes. This removes negative margins from .row and horizontal padding from immediate children columns.
    • Remove the parent .container or .container-fluid to create an edge-to-edge design and add .mx-0 to the .row to prevent overflow.
    • No gutters eliminates margin and padding for both row and columns.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Gutters</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="row g-0 text-center mt-2"><div class="col-sm-4 col-md-6 p-2 bg-info">First Column</div><div class="col-4 col-md-3 p-2 bg-warning">Second Column</div></div></body></html>

  • Columns

    This chapter will discuss about Bootstrap columns. The flexbox grid system allows you to modify columns with various alignment, ordering, and offsetting options. Using column classes, you can control the widths of non-grid items.

    Before learning how to change and customise your grid columns, be sure to read the Grid page first.

    How it works

    • On the flexbox architecture of the grid, columns are built. Flexbox allows changing of specific columns and groups of columns at the row level.
    • When creating grid layouts, all content is placed in columns. Bootstrap grid’s hierarchy goes from the container to the row to the column to your content. There may be unforeseen repercussions when you combine the content and column.
    • For generating responsive layouts, Bootstrap provides predefined classes. Each grid tier has six breakpoints and a dozen of columns. Bootstrap provides many classes to create your desired layouts.

    Alignment

    Align columns vertically and horizontally using flexbox alignment utilities.

    Vertical alignment

    Use vertical-alignment utilities to changes the alignment of elements vertically.

    • Use the align-items-start class to align content vertically at starting position.
    • Use the align-items-center class to align content vertically at center.
    • Use the align-items-end class to align content vertically at the end.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Columns</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><h5>Align the content at start</h5><div class="row align-items-start bg-info mt-4" style="min-height: 80px;"><div class="col bg-warning">
    Tutorialspoint
    </div></div><h5 class="mt-2">Align the content at center</h5><div class="row align-items-center bg-info mt-4" style="min-height: 80px;"><div class="col bg-warning">
    Tutorialspoint
    </div></div><h5 class="mt-2">Align the content at end</h5><div class="row align-items-end bg-info mt-4" style="min-height: 80px;"><div class="col bg-warning">
    s
    </div></div></div></body></html>

    Adjust the alignment of each column separately using .align-self-* classes.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Columns</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center mt-4"><div class="row  bg-warning" style="min-height: 80px;"><div class="col align-self-start bg-info">
    
            First Column
          &lt;/div&gt;&lt;div class="col align-self-center bg-info"&gt;
            Second Column
          &lt;/div&gt;&lt;div class="col align-self-end bg-info"&gt;
            Third Column
          &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Horizontal alignment

    Horizontal alignment can be alter using justify-content-* classes to align the columns horizontally.

    • Use justify-content-start to align columns from start.
    • Use justify-content-center to align columns at the center.
    • Use justify-content-end to align columns at the end.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Columns</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center mt-4"><h5>Align the columns at start</h5><div class="row justify-content-start bg-info mt-4" style="min-height: 40px;"><div class="col-4 bg-warning">
    
          First Column
        &lt;/div&gt;&lt;div class="col-4 bg-light"&gt;
          Second Column
        &lt;/div&gt;&lt;/div&gt;&lt;h5 class="mt-4"&gt;Align the columns at center&lt;/h5&gt;&lt;div class="row justify-content-center bg-info mt-4" style="min-height: 40px;"&gt;&lt;div class="col-4  bg-warning"&gt;
         First Column
        &lt;/div&gt;&lt;div class="col-4 bg-light"&gt;
          Second Column
        &lt;/div&gt;&lt;/div&gt;&lt;h5 class="mt-4"&gt;Align the columns at end&lt;/h5&gt;&lt;div class="row justify-content-end bg-info mt-4" style="min-height: 40px;"&gt;&lt;div class="col-4  bg-warning"&gt;
          First Column
        &lt;/div&gt;&lt;div class="col-4 bg-light"&gt;
          Second column
        &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>
    • Use justify-content-around to equalise the spacing around the two columns.
    • Use justify-content-between to add space between the two columns.
    • Use justify-content-evenly class to add an equal space between the right and left columns of two desired columns.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Columns</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center mt-4"><h5 class="mt-4">Add space between the two columns using justify-content-around</h5><div class="row justify-content-around bg-info mt-4" style="min-height: 40px;"><div class="col-4 bg-warning">
    
          First Column
        &lt;/div&gt;&lt;div class="col-4 bg-light"&gt;
          Second Column
        &lt;/div&gt;&lt;/div&gt;&lt;h5 class="mt-4"&gt;Add space between the two columns using justify-content-between.&lt;/h5&gt;&lt;div class="row justify-content-between bg-info mt-4" style="min-height: 40px;"&gt;&lt;div class="col-4 bg-warning"&gt;
          First Column
        &lt;/div&gt;&lt;div class="col-4 bg-light"&gt;
          Second Column
        &lt;/div&gt;&lt;/div&gt;&lt;h5 class="mt-4"&gt;Add equal space between columns using justify-content-evenly.&lt;/h5&gt;&lt;div class="row justify-content-evenly bg-info mt-4" style="min-height: 40px;"&gt;&lt;div class="col-4 bg-warning"&gt;
          First Column
        &lt;/div&gt;&lt;div class="col-4 bg-light"&gt;
          Second Column
        &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Column wrapping

    If there are more than 12 columns in a row, they will automatically wrap to the next line as a single unit.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Columns</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container"><div class="row mt-2"><div class="col-2 bg-warning">If there are more than 12 columns in a row, they will automatically wrap to the next line as a single unit.</div><div class="col-6 bg-info">If there are more than 12 columns in a row, they will automatically wrap to the next line as a single unit.</div><div class="col-9 bg-primary">If there are more than 12 columns in a row, they will automatically wrap to the next line as a single unit.</div></div></div></body></html>

    Column breaks

    To break the column to a new line in flexbox, add a div element with a 100% width, after the column where you want to break the row. This normally occurs with multiple .rows, although not all implementation methods are suitable for this.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Columns</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><div class="row mt-2"><div class="col-6 col-sm-3 bg-info">First Column</div><div class="col-6 col-sm-3 bg-warning">Second Column</div><div class="w-100"></div><div class="col-6 col-sm-3 bg-primary">Third Column</div><div class="col-6 col-sm-3 bg-secondary">Fourth Column</div></div></div></body></html>

    You can also use responsive display utilities to apply this break at particular breakpoints.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Columns</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center mt-2"><div class="row"><div class="col-6 col-sm-4  bg-info">First Column</div><div class="col-6 col-sm-4  bg-warning">Second Column</div><div class="w-100 d-none d-md-block"></div><div class="col-6 col-sm-4 bg-primary">Third Column</div><div class="col-6 col-sm-4 bg-light">Fourth Column</div></div></div></body></html>

    Reordering

    Bootstrap's column order classes adjust the grid system's order based on various screen sizes.

    Order classes

    The visual order of your content is controlled using .order- classes. Because these classes are responsive, you can sort them by breakpoint (e.g., .order-2 order-md-3). Support for values 1 to 5 across all grid tiers is included. The default number of .order-* classes can be modified via Sass variable.https://www.tutorialspoint.com/bootstrap/examples/columns_order_classes.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Columns</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><div class="row"><div class="col bg-info">
    
            no order applied.
          &lt;/div&gt;&lt;div class="col order-5 bg-warning"&gt;
            with an order of 5.
          &lt;/div&gt;&lt;div class="col order-1 bg-primary"&gt;
            with an order of 1.
          &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Additionally, the responsive classes .order-first and .order-last can be used to reorder elements by using order: -1 and order: 6, respectively. You can combine these classes with numbered .order-* classes as required.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Columns</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center mt-2"><div class="row"><div class="col order-last bg-info">
    
            First column as ordered last
          &lt;/div&gt;&lt;div class="col order-first bg-primary"&gt;
            Second column as ordered first
          &lt;/div&gt;&lt;div class="col bg-warning"&gt;
            Third column (unordered)
          &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Offsetting columns

    The grid columns offset can be achieved in two ways:

    • .offset- grid
    • margin utilities

    Grid classes are sized to match columns, While margins are more suitable for quick layouts with variable offset width.

    Offset classes

    Use .offset-md-* classes to shift the columns from their original position to the right side. These classes add *columns to the left margin of a column. The class .offset-md-4 shifts .col-md-4 to the right by four columns.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Columns</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><div class="row mt-2"><div class="col-md-2 bg-info p-2">First Column</div></div><div class="row mt-2"><div class="col-md-2 offset-md-3 bg-warning p-2">Second Column</div></div><div class="row mt-2"><div class="col-md-2 offset-md-2 bg-info p-2">Third Column</div></div><div class="row mt-2"><div class="col-md-2 offset-md-4 bg-warning p-2">Fourth Column</div></div></div></body></html>

    Column clearing at responsive breakpoints

    You need to reset the offsets at responsive breakpoints to clear columns. View the grid example for a demonstration

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Columns</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><div class="row mt-2"><div class="col-sm-5 col-md-6 bg-warning">First Row First Column</div><div class="col-sm-5 offset-sm-2 col-md-6 offset-md-0 bg-info">First Row Second Column</div></div><div class="row mt-2"><div class="col-sm-6 col-md-5 col-lg-6 bg-warning">Second Row First Column</div><div class="col-sm-6 col-md-5 offset-md-2 col-lg-6 offset-lg-0  bg-info">Second Row Second Column</div></div></div></body></html>

    Margin utilities

    In version 4, flexbox allows you to utilize margin utilities such as .me-auto to separate sibling columns from each other

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Columns</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><div class="row mt-2"><div class="col-md-4 bg-info"> First Row First Column</div><div class="col-md-4 ms-auto bg-warning">First Row Second Column</div></div><div class="row mt-2"><div class="col-md-3 ms-md-auto bg-info">Second Row First Column</div><div class="col-md-3 ms-md-auto bg-warning">Second Row Second Column</div></div><div class="row mt-2"><div class="col-auto me-auto bg-info">Third Row First Column</div><div class="col-auto bg-warning">Third Row Second Column</div></div></div></body></html>

    Standalone column classes

    To provide a specific width for an element, use .col-* classes outside a .row. The paddings are omitted when column classes are used as non-direct children of a row.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Columns</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="col-3 p-2 mb-2 bg-info">
    
     First Column
    &lt;/div&gt;&lt;div class="col-sm-6 p-2 bg-warning"&gt;
      Second Column
    &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    To create responsive floated images, combine the classes with utilities. If the text is shorter, wrap it in a .clearfix wrapper to clear the float.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Columns</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="clearfix"><img src="\bootstrap\images\tut.png" class="col-sm-2 float-sm-end mb-2 ms-sm-2" alt="..."><p> Create responsive floated images, combine the classes with utilities. If the text is shorter, wrap it in a .clearfix wrapper to clear the float. Create responsive floated images, combine the classes with utilities. If the text is shorter, wrap it in a .clearfix wrapper to clear the float.</p><p> Create responsive floated images, combine the classes with utilities. If the text is shorter, wrap it in a .clearfix wrapper to clear the float. Create responsive floated images, combine the classes with utilities. If the text is shorter, wrap it in a .clearfix wrapper to clear the float. create responsive floated images, combine the classes with utilities.</p><p> Create responsive floated images, combine the classes with utilities. If the text is shorter, wrap it in a .clearfix wrapper to clear the float. Create responsive floated images, combine the classes with utilities. If the text is shorter, wrap it in a .clearfix wrapper to clear the float.</p><p> Create responsive floated images, combine the classes with utilities. If the text is shorter, wrap it in a .clearfix wrapper to clear the float. Create responsive floated images, combine the classes with utilities. If the text is shorter, wrap it in a .clearfix wrapper to clear the float.</p></div></body></html>

  • Grid system

    This chapter will discuss about Bootstrap grid system. In Bootstrap, Grid system allows up to 12 columns across the page and is built with flexbox

    Basic example

    • Bootstrap’s grid system is a responsive layout tool that uses containers, rows, and columns to align content.
    • Use a .container class for a responsive fixed width container.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><div class="row mt-2"><div class="col p-2 bg-primary">
    
            First Column
          &lt;/div&gt;&lt;div class="col p-2 bg-warning"&gt;
            Second Column
          &lt;/div&gt;&lt;div class="col p-2 bg-info"&gt;
            Third Column
          &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    How it works

    • Bootstrap grid supports six responsive breakpoints. Breakpoints affect all sizes above it (such as sm, md, lg, xl, xxl), allowing you to control container and column sizing and behavior at each breakpoint.
    • Containers center and horizontally pad your content. Use .container for responsive pixel width or .container-fluid for full width across all viewport and device sizes. For various breakpoints the responsive container classes are used.
    • Rows are wrappers for columns. Each column contains horizontal padding. This padding is then applied to rows with negative margins. In this manner, all the content in the columns, is left-aligned.
    • Rows supports modification classes for uniform column sizing column sizing and gutter classes for changing the spacing of your text.
    • Columns are incredibly flexible. You can create various elements combination with any number of columns using one of the 12 template columns available per row.
    • Column widths are set in percentages for fluid and relative sizing to parent element.
    • Gutters are responsive and customizable. They are available for all the viewports and are of same size as margin and padding. You can modify gutters by using the .gx-* (for horizontal gutters), .gy-* (for vertical gutters), .g-* (for all gutters) and .g-0 to remove gutters.
    • To create more semantic markup, you can use predefined grid's source Sass mixins.

    There are six classes in Bootstrap Grid System:

    • Extra small (.col-xs)
    • Small (.col-sm-)
    • Medium (.col-md-)
    • Large (.col-lg-)
    • Extra large (.col-xl-)
    • Extra extra large (.col-xxl-)

    How the grid varies over these breakpoints is shown in the below table:

    Extra small
    <576px
    Small
    576px
    Medium
    768px
    Large
    992px
    X-Large
    1200px
    XX-Large
    1400px
    Container max-widthNone (auto)540px720px960px1140px1320px
    Class prefix.col-.col-sm-.col-md-.col-lg-.col-xl-.col-xxl-
    # of columns12-----
    Gutter width1.5rem (.75rem margin on both sides.)-----
    Custom guttersYes-----
    NestableYes-----
    Column orderingYes-----

    Auto-layout columns

    For easy column sizing without an explicit numbered class, use breakpoint-specific column classes like .col-sm-6.

    Equal-width

    • Use equal-width grid system to create the grid in equal sizes.
    • Two grid layouts work on any device size from xs to xxl. For each breakpoint, you can add many unit-less classes, and each column/row will have the same width.
    https://www.tutorialspoint.com/bootstrap/examples/grid_equal_width.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><h5>Equal columns</h5><div class="row mt-2"><div class="col  p-2 bg-primary">
    
            First Column
          &lt;/div&gt;&lt;div class="col  p-2 bg-info"&gt;
            Second Column
          &lt;/div&gt;&lt;/div&gt;&lt;h5&gt;Equal rows&lt;/h5&gt;&lt;div class="col mt-2"&gt;&lt;div class="row  p-2 bg-warning text-white"&gt;
            First Row
          &lt;/div&gt;&lt;div class="row  p-2 bg-secondary text-white"&gt;
            Second Row
          &lt;/div&gt;&lt;div class="row  p-2 bg-success text-white"&gt;
            Third Row
          &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Setting one column width

    • You can choose one column width and other columns automatically resize around it.
    • Use grid classes, mixins, or inline widths. You can resize the other columns no matter the width of the center column.

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><div class="row mt-2"><div class="col-6  p-2 bg-primary text-white">
    
            First Column (col-6)
          &lt;/div&gt;&lt;div class="col-3  p-2 bg-secondary text-white"&gt;
           Second Column (col-3)
          &lt;/div&gt;&lt;div class="col p-2 bg-warning text-white"&gt;
            Third Column (col)
          &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Variable width content

    Use col-{breakpoint}-auto classes to size columns according to the content's natural width.https://www.tutorialspoint.com/bootstrap/examples/grid_variable_width_content.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><div class="row justify-content-md-center mt-2"><div class="col col-lg-2  p-2 bg-primary ">
    
           First Column
          &lt;/div&gt;&lt;div class="col-md-auto  p-2 bg-info "&gt;
            Second column with variable width content.
          &lt;/div&gt;&lt;div class="col col-lg-2  p-2 bg-warning"&gt;
           Third Column
          &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Responsive classes

    In Bootstrap, grid has six tiers of predefined classes which is used to create complex responsive layouts. You can customize the columns/row to small, medium, large, or extra-large devices.

    All breakpoints

    Use the .col and .col-* classes for grids that are consistent across all sizes of devices. If you require a column of a specific size then use a numbered class.https://www.tutorialspoint.com/bootstrap/examples/grid_all_breakpoints.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><h5>Columns</h5><div class="row mt-2"><div class="col p-2 bg-primary">First Column</div><div class="col p-2 bg-warning">Second Column</div><div class="col p-2 bg-light">Third Column</div></div><h5>Rows</h5><div class="col mt-2"><div class="row-9 p-2 bg-info">First Row</div><div class="row-3 p-2 bg-success">Second Row</div></div></div></body></html>

    Stacked to horizontal

    Use .col-sm-* classes to build a simple grid system that is stacked on extra small and small devices and becomes horizontal on larger devices.

    Note: Resize the browser to check the effect on various devices.https://www.tutorialspoint.com/bootstrap/examples/grid_stacked_to_horizontal.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><h5>Columns</h5><div class="row mt-2"><div class="col-sm-6 p-2 bg-primary text-white">First Column</div><div class="col-sm-3 p-2 bg-success text-white">Second Column</div><div class="col-sm-2 p-2 bg-dark text-white">Third Column</div></div><h5>Rows</h5><div class="col mt-2"><div class="row-sm p-2 bg-info">First row</div><div class="row-sm p-2 bg-warning">Second row</div></div></div></body></html>

    Mix and match

    Use a combination of various classes for each tier to easily stack the columns in some grid tiers according to your needs.https://www.tutorialspoint.com/bootstrap/examples/grid_mix_and_match.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><div class="row mt-2"><div class="col-sm-4 p-2 bg-primary text-white">First column of col-sm-4</div><div class="col-3  p-2 bg-secondary text-white">Second column of col-3</div></div><div class="row mt-2"><div class="col-4 col-md-2 p-2 bg-warning text-white">First column of col-4 col-md-2</div><div class="col-4 col-md-2 p-2 bg-secondary text-white">Second column of col-4 col-md-2</div><div class="col-4 col-md-2 p-2 bg-info text-white">Third column of col-4 col-md-2</div></div><div class="row mt-2"><div class="col-sm-3 p-2 bg-dark text-white">First column of col-sm-3</div><div class="col-md-6 p-2 bg-success text-white">Second column of col-md-6</div></div></div></body></html>

    Row columns

    • Bootstrap grid provides row column classes to create simple grid layouts.
    • Individual rows are included in .row* class.
    • Individual columns are included in .col* class.
    • Use .row-cols-* class to set the number of columns in a single row.
    • Use .row-cols-auto to adjust the column's size based on its content.

    Create two different columns using .row-cols-2 class.https://www.tutorialspoint.com/bootstrap/examples/grid_row_columns_2.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><div class="row row-cols-2"><div class="col bg-info p-2">First Row First Column</div><div class="col bg-primary p-2">First Row Second Column</div><div class="col bg-warning p-2">Second Row First Column</div></div></div></body></html>

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container  text-center mt-2"><div class="row row-cols-3 mt-2"><div class="col bg-info p-2">First Row First Column</div><div class="col bg-light p-2">First Row Second Column</div><div class="col bg-primary p-2">First Row Third Column</div><div class="col bg-secondary p-2">Second Row First Column</div><div class="col bg-success p-2">Second Row Second Column</div><div class="col bg-warning p-2">Second Row Third Column</div></div></div></body></html>

    Create grids of rows and columns using row-cols-auto class.https://www.tutorialspoint.com/bootstrap/examples/grid_row_columns_auto.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><div class="row row-cols-auto"><div class="col bg-primary p-2">First Row First Column</div><div class="col bg-secondary p-2">First Row Second Column</div><div class="col bg-warning p-2">First Row Third Column</div><div class="col bg-info p-2">First Row Fourth Column</div><div class="col bg-success p-2">First Row Fifth Column</div><div class="col bg-light p-2">First Row sixth Column</div><div class="col bg-danger p-2">Second Row First Column</div></div></div></body></html>

    Create four different columns using row-cols-4 class.https://www.tutorialspoint.com/bootstrap/examples/grid_row_columns_4.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><div class="row row-cols-4"><div class="col bg-primary p-2">First Row First Column</div><div class="col bg-secondary p-2">First Row Second Column</div><div class="col bg-warning p-2">First Row Third Column</div><div class="col bg-info p-2">First Row Fourth Column</div><div class="col bg-light p-2">Second Row First Column</div><div class="col bg-danger p-2">Second Row Second Column</div></div></div></body></html>

    Using row-cols-1row-cols-sm-3 and row-cols-md-6 classes.https://www.tutorialspoint.com/bootstrap/examples/grid_row_columns.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><div class="row row-cols-1 row-cols-sm-3 row-cols-md-6 mt-2"><div class="col bg-primary p-2">First Row First Column</div><div class="col bg-light p-2">First Row Second Column</div><div class="col bg-warning p-2">First Row Third Column</div><div class="col bg-info p-2">First Row Fourth Column</div><div class="col bg-danger p-2">First Row Fifth Column</div></div></div></body></html>

    Using the row-cols() Sass mixin.https://www.tutorialspoint.com/bootstrap/examples/grid_custom_row_columns.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script><style>
    
      .custom_grid{
        @media row-cols(2);
        @media media-breakpoint-up(lg) {
          @media row-cols(6);
        }
      }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="container custom_grid text-center"&gt;&lt;div class="row"&gt;&lt;div class="col bg-primary p-2"&gt;First Row First Column&lt;/div&gt;&lt;div class="col bg-light p-2"&gt;First Row Second Column&lt;/div&gt;&lt;div class="col bg-warning p-2"&gt;First Row Third Column&lt;/div&gt;&lt;div class="col bg-info p-2"&gt;First Row Fourth Column&lt;/div&gt;&lt;div class="col bg-danger p-2"&gt;First Row Fifth Column&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Nesting

    A nesting grid system adds rows and columns of the grid in single cell of an existing grid. The nested rows should consist of a group of columns whose total does not exceed 12 (it is not necessary to utilize all 12 columns).https://www.tutorialspoint.com/bootstrap/examples/grid_nesting.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Grid</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container text-center"><div class="row mt-2"><div class="col-sm bg-primary p-2">
    
          First Column
        &lt;/div&gt;&lt;div class="col-sm bg-info p-2"&gt;&lt;div class="container"&gt;&lt;div class="row"&gt;&lt;div class="col col-sm bg-light"&gt;
                Second Column
              &lt;/div&gt;&lt;div class="col col-sm bg-light"&gt;
                Second Column 
              &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="col-sm bg-primary p-2"&gt;
          Third Column
        &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

  • Containers

    This chapter will discuss about Bootstrap containers. Containers are used to pad content within them.

    Containers are required for default grid system (Grid system uses a series of containers, rows and columns to align content). Containers are used to contain, pad, and center the content within them. Containers can also be nested, though most layouts don’t require a nested container.

    There are three different container classes in Bootstrap:

    • .container (sets responsive max-widths).
    • .container-{breakpoint} (width: 100% until specified breakpoint).
    • .container-fluid (width: 100% at all breakpoints).

    How the max-width of the container (when compared to original .container and .container-fluid) varies across each breakpoint is shown in the below table:

    Examples of the same can be seen in chapter Grid Demo

    Extra small
    <576px
    Small
    576px
    Medium
    768px
    Large
    992px
    X-Large
    1200px
    XX-Large
    1400px
    .container100%540px720px960px1140px1320px
    .container-sm100%540px720px960px1140px1320px
    .container-md100%100%720px960px1140px1320px
    .container-lg100%100%100%960px1140px1320px
    .container-xl100%100%100%100%1140px1320px
    .container-xxl100%100%100%100%100%1320px
    .container-fluid100%100%100%100%100%100%

    Default Containers

    Use .container class which creates a responsive fixed-width container.https://www.tutorialspoint.com/bootstrap/examples/default_containers.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Container</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container mt-4"><div class="bg-light"><h2 class="text-success text-center">Tutorialspoints</h2><h5 class="text-primary text-center">Bootstrap - Container</h5><p>Container is used to set the margin of the content. It contains row elements and the row elements are containers of columns. This is known as the grid system.
    
            Container is used to set the margin of the content. It contains row elements and the row elements are containers of columns.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Responsive Containers

    • Use responsive containers to declare a class that is 100% wide until the specific breakpoint is reached, after that use max-widths for all subsequent breakpoints.
    • Use the .container-sm|md|lg|xl classes to decide whether the container should be responsive or not.
    https://www.tutorialspoint.com/bootstrap/examples/responsive_containers.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Container</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container-sm text-success  border mt-2">Tutorialspoints breakpoint-sm</div><div class="container-md text-success  border mt-2">Tutorialspoints breakpoint-md</div><div class="container-lg text-success  border mt-2">Tutorialspoints breakpoint-lg</div><div class="container-xl text-success  border mt-2">Tutorialspoints breakpoint-xl</div><div class="container-xxl text-success border mt-2">Tutorialspoints breakpoint-xxl</div></body></html>

    Fluid Containers

    Use the .container-fluid class to create a full width container. They span the entire width of the screen.https://www.tutorialspoint.com/bootstrap/examples/fluid_containers.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Container</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container-fluid"><h2 class="text-success text-center">Tutorialspoints</h2><h5 class="text-primary text-center">Bootstrap - Container</h5><p>Container is used to set the margin of the content. It contains row elements and the row elements are containers
    
          of columns. This is known as the grid system.
          Container is used to set the margin of the content. It contains row elements and the row elements are containers
          of columns.&lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Print Page

  • Breakpoint

    This chapter will discuss about Bootstrap breakpoints. Bootstrap breakpoints help us determine how a responsive layout is viewed on various devices and viewport sizes.

    Basic concepts

    • Breakpoints in Bootstrap are used to create responsive designs. You may adjust them at a particular viewport or device size.
    • CSS media queries allow us to customize styling based on browsers and operating sytem parameters. Media queries in Boostrap mostly use min-width to control the breakpoints.
    • Bootstrap’s goal is mobile-first, responsive designs. Bootstrap creates mobile-friendly layouts with minimal styles, adding layers for larger devices. It improves rendering time and gives users a better viewing experience.

    Types of breakpoints

    Bootstrap provides six default breakpoints referred to as grid tiers. These can be customized if we use Boostrap’s source Sass files.

    BreakpointClass InfixDimensions
    Extra smallNone<576px
    Smallsm576px
    Mediummd768px
    Largelg992px
    Extra largexl1200px
    Extra extra largexxl1400px

    These breakpoints cover common device sizes and viewport dimensions. These bootstrap breakpoints can be changed using Sass, as shown below:

      $grid-breakpoints: (
    
    xs: 0,
    sm: 576px,
    md: 768px,
    lg: 992px,
    xl: 1200px,
    xxl: 1400px
    );

    Media queries

    Bootstrap is developed to be mobile first, hence media queries are used to create wise breakpoints for its layouts and interfaces. Minimum viewport widths are used to control breakpoints which scale up elements as viewport changes.

    Min-width

    min-width media feature state specifies the minimum screen width of a specific device. Setting min-width in the breakpoints means CSS is only applied to devices whose width is greater than min-width of the device.

      @include media-breakpoint-up(sm) { ... }
    

    The above syntax means that CSS would be applied for devices larger than the min-width i.e Small devices (landscape phones, 576px and up).

    Let us see usage of min-width media feature with an example. Here you will see that we apply hide a div on devices width less than 768px.https://www.tutorialspoint.com/bootstrap/examples/breakpoints_min_width.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Breakpoint</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script><style>
      .custom-class {
    
    display: none;
    } @media (min-width: 768px) {
    .custom-class {
      display: block;
    }
    @media (min-width: 768px) {
    .custom-class {
      display: block;
    }
    } </style></head><body><h5>This block is visible on all devices</h5><div class="container-fluid mt-2 "><div class="row"><div class="col-md-6 bg-warning p-3">
          md-6 warning
        &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;br&gt;&lt;h5&gt;This block is not visible for sm breakpoint but visible for other breakpoints&lt;/h5&gt;&lt;div class="container-fluid mt-2 custom-class"&gt;&lt;div class="row"&gt;&lt;div class="col-md-6 bg-warning p-3"&gt;
          md-6 warning
        &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Max-width Breakpoint

    max-width media feature states the maximum screen width of a specific device. Setting max-width in the breakpoints means CSS is only applied to devices whose width is smaller than mentioned in the media query.

      @include media-breakpoint-down(xl) { ... }
    

    The above syntax means that CSS would be applied to large devices (desktops, less than 1200px).

    Let us see usage of max-width media feature with an example:https://www.tutorialspoint.com/bootstrap/examples/breakpoints_max_width.php

    Example

    You can edit and try running this code using Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Breakpoint</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script><style>
    .custom-class {
      display: none;
    }
    @media (max-width: 767.98px) {
      .custom-class {
    
    display: block;
    } } </style></head><body><h5>This block visible on all devices</h5><div class="container-fluid mt-2"><div class="row"><div class="col-xxl-3 bg-primary text-black p-3">
        xxl-3 primary
      &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h5&gt;This block not visible all devices larger than sm&lt;/h5&gt;&lt;div class="container-fluid mt-2 custom-class"&gt;&lt;div class="row"&gt;&lt;div class="col-lg-6  bg-warning text-black p-3"&gt;
        lg-6 warning
      &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Single Breakpoint

    Single breakpoint means targeting a specific screen sizes using minimum and maximum breakpoint widths in media queries.

      @include media-breakpoint-only(md) { ... }
    

    The above syntax means that CSS would be applied for devices with screen sizes between @media (min-width: 768px) and (max-width: 991.98px) { ... } (i.e medium sized devices such as tablets, desktops)

    Between Breakpoints

    Between breakpoints target multiple breakpoints.

      @include media-breakpoint-between(md, xl) { ... }
    

    Above syntax results in @media (min-width: 892px) and (max-width: 1278px) { ... }, which means styles are applied starting from medium devices and up to extra large devices.

  • Color modes

    This chapter discusses about the color modes supported by Bootstrap. The different color modes available are:

    • light mode (default)
    • dark mode (new)
    • create your own custom template

    Dark mode

    With v5.3.0, a new color mode is introduced, i.e. the dark mode. Toggling of color modes on <html> element or on any specific components and elements is allowed, using the data-bs-theme attribute.

    Let us see an example:https://www.tutorialspoint.com/bootstrap/examples/color_mode_dark.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html><head><title>Bootstrap - Color modes</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h1 class="text-center">Color mode - dark</h1><center><div class="dropdown" data-bs-theme="light"><button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButtonLight" data-bs-toggle="dropdown" aria-expanded="false">
    
    			  Light mode dropdown
    			&lt;/button&gt;&lt;ul class="dropdown-menu" aria-labelledby="dropdownMenuButtonLight"&gt;&lt;li&gt;&lt;a class="dropdown-item active" href="#"&gt;Item 1&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Item 2&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Item 3&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Item 4&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;hr class="dropdown-divider"&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Total items&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div class="dropdown" data-bs-theme="dark"&gt;&lt;button class="btn btn-danger dropdown-toggle" type="button" id="dropdownMenuButtonDark" data-bs-toggle="dropdown" aria-expanded="false"&gt;
    			  Dark mode dropdown
    			&lt;/button&gt;&lt;ul class="dropdown-menu" aria-labelledby="dropdownMenuButtonDark"&gt;&lt;li&gt;&lt;a class="dropdown-item active" href="#"&gt;Item 1&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Item 2&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Item 3&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Item 4&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;hr class="dropdown-divider"&gt;&lt;/li&gt;&lt;li&gt;&lt;a class="dropdown-item" href="#"&gt;Total items&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/center&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Overview

    • Color mode styles are controlled by the data-bs-theme attribute.
    • The data-bs-theme atrribute can be applied on <html> element or any other component or element.
    • If applied on <html> element, it will apply to everything under the scope of <html> element.
    • If applied to a specific component or element, it will be scoped to that particular component or element.
    • You will have to add new overrides for the shared global CSS variables, for each color mode you want to support. Use the following mixin to write the color mode specific style:

    Usage

    Enable dark mode

    You can enable the dark mode across your project by adding data-bs-theme="dark" attribute to the <html> element. This setting will be applied to all the components and elements, except for those that have a different value for data-bs-theme.

    This can be achieved by the following code:

    <!DOCTYPE html><html lang="en" data-bs-theme="dark"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Bootstrap color mode</title><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous"></head><body><h1>Hello, world!</h1><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script></body></html>

    Custom color modes

    Apart from light and dark mode, you can also create your own custom color mode. You can create your own data-bs-theme selector with a custom value, and modidy the Sass and CSS variables.

    Toggle between color modes

    You can switch or toggle between the dark and light mode using CSS and JavaScript. Here is an example shown below:https://www.tutorialspoint.com/bootstrap/examples/color_mode_toggle.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html><head><title>Bootstrap - Color modes</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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script><style>
    
        body {
        padding: 25px;
        background-color: white;
        color: black;
        font-size: 25px;
        }
        .dark-mode {
        background-color: black;
        color: white;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Toggle Dark/Light Mode&lt;/h2&gt;&lt;p&gt;Click the button to toggle between dark and light mode for this page.&lt;/p&gt;&lt;button onclick="myFunction()"&gt;Toggle dark mode&lt;/button&gt;&lt;script&gt;
        function myFunction() {
        var element = document.body;
        element.classList.toggle("dark-mode");
        }
        &lt;/script&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Print Page

  • CSS variables

    This chapter discusses about all the CSS variables provided by Bootstrap, that help in fast and customized design and development of applications.

    The compiled CSS of Bootstrap consists of a plethora of CSS custom properties (variables) that allow for instant customization without the need to recompile Sass, wherein commonly used values such as theme colors, breakpoints, and primary font stacks are easily accessible during browser inspection, code sandbox operation, or general prototyping.

    All the custom variables provided by Bootstrap are prefixed with bs-, so that there is no conflict with any other third-party CSS.

    Root variables

    Root variables are the variables that can be accessed from anywhere, Bootstraps CSS is loaded. These variables are located in the _root.scss file and also included in the compiled dist files

    Default variables

    The CSS variables that are accessible everywhere, irrespective of the color mode, are the default variables.

        :root,
    
    [data-bs-theme=light] {
    --bs-blue: #0d6efd;
    --bs-indigo: #6610f2;
    --bs-purple: #6f42c1;
    --bs-pink: #d63384;
    --bs-red: #dc3545;
    --bs-orange: #fd7e14;
    --bs-yellow: #ffc107;
    --bs-green: #198754;
    --bs-teal: #20c997;
    --bs-cyan: #0dcaf0;
    --bs-black: #000;
    --bs-white: #fff;
    --bs-gray: #6c757d;
    --bs-gray-dark: #343a40;
    --bs-gray-100: #f8f9fa;
    --bs-gray-200: #e9ecef;
    --bs-gray-300: #dee2e6;
    --bs-gray-400: #ced4da;
    --bs-gray-500: #adb5bd;
    --bs-gray-600: #6c757d;
    --bs-gray-700: #495057;
    --bs-gray-800: #343a40;
    --bs-gray-900: #212529;
    --bs-primary: #0d6efd;
    --bs-secondary: #6c757d;
    --bs-success: #198754;
    --bs-info: #0dcaf0;
    --bs-warning: #ffc107;
    --bs-danger: #dc3545;
    --bs-light: #f8f9fa;
    --bs-dark: #212529;
    --bs-primary-rgb: 13, 110, 253;
    --bs-secondary-rgb: 108, 117, 125;
    --bs-success-rgb: 25, 135, 84;
    --bs-info-rgb: 13, 202, 240;
    --bs-warning-rgb: 255, 193, 7;
    --bs-danger-rgb: 220, 53, 69;
    --bs-light-rgb: 248, 249, 250;
    --bs-dark-rgb: 33, 37, 41;
    --bs-primary-text-emphasis: #052c65;
    --bs-secondary-text-emphasis: #2b2f32;
    --bs-success-text-emphasis: #0a3622;
    --bs-info-text-emphasis: #055160;
    --bs-warning-text-emphasis: #664d03;
    --bs-danger-text-emphasis: #58151c;
    --bs-light-text-emphasis: #495057;
    --bs-dark-text-emphasis: #495057;
    --bs-primary-bg-subtle: #cfe2ff;
    --bs-secondary-bg-subtle: #e2e3e5;
    --bs-success-bg-subtle: #d1e7dd;
    --bs-info-bg-subtle: #cff4fc;
    --bs-warning-bg-subtle: #fff3cd;
    --bs-danger-bg-subtle: #f8d7da;
    --bs-light-bg-subtle: #fcfcfd;
    --bs-dark-bg-subtle: #ced4da;
    --bs-primary-border-subtle: #9ec5fe;
    --bs-secondary-border-subtle: #c4c8cb;
    --bs-success-border-subtle: #a3cfbb;
    --bs-info-border-subtle: #9eeaf9;
    --bs-warning-border-subtle: #ffe69c;
    --bs-danger-border-subtle: #f1aeb5;
    --bs-light-border-subtle: #e9ecef;
    --bs-dark-border-subtle: #adb5bd;
    --bs-white-rgb: 255, 255, 255;
    --bs-black-rgb: 0, 0, 0;
    --bs-font-sans-serif: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
    --bs-font-monospace: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    --bs-gradient: linear-gradient(180deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0));
    --bs-body-font-family: var(--bs-font-sans-serif);
    --bs-body-font-size: 1rem;
    --bs-body-font-weight: 400;
    --bs-body-line-height: 1.5;
    --bs-body-color: #212529;
    --bs-body-color-rgb: 33, 37, 41;
    --bs-body-bg: #fff;
    --bs-body-bg-rgb: 255, 255, 255;
    --bs-emphasis-color: #000;
    --bs-emphasis-color-rgb: 0, 0, 0;
    --bs-secondary-color: rgba(33, 37, 41, 0.75);
    --bs-secondary-color-rgb: 33, 37, 41;
    --bs-secondary-bg: #e9ecef;
    --bs-secondary-bg-rgb: 233, 236, 239;
    --bs-tertiary-color: rgba(33, 37, 41, 0.5);
    --bs-tertiary-color-rgb: 33, 37, 41;
    --bs-tertiary-bg: #f8f9fa;
    --bs-tertiary-bg-rgb: 248, 249, 250;
    --bs-heading-color: inherit;
    --bs-link-color: #0d6efd;
    --bs-link-color-rgb: 13, 110, 253;
    --bs-link-decoration: underline;
    --bs-link-hover-color: #0a58ca;
    --bs-link-hover-color-rgb: 10, 88, 202;
    --bs-code-color: #d63384;
    --bs-highlight-bg: #fff3cd;
    --bs-border-width: 1px;
    --bs-border-style: solid;
    --bs-border-color: #dee2e6;
    --bs-border-color-translucent: rgba(0, 0, 0, 0.175);
    --bs-border-radius: 0.375rem;
    --bs-border-radius-sm: 0.25rem;
    --bs-border-radius-lg: 0.5rem;
    --bs-border-radius-xl: 1rem;
    --bs-border-radius-xxl: 2rem;
    --bs-border-radius-2xl: var(--bs-border-radius-xxl);
    --bs-border-radius-pill: 50rem;
    --bs-box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    --bs-box-shadow-sm: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    --bs-box-shadow-lg: 0 1rem 3rem rgba(0, 0, 0, 0.175);
    --bs-box-shadow-inset: inset 0 1px 2px rgba(0, 0, 0, 0.075);
    --bs-focus-ring-width: 0.25rem;
    --bs-focus-ring-opacity: 0.25;
    --bs-focus-ring-color: rgba(13, 110, 253, 0.25);
    --bs-form-valid-color: #198754;
    --bs-form-valid-border-color: #198754;
    --bs-form-invalid-color: #dc3545;
    --bs-form-invalid-border-color: #dc3545;
    }

    Dark mode variables

    Following variables are limited to the built-in dark mode of Bootstrap:

        [data-bs-theme=dark] {
    
        color-scheme: dark;
        --bs-body-color: #adb5bd;
        --bs-body-color-rgb: 173, 181, 189;
        --bs-body-bg: #212529;
        --bs-body-bg-rgb: 33, 37, 41;
        --bs-emphasis-color: #fff;
        --bs-emphasis-color-rgb: 255, 255, 255;
        --bs-secondary-color: rgba(173, 181, 189, 0.75);
        --bs-secondary-color-rgb: 173, 181, 189;
        --bs-secondary-bg: #343a40;
        --bs-secondary-bg-rgb: 52, 58, 64;
        --bs-tertiary-color: rgba(173, 181, 189, 0.5);
        --bs-tertiary-color-rgb: 173, 181, 189;
        --bs-tertiary-bg: #2b3035;
        --bs-tertiary-bg-rgb: 43, 48, 53;
        --bs-primary-text-emphasis: #6ea8fe;
        --bs-secondary-text-emphasis: #a7acb1;
        --bs-success-text-emphasis: #75b798;
        --bs-info-text-emphasis: #6edff6;
        --bs-warning-text-emphasis: #ffda6a;
        --bs-danger-text-emphasis: #ea868f;
        --bs-light-text-emphasis: #f8f9fa;
        --bs-dark-text-emphasis: #dee2e6;
        --bs-primary-bg-subtle: #031633;
        --bs-secondary-bg-subtle: #161719;
        --bs-success-bg-subtle: #051b11;
        --bs-info-bg-subtle: #032830;
        --bs-warning-bg-subtle: #332701;
        --bs-danger-bg-subtle: #2c0b0e;
        --bs-light-bg-subtle: #343a40;
        --bs-dark-bg-subtle: #1a1d20;
        --bs-primary-border-subtle: #084298;
        --bs-secondary-border-subtle: #41464b;
        --bs-success-border-subtle: #0f5132;
        --bs-info-border-subtle: #087990;
        --bs-warning-border-subtle: #997404;
        --bs-danger-border-subtle: #842029;
        --bs-light-border-subtle: #495057;
        --bs-dark-border-subtle: #343a40;
        --bs-heading-color: inherit;
        --bs-link-color: #6ea8fe;
        --bs-link-hover-color: #8bb9fe;
        --bs-link-color-rgb: 110, 168, 254;
        --bs-link-hover-color-rgb: 139, 185, 254;
        --bs-code-color: #e685b5;
        --bs-border-color: #495057;
        --bs-border-color-translucent: rgba(255, 255, 255, 0.15);
        --bs-form-valid-color: #75b798;
        --bs-form-valid-border-color: #75b798;
        --bs-form-invalid-color: #ea868f;
        --bs-form-invalid-border-color: #ea868f;
      }

    Component variables

    The usage of custom properties as local variables for various components is becoming more prevalent in Bootstrap 5. This results in a reduction of compiled CSS, prevents styles from being inherited in nested tables, and permits some customization and expansion of Bootstrap components following Sass compilation.

    CSS variables are distinctively used in navbarsgrids and many more. When CSS variables are assigned at base component level, it becomes easier to customize and modify it later.

    Prefix

    A prefix is used with most of the variables, in order to prevent any collisions with your own codebase. Every CSS variable requires , apart from the prefix.

    You can customize the prefix, using the $prefix Sass variable. It is set to bs-, by default.

    Examples

    CSS variables provide comparable adaptability to Sass variables; however, there is no requirement for compilation before transmitting to the browser. As an illustration, we utilize CSS variables to reset our page’s font and link styles:

        body {
    
        font: 1rem/1.5 var(--bs-font-monospace);
    }
    a {
        color: var(--bs-red);
    }

    Focus variables

    By employing a blend of Sass and CSS variables, Bootstrap enables the provision of personalized :focus styles that can be selectively appended to singular components and elements. Nevertheless, the overriding of all :focus styles across the board is not currently implemented.

    Default values can be set in the Sass, that can be customized before compiling.

    scss/_variables.scss
    
    $focus-ring-width:      .25rem;
    $focus-ring-opacity:    .25;
    $focus-ring-color:      rgba($primary, $focus-ring-opacity);
    $focus-ring-blur:       0;
    $focus-ring-box-shadow: 0 0 $focus-ring-blur $focus-ring-width $focus-ring-color;

    The variables are subsequently assigned to CSS variables at the :root level, which can be customized in real-time and feature options for x and y offsets, with their default fallback value being 0.

    scss/_root.scss
    
    --#{$prefix}focus-ring-width: #{$focus-ring-width};
    --#{$prefix}focus-ring-opacity: #{$focus-ring-opacity};
    --#{$prefix}focus-ring-color: #{$focus-ring-color};

    Grid breakpoints

    Grid breakpoints, such as md, lg, xl, xxl are included as CSS variables (except for xs). CSS variables can not be used in media queries.

  • RTL

    This chapter discusses about RTL (right to left) support provided by Bootstrap. The RTL feature supports for right-to-left text across your layout, components and utilities.

    Requirements

    To enable RTL in pages powered by Bootstrap, you must fulfill the two requirements. They are as follows:

    • On <html> element, set dir-“rtl”.
    • On <html> element, add an appropriate lang attribute, such as lang=”ar”.

    You need to include the RTL version of CSS. For example, here is a stylesheet with RTL enabled:

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.rtl.min.css" integrity="sha384-PJsj/BTMqILvmcej7ulplguok8ag4xFTPryRq8xevL7eBYSmpXKcbNVuy+P0RMgq" crossorigin="anonymous">

    Starter template

    Following is a sample of starter template meeting the requirements for enabling RTL:https://www.tutorialspoint.com/bootstrap/examples/rtl_template.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="ar" dir="rtl"><head><!-- Required meta tags --><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><!-- Bootstrap CSS --><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.rtl.min.css" integrity="sha384-PJsj/BTMqILvmcej7ulplguok8ag4xFTPryRq8xevL7eBYSmpXKcbNVuy+P0RMgq" crossorigin="anonymous"><!--"Welcome to Tutorialspoint" written in arabic--><title>   Tutorialspoint</title></head><body><!--"Welcome to Tutorialspoint" written in arabic--><h1>   Tutorialspoint</h1><!-- Optional JavaScript; choose one of the two! --><!-- Option 1: Bootstrap Bundle with Popper --><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script><!-- Option 2: Separate Popper and Bootstrap JS --><!--
       <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script>
       <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-fbbOQedDUMZZ5KreZpsbe1LCZPVmfTnH7ois6mU1QK+m14rQ1l2bGBq41eYeM/fS" crossorigin="anonymous"></script>
       --></body></html>

    Customize from source

    Use the variables, maps and mixins, for customization purposes. The approach works exactly like LTR, for RTL.

    Custom RTL values

    There are certain directives for RTL CSS values, via which you can set the output of a variable different for RTL. For an example, in order to decrease the font weight throughout your codebase, you can use the syntax as /*rtl: {value}*/.

    $font-weight-bold: 600 #{/* rtl:500 */} !default;
    

    This would output to the following for default CSS and RTL CSS:

    /* bootstrap.css */
    dt {
       font-weight: 600 /* rtl:500 */; 
    }
    
    /* bootstrap.rtl.css */
    dt {
       font-weight: 500;
    }
    

    Alternative font stack

    You should be aware that not all the non-Latin alphabets are supported. Hence in order to switch from Pan-European to Arabic family of fonts, you may need to use /*rtl:insert: {value}*/ in your font stack to alter the names of font families.

    To switch from Helvetica Neue font for LTR to Helvetica Neue Arabic for RTL, your Sass code could look like this:

    $font-family-sans-serif:
    Helvetica Neue #{"/* rtl:insert:Arabic */"},
    
    // Cross-platform generic font family (default user interface font)
    system-ui,
    
    // Safari for macOS and iOS (San Francisco)
    -apple-system,
    
    // Chrome < 56 for macOS (San Francisco)
    BlinkMacSystemFont,
    
    // Windows
    "Segoe UI",
    
    // Android
    Roboto,
    
    // Basic web fallback
    Arial,
    
    // Linux
    "Noto Sans",
    
    // Sans serif fallback
    sans-serif,
    
    // Emoji fonts
    "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji" !default;
    

    RTL and LTR at the same time

    Do you want to use LTR and RTL together? Its very much possible, you just need to wrap your @imports with a class, and set a custom rename rule for RTLCSS:

    /* rtl:begin:options: {
       "autoRename": true,
       "stringMap":[ {
    
      "name": "ltr-rtl",
      "priority": 100,
      "search": ["ltr"],
      "replace": ["rtl"],
      "options": {
         "scope": "*",
         "ignoreCase": false
      }
    } ] } */ .ltr { @import "../node_modules/bootstrap/scss/bootstrap"; } /*rtl:end:options*/

    Each selector in your CSS files will have the prefix .ltr (or .rtl for RTL files) after executing Sass and RTLCSS. Now that both files can be used on the same page, you can use either the .ltr or .rtl component wrapper extension to specify which direction to utilise.

    While working with LTR and RTL implementation together, you need to consider the following points:

    1. Make sure to add dir and lang attributes accordingly, when switching .ltr and .rtl
    2. Try to do some customization and load one of the two files (ltr & rtl) asynchronously, as loading of both the files can cause performance issues.
    3. Nesting styles will prevent the form-validation-state() mixin and it may not work as intended.

    The Breadcrumb case

    The only case that requires its own brand-new variable is the breadcrumb separator, namely $breadcrumb-divider-flipped, defaulting to $breadcrumb-divider.