As of 2022, Bootstrap is at version five and is one of the most popular frontend frameworks. It has an extensive list of prebuilt components and an impressive collection of JavaScript plugins. In this article, you’ll learn how to use Bootstrap and make the most of its features.

Installing Bootstrap in Your Project

There are three ways to use Bootstrap in your project. You can download and host the CSS and JavaScript files, install it in your project using npm, or copy and paste the appropriate cdn links in your project.

With the cdn approach, you need to remember to place the Bootstrap link before any other CSS link in the head tag of your HTML file.

Some Bootstrap components have functional activities, such as button toggling and positioning that requires the importation of JavaScript and Popper script. So, if you intend to utilize any functional components, you’ll need to add the script tag to your HTML file as well.

The final thing you need to start using Bootstrap is the viewporttag.

The Viewport Meta Tag

Since Bootstrap is a mobile-first technology, the viewporttag will aid in responsive design. A simple way to use bootstrap in your project is to just copy Bootstrap’s starter template.

Creating a Website With Bootstrap

When you’re creating a new website, one of the first things you need to consider is the layout. After that, you can move to other components like buttons and typography.

Bootstrap has a collection of structural components that you can use to organize elements on a web page. These layout structures include:

Containers Grid Columns Gutters Breakpoints

Using a slightly altered version of the Bootstrap starter template, you can start outlining the structure of your webpage and add new components.

The index.html File

The Bootstrap Container Class

The Bootstrap container class pads, contains, and aligns the elements on your webpage. If you plan to use Bootstrap’s default grid, then you’ll need to also use Bootstrap’s container class. There are three types of container classes; container, container-fluid, and container-{breakpoint}. The container class is the default container; it is responsive and has a fix-width at each of Bootstraps six breakpoints.

Bootstrap’s six default breakpoints includes:

Extra Small: Less than 576px. Small: Greater than or equal to 576px. Medium: Greater than or equal to 768px. Large: Greater than or equal to 992px. X-Large: Larger than or equal to 1200px. XX-Large: Bigger than or equal to 1400px.

To use Bootstrap’s container in your project, you can simply add the desired container class to the external div on your webpage.

Using Bootstrap’s Container

Inserting the code above in the body of your existing HTML file will make your webpage responsive, and it will also create padding on each side of your webpage.

The Bootstrap Grid System

Bootstrap’s grid uses a twelve-column system that relies on the row and col grid classes, as well as the container class. Each row has twelve columns, and any element can span across one or more of these columns. The column class will indicate how many columns an element should occupy. For example, an element using the col-2 class will span across two columns, an element using the col-3 class will span across three columns, and so forth.

The Bootstrap grid system is based on the flexbox module. If only two columns occupy a row, they’ll divide the space equally among themselves. The gutter class is one of Bootstrap’s structural elements, and it controls the spacing between each column in the grid system. Each grid column has 12px of padding on either side.

Using Bootstrap’s Grid System

Inserting the code above into the container div will create a Bootstrap grid system of three rows and two columns. The first row at the top will hold the navbar, the third row at the bottom will hold the website footer, and the second row in the middle will hold the content of the webpage. The second row has two columns—the main article and an aside.

Creating a local CSS file and adding a border to each section of the grid will allow you to see it more clearly.

The style.css File

Linking to the CSS file above will create the following output in your browser:

An obvious difference in the image above is the size of the columns. Usually, two (or more) columns in a row occupy the same amount of space unless you explicitly state otherwise. The col-sm-4 class in the HTML code above ensures that the second column only spans over four of the twelve columns in the row. The sm in the col-sm-4 class represents the small breakpoint, so, the aside section will only occupy four columns from the small breakpoint and above.

Bootstrap Components

After you’ve decided on the layout of your webpage the next step is to add website building elements, which Bootstrap calls components. Bootstrap’s list of components include:

Navbar Buttons Button group List group Cards Collapse Dropdowns

The Bootstrap Navbar Class

Every Bootstrap navigation bar requires the navbar class. They also require the use of the