← Back to Bootstrap Course | Chapter 2: Grid System | Lesson 7 of 7

Auto-layout columns

Auto-layout columns size themselves from their content or share space equally with no numbers needed.

In this page:

  1. Auto-layout columns
Syntax
markup
<div class="row">
  <div class="col">equal</div>
  <div class="col-6">fixed width</div>
  <div class="col">equal</div>
</div>

Auto-layout columns

Plain .col columns share the row equally. Setting one column's width, such as .col-6, makes the others share the remainder. Variable-width content uses .col-auto or breakpoint versions like .col-md-auto. Gutters can be changed with g-* classes.

Note: g-0 removes gutters, g-4 makes them larger.

Example: Auto-layout columns

markup
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="container text-center">
  <div class="row g-2 mb-2"><div class="col"><div class="bg-info-subtle p-2">1 of 3</div></div><div class="col"><div class="bg-info-subtle p-2">2 of 3</div></div><div class="col"><div class="bg-info-subtle p-2">3 of 3</div></div></div>
  <div class="row g-2"><div class="col"><div class="bg-warning-subtle p-2">fills</div></div><div class="col-6"><div class="bg-warning p-2">col-6</div></div><div class="col"><div class="bg-warning-subtle p-2">fills</div></div></div>
</div>
</body>
</html>
Live Example
Related Topics
Common Mistakes
  1. Mixing fixed widths that overflow
  2. Expecting equal widths with col-auto
  3. Forgetting gutter classes
Chapter Summary
  • .col shares space equally
  • One set width lets others share the rest
  • col-auto sizes to content
  • g-* controls gutters
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.