By Syed Fazle Rahman

Responsive Web Design Tips from Bootstrap’s CSS

By Syed Fazle Rahman

With the release of version 3, Bootstrap has gone mobile first, building on its already responsive base.

What kinds of things does Bootstrap include in its CSS to help with this? Let’s examine a few things and gain some insight that might help us in our own custom projects.

Defining Proper Media Queries

Bootstrap has clearly defined breakpoints for different kinds of devices, specified by using CSS media queries. The following are the breakpoint categories used for the different types of devices:

  1. Extra Small Devices (e.g. cell phones) are the default, creating the “mobile first” concept in Bootstrap. This covers devices smaller than 768px wide.
  2. “Small Devices” (e.g. tablets) are targeted with @media (min-width: 768px) and (max-width: 991px) { ... }.
  3. Medium Sized Devices (e.g. Desktops) have a screen size smaller than 1200px and greater than 991px, using @media (min-width: 992px) and (max-width: 1199px) { ... }.
  4. Larger Devices (e.g. wide-screen monitors) are greater than 1200px, targeted using @media (min-width: 1200px) { ... }.

Note: Mobile devices that we use today come with 2 different screen orientations: Portrait and Landscape. So the above is mostly true for landscape view only. For example, if you are using a Samsung Galaxy Note III phone, the landscape view falls in the “Small Devices” category whereas the portrait view would fall under “Extra Small Devices”.

This kind of categorization is common in responsive frameworks and it’s something you can certainly benefit from understanding better.

The Grid System Demystified

If you are familiar with Bootstrap’s grid system, you might know that there is a specific HTML structure required to properly set up its grids. Let’s demystify it.

Let’s first have a look at Bootstrap’s HTML for a two-column setup:

<div class="container">
  <div class="row">

    <div class="col-xs-6">
      <p>Column 1</p>

    <div class="col-xs-6">
      <p>Column 2</p>


As shown above, Bootstrap’s grid system starts with a container element. Containers define how much space a grid system should use. They can be of two types: .container has different widths for different types of devices whereas .container-fluid expands to fit the width of the device.

With the help of media queries, Bootstrap gives different widths to the .container depending on the size of the device:

  • Extra small devices (<768px): width: auto (or no width)
  • Small Devices (≥768px): width: 750px
  • Medium Devices (≥992px): width: 970px
  • Larger Devices (≥1200px): width: 1170px

Here are some more CSS declarations that are applied to the .container class.

.container {
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;

Bootstrap container

As seen in the above image, the .container prevents the content inside the element from touching the browser edge using 15px of padding on each side. It also ensures the container is centered using auto for left and right margins.

Rows are another important element in Bootstrap’s Grid System. Before creating columns, you can define a row using the class .row. Here’s a snippet from Bootstrap’s CSS for the .row class:

.row {
  margin-right: -15px;
  margin-left: -15px;

As shown above, our row has negative left and right margins of -15px to allow the row to touch the edge of its container element. This acts as a wrapper to hold columns, which can add up to 12 in number.

Bootstrap row

You may have noticed that the margins on the row seem to be counteracting the 15px of padding applied to the container. If we analyze the columns, we can see why this is needed.

Here’s a snippet from Bootstrap’s CSS for the .col-xs-6 class.

.col-xs-6 {
  padding-right: 15px;
  padding-left: 15px;

As shown, left and right padding of 15px is applied to the columns, resulting in something like the image below:

Bootstrap columns with padding

Because of the negative margins on the row, the columns are touching the edges of the row and the edges of the container. But the padding causes the contents that go inside these columns to remain 15px away from the edges of the container.

Containers are used for multiple purposes, not just for the grid system, so the 15px padding helps to avoid the content touching the edges of the browser (when using .container-fluid). Rows have the negative margins so that they are not pushed by the padding of the container.

If you are considering designing your own framework, you might want to consider using this padding/margin technique.

Defining Proper Column Widths

Bootstrap uses percentages (%) as the unit to define the widths of columns, helping with responsiveness. As stated above, there are 4 different categories of device-based breakpoints. Each category has its own set classes for columns of different sizes.

  1. Extra small devices use .col-xs-*.
  2. Small devices use .col-sm-*.
  3. Medium devices use .col-md-*.
  4. Large devices use .col-lg-*.

The asterisk character (*) gets replaced by a number. For example, .col-xs-6 creates a column 6 times the size of a .col-xs-1 column; .col-sm-4 creates a column four times the size of .col-sm-1, and so on.

By default, all the columns have no width set, which defaults to width: auto. However, within the media queries, Bootstrap gives width values to each column class.

Here’s a snippet from Bootstrap’s CSS for the column classes with asterisks replacing the sizes for brevity (xs, sm, md, etc):

.col-*-12 {
  width: 100%;

.col-*-11 {
  width: 91.66666667%;

.col-*-10 {
  width: 83.33333333%;

.col-*-9 {
  width: 75%;

.col-*-8 {
  width: 66.66666667%;

.col-*-7 {
  width: 58.33333333%;

.col-*-6 {
  width: 50%;

.col-*-5 {
  width: 41.66666667%;

.col-*-4 {
  width: 33.33333333%;

.col-*-3 {
  width: 25%;

.col-*-2 {
  width: 16.66666667%;

.col-*-1 {
  width: 8.33333333%;

Let’s analyze the above code. A class .col-lg-6 will have a width of 50% in large devices but when viewed in medium, small, and extra-small devices, the default width: auto is used. This ensures that the columns are converted to a stacked layout (rather than side by side) in smaller devices.

Responsive Tables

Tables, used for displaying tabular data, are also responsive in Bootstrap.

To use Bootstrap’s table styles, we use the class .table, which has the following CSS:

.table {
  width: 100%;
  max-width: 100%;
  margin-bottom: 20px;

Bootstrap forces tables to fit the width of the parent element by applying a width of 100%. But this has an issue. A multi-column table will get squeezed on smaller devices and may not be readable.

Bootstrap has another class to remedy this: .table-responsive. Here’s the CSS:

.table-responsive {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  -ms-overflow-style: -ms-autohiding-scrollbar;
  border: 1px solid #ddd;

These styles cause the table to become scrollable on the horizontal axis on smaller devices.

Responsive Images

Working with larger images may be a problem for smaller devices. Bootstrap uses a class of .img-responsive to make any image responsive:

.img-responsive {
  display: block;
  max-width: 100%;
  height: auto;

This combination of max-width: 100% and height: auto will ensure the images scale down proportionally in smaller devices, while staying within the parent element’s constraints on larger devices.


These RWD tips are just a few things I’ve picked up from Bootstrap 3. If you’ve noticed anything else in their source code not mentioned here, feel free to share it in the comments.

  • jokeyrhyme

    Device-specific media queries are an abomination and a cop-out. Media queries should be designed specifically for the content you have.

    Frameworks focus on devices because they don’t magically know anything about your content, but designers on any given project should know better.

    • Russell

      Why? Not trolling, trying to learn.

  • Vivek Kumar Bansal

    Isn’t this article quite late, going by the intro? Anyways Nice article

    • LouisLazaris

      The article isn’t meant to be a news piece on the release of Bootstrap 3, but an examination of the code. The intro just points out that the mobile first thing has started with version 3.

  • LouisLazaris

    He/she is correct, but that’s just one of the flaws of a framework.

    To put it very basically, the reason it’s generally bad practice, is because the whole idea of “breakpoints” is based on “where your content/layout breaks”. That is, at what “point” does your content “break”? When you determine that, then you can determine where to define those “points” to alter the layout. In other words, your layout doesn’t necessarily break at “768px” as Bootstrap assumes; but instead, it might break at 790px or 755px. It’s the content that will determine that, which the framework doesn’t know anything about.

    But for a generic framework like Bootstrap, there’s nothing wrong with it. That’s the only way to do it, and if you follow the grid system pretty closely, then it shouldn’t really cause too many problems. But again, you’d have to consider that on a case-by-case basis, and a framework can’t really do that out of the box.

    • Knight Yoshi

      However, that’s one of the great things about the Bootstrap framework. It’s so easy to change anything and everything. To adjust it for one’s own needs.

  • Sander

    @media (min-width: 992px) and (max-width: 1999px) { … }

    Shouldn’t that be 1199px instead of 1999px?

    • LouisLazaris

      Yes, that’s fixed now, nice catch. Thanks.

  • Nice overview. Bootstrap is a very useful framework, especially for myself when building templates for a content management system.

    It has several other tricks up its sleeve such as pull-left and pull-right to align content.

    However, I’m not overly convinced of the enforced 15px padding – I think I’d prefer to have more control in my own local css.

    And I do think there is a demand for a media query of max-width 420px for mobiles in portrait mode.


    • Those are good points. I think it’s important for all of us to realize, it’s called Bootstrap for a reason. That is it’s not called “Use It As-Is Or Die.” :)

  • re: “Let’s analyze the above code. A class .col-lg-6 will have a width of 50% in large devices but when viewed in medium, small, and extra-small devices, the default width: auto is used. This ensures that the columns are converted to a stacked layout (rather than side by side) in smaller devices.”

    Yes, solid overview. Thanks for sharing.

    Perhaps in your next article I think the idea implied in this bit (quoted) might be worth exploring further. I’m not so sure most people (new to a RWD framework like BS3) grasp the idea of using the col width classes for different screen sizes. For example something like: class=”col-xs-6 col-lg-3″

  • seanhunt

    This is an OK intro, but only an intro. Personally I think Bootstrap is wonderful. Even if you are making a website that will only be viewed on a desktop monitor, it is a great way to layout your application and if you need a large data intensive Intranet screen, you can just adjust the left margin to not auto center. By the way, notice that that extra-small really is not small enough for an iPhone 5 or before, Well, add your own step and it will work dandy. I’ve tried JQuery mobile which has its place and experimented with responsive javascript (Bootstrap makes it unnecessary), but I like Bootstrap best.

  • Here’s a learning I committed to memory: Don’t use .row unless you’re going to use .col* too. Otherwise your left/right margins will be 0 instead of 15px. Why? Because .row effectively eliminates the padding introduced by .container and then .col* adds it back. So without .col*, you’re left with no left/right margins. But this begs the question: when would one *not* use .col* classes? When one doesn’t need an adaptive layout, i.e. when the layout should remain the same at any width.

    • Sander Teunissen

      Why would you want to use row when not using col? You could just omit the row class (or the entire div)

  • Reloj

    Thank you for this site Syed. I was wondering if you know how to make links to tabs from a button in bootstrap 3. Basically from a button that says: read more >>> be able to link to a specific tab (an open it) in the same page.

    I would appreciate any help with this.


    • Sander Teunissen

      This sounds like something you would do using JavaScript. Just like activating the tabs as explained in you could bind a click handler to the “read more” link that opens the tab. such as:

      $(‘#myLink’).click(function (e) {

  • I’m confused. I use a grid where the width is 1170/1140 for large, 970 for medium desktop, 750 for tablet. When I get to iPhone portrait is 320 with gutters. Is that right?

  • Sam

    If it is all responsive – it will automatically fit – then why do I have to choose a column type – sm/md, etc. Can someone clarify this – why/what column size do I choose

  • Jeremiah Emmerson

    I noticed a big problem for images, especially for Samsung Galaxy S4, S5. The images themselves are really high dpi and you would think the resolution would be crisp. I will try this. Very good article. Good insight.

  • Paul Peterson

    Excellent overview, Syed. Thanks for the effort you put into it!

  • Jaydot

    Thank you for posting this! Most of it is too complicated for me, but I’ve just spent hours and hours trying to get table-responsive to work in Joomla – until I found out that Joomla still uses Bootstrap 2.3.2 which doesn’t have the table-responsive class.
    Fixed now, and working beautifully!

  • rahul singh

    Waow..just to know a lot in this article of yours.Thanks..:)

  • Bootstrap is very Simple As Per Media Query. Bootstrap is small code need and media query is very large code want.

  • nb koteswara rao

    what are the standerd screen resolutions for media quary in css? can anyone help me…?

Get the latest in Front-end, once a week, for free.