Responsive design requires a responsive grid and responsive breakpoints. Bootstrap provides both of these as part of its library. Bootstrap is a popular CSS framework that provides a pre-prepared library of CSS and JavaScript components, such as forms, buttons, and navigation, that can be used to build responsive and mobile-ready websites. It is designed to help developers quickly and easily create responsive, mobile-first websites, and it is widely used in front-end web development. Bootstrap is open-source and free to use.
BOOTSTRAP GRID SYSTEM
The bootstrap grid system helps us to create web page layouts through a series of rows and columns that house our content. For the grid, bootstrap uses a 12 column grid system that can be fluid or fixed, if more than 12, the element will be stacked. The bootstrap grid system always has a container, rows and columns. The container is the root element of your grid. It contains pads and aligns your content. Containers provide a means to center and horizontally pad your siteβs contents. Use .container for a responsive pixel width (Its width is determined based on the current responsive breakpoint) or .container-fluid for width: 100% across all viewport and device sizes.
Since bootstrap uses a 12 column grid system, if two columns is defined for a number of row(s), Bootstrap is smart and will set the two columns to span six columns spaces.
A breakpoint is the screen size threshold determined by specific layout requirements. At a given breakpoint range, the layout adjusts to suit the screen size and orientation. We use class in fixes for responsive breakpoints in the Bootstrap grid system. Here are the responsive breakpoints available in bootstrap and how we use them.
Extra small is for screens less than 576 pixels wide.
Small is for screens greater than or equal to 576 pixels wide. In bootstrap CSS rules, this is abbreviated as SM.
Medium is for screens greater than or equal to 768 pixels wide. In Bootstrap CSS rules, this is abbreviated as MD.
Large is for screens greater than or equal to 992 pixels wide. In Bootstrap CSS rules, this is abbreviated as LG.
Extra large is for screens greater than or equal to 1200 pixels wide. In bootstrap CSS rules this is abbreviated as XL.
Extra extra large is the screen is greater than or equal to 1400 pixels wide.
In bootstrap CSS rules, this is abbreviated as XXL.
Here is an example of using the Bootstrap grid system to create a responsive layout:
<div class="container">
<div class="row">
<div class="col-sm-4">Column 1</div>
<div class="col-sm-4">Column 2</div>
<div class="col-sm-4">Column 3</div>
</div>
</div>
In this example, the container class is used to create a container for the grid. The row class is used to create a row, and the col-sm-4 class is used to create three equal-width columns that will stack vertically on smaller screens (below 576px).
You can also use different grid classes to create different layouts depending on the screen size. For example, using col-md-6 and col-lg-3 classes, you can create two equal-width columns on medium screens (768px and up) and three equal-width columns on large screens (992px and up).
You can also use the offset classes to create empty space between columns.
<div class="container">
<div class="row">
<div class="col-sm-4">Column 1</div>
<div class="col-sm-4 offset-sm-4">Column 2</div>
</div>
</div>
This will create a 4 column layout with Column 1 taking 4 columns and Column 2 taking 4 columns with an offset of 4 columns.
You can also use the push and pull classes to change the order of columns for different screens.
<div class="container">
<div class="row">
<div class="col-sm-4 col-md-6 push-md-6">Column 1</div>
<div class="col-sm-4 col-md-6 pull-md-6">Column 2</div>
</div>
</div>
This will create a 4 columns layout for small screens and a 6 columns layout for medium screens with Column 1 being pushed to the right of Column 2 on medium screens.
The bootstrap system can be customized according to your design need.
Advantages of the Bootstrap Grid System
The Bootstrap grid system has several advantages that make it a popular choice for front-end web development:
Responsive design
Bootstrap's grid system is designed to be responsive and adapt to different screen sizes, making it easy to create mobile-ready websites.
Consistency
The grid system provides a consistent layout that can be used across different pages and components of a website, making it easy to maintain a consistent design.
Flexibility
The grid system can be easily customized to create different layouts depending on the screen size, allowing for flexibility in design.
Easy to use
The grid system is easy to learn and use, and it requires minimal CSS and JavaScript knowledge.
Large community
Bootstrap is an open-source project with a large community of developers, so there are plenty of resources and tutorials available to help you learn and use the grid system.
Cross-browser compatibility
Bootstrap grid system is designed to work with most modern browsers and is compatible with latest versions of chrome, firefox, safari, and internet explorer.
Speed up development
Using Bootstrap grid system can speed up development time, as it eliminates the need to write CSS and JavaScript code from scratch for common components.
Accessibility
Bootstrap follows web accessibility guidelines, making sure the grid system is accessible for all users.
Conclusion
The Bootstrap grid system is a powerful tool that can help developers create responsive, mobile-ready websites quickly and easily, with a consistent and flexible layout. It can help to speed up development time and make it easy to maintain a website's design.
Top comments (2)
Great Article!
All of us know that Bootstrap is great css library and has many ui components.
But, it's a little heavy, nowadays, Tailwind CSS is fashionable.
Thank you
Thanks @reacthunter0324 . Yes Tailwind is lighter