Bootstrap Responsive Layout
Learn how to create layouts that work properly on mobile, tablet and desktop devices.
What is Responsive Layout?
A responsive layout automatically adjusts the size and position of webpage content according to the screen size.
A responsive website should work properly on mobile phones, tablets, laptops and desktops.
Think of a webpage like water in a container. When the available space changes, the content adjusts itself to fit the available space. Responsive design works in a similar way.
Why Do We Need Responsive Design?
Users can access websites from many different devices. Therefore, a website should adapt to different screen sizes.
Mobile
Small screen with limited available space.
Tablet
Medium-sized screen with more available space.
Desktop
Large screen with more layout space.
Bootstrap Responsive Breakpoints
Bootstrap provides responsive breakpoints that allow us to change the layout according to screen size.
| Breakpoint | Class Prefix | Common Device |
|---|---|---|
| Extra Small | No prefix | Small mobile devices |
| Small |
sm
|
Larger mobile devices |
| Medium |
md
|
Tablets |
| Large |
lg
|
Laptops |
| Extra Large |
xl
|
Large desktops |
| Extra Extra Large |
xxl
|
Very large screens |
Responsive Columns
Bootstrap allows us to specify different column widths for different screen sizes.
<div class="col-12 col-md-6 col-lg-4">
Content
</div>
- col-12 → Full width on small screens
- col-md-6 → Half width on medium screens
- col-lg-4 → One-third width on large screens
Responsive Grid Example
The following example changes its layout depending on the screen size.
<div class="row">
<div class="col-12 col-md-6 col-lg-4">
Column 1
</div>
<div class="col-12 col-md-6 col-lg-4">
Column 2
</div>
<div class="col-12 col-md-6 col-lg-4">
Column 3
</div>
</div>
Output:
Column 1
Responsive content
Column 2
Responsive content
Column 3
Responsive content
Resize your browser window and observe how the columns change their position.
Responsive Navigation
Responsive design is also important for navigation. On smaller screens, navigation menus can change their appearance to provide a better user experience.
A desktop website may display all navigation links horizontally, while a mobile website may use a collapsed menu.
Responsive Images
Bootstrap provides the
.img-fluid class to make images
responsive.
<img src="image.jpg"
class="img-fluid"
alt="Responsive Image">
It allows an image to scale within its parent container so that it does not overflow the available width.
Responsive Content
Responsive design is not only about columns. Text, images, buttons, cards and other elements should also fit properly on different devices.
Desktop
More horizontal space is available, so multiple elements can appear side by side.
Mobile
Limited horizontal space means content often moves into separate rows.
Responsive Layout Diagram
The same layout can behave differently depending on the device.
Mobile
Tablet
Desktop
Real-Life Example – CIIT Training Institute
Suppose CIIT Training Institute wants to display its three courses:
- Java Full Stack
- .NET Full Stack
- Python Full Stack
On desktop, we can display all three courses side by side. On mobile, they can automatically move into separate rows.
<div class="row">
<div class="col-12 col-md-4">
Java Full Stack
</div>
<div class="col-12 col-md-4">
.NET Full Stack
</div>
<div class="col-12 col-md-4">
Python Full Stack
</div>
</div>
Output:
Java Full Stack
Java + Spring Boot + SQL
.NET Full Stack
C# + ASP.NET Core + SQL
Python Full Stack
Python + Django + SQL
Advantages of Responsive Layout
- Works across different screen sizes.
- Improves mobile user experience.
- Reduces the need for separate mobile websites.
- Makes content easier to read and navigate.
- Helps create modern and mobile-friendly websites.
Common Mistakes
- Using fixed widths that do not adapt to smaller screens.
- Forgetting responsive column classes.
- Using images without responsive sizing.
- Testing the website only on desktop.
Summary
In this lesson, we learned that responsive layouts automatically adjust webpage content according to different screen sizes.
We learned how Bootstrap breakpoints and responsive
column classes such as col-md-6 and
col-lg-4 help create flexible layouts.
We also learned how responsive layouts can be used for mobile, tablet and desktop devices to provide a better user experience.