Bootstrap 5 Grid: Medium Devices

Medium device grid example

XSmall Small Medium Large Extra Large XXL
Class prefix .col- .col-sm- .col-md- .col-lg- .col-xl- .col-xxl-
Screen width <576px >=576px >=768px >=992px >=1200px >=1400px

In the previous chapter, we demonstrated a grid example containing classes for small devices. We used two divs (columns) and gave them a 25% / 75% split:

<div class="col-sm-3">....</div>
<div class="col-sm-9">....</div>

But a 50% / 50% split design may be better on medium devices.

Medium devices are defined as screen widthFrom 768 pixels to 991 pixels.

For medium devices, we will use .col-md-* Classes:

<div class="col-sm-3 col-md-6">....</div>
<div class="col-sm-9 col-md-6">....</div>

On small devices, please use classes containing -sm- class. On medium devices, please use classes containing -md- class.

The following example will result in a 25% / 75% split on small devices and a 50% / 50% split on medium (as well as large, extra large, and extra extra large) devices. On extra small devices, it will automatically stack (100%):

Example

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-3 col-md-6">
      <p>The World Wide Fund for Nature (WWF), founded on April 29, 1961, has a giant panda as its logo...</p>
    </div>
    <div class="col-sm-9 col-md-6">
      <p>In 1980, WWF officially came to China, at the invitation of the Chinese government to carry out the protection work of giant pandas and their habitats...</p>
    </div>
  </div>
</div>

Try It Yourself

Note:Make sure the total is equal to or less than 12 (you do not need to use all 12 available columns):

using Medium only

In the following example, we only specify .col-md-6 class (without .col-sm-*). This means that medium, large, extra-large, and XXL devices will split 50% / 50% - because this class will expand. However, for small and extra-small devices, they will be vertically stacked (100% width):

Example

<div class="row">
  <div class="col-md-6">
    <p>The World Wide Fund for Nature (WWF), founded on April 29, 1961, has a giant panda as its logo...</p>
  </div>
  <div class="col-md-6">
    <p>In 1980, WWF officially came to China, at the invitation of the Chinese government to carry out the protection work of giant pandas and their habitats...</p>
  </div>
</div>

Try It Yourself

Automatic Layout Columns

In Bootstrap 5, there is a simple way to create equal-width columns for all devices: just from .col-md-* remove the numbers and use only on the col element .col-md class. Bootstrap will recognize how many columns there are, and each column will get the same width.

If the screen sizeLess than 768px, columns will be horizontally stacked:

<!-- Two columns: 50% width on medium and larger devices -->
<div class="row">
  <div class="col-md">1 of 2</div>
  <div class="col-md">2 of 2</div>
</div>
<!-- Four columns: 25% width on medium and larger devices -->
<div class="row">
  <div class="col-md">1 of 4</div>
  <div class="col-md">2 of 4</div>
  <div class="col-md">3 of 4</div>
  <div class="col-md">4 of 4</div>
</div>

Try It Yourself

The next chapter will show how to add different split percentages for large devices.