Question
How to Center a Bootstrap 3 Column in the Grid System
Question
How can I center a div that uses a single Bootstrap column width inside a 12-column container in Bootstrap 3?
For example, I have this code:
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
.centered {
background-color: red;
}
</style>
<body class="container">
<div class="col-lg-1 col-offset-6 centered">
<img src="https://via.placeholder.com/100" alt="Example image">
</div>
</body>
I want the .centered element to appear in the middle of the container. I may later place it inside a .row if I have multiple elements, but for now I just want one div that is one column wide and visually centered inside the 12-column layout.
I am also unsure whether using an offset is the right approach, because I do not want to "push" the element over arbitrarily. I want the empty space on both sides to be distributed evenly, and as the container becomes smaller, that space should shrink evenly until the container width is about the same as the column itself.
Short Answer
By the end of this page, you will understand how centering works in Bootstrap 3's grid system, why columns must live inside rows, when to use offsets, and when to use text alignment or custom CSS instead. You will also see practical examples for centering a single column and centering its contents correctly.
Concept
Bootstrap 3 uses a 12-column grid system. Each .col-* element takes up a certain number of those 12 columns.
For example:
.col-lg-1uses 1 out of 12 columns.col-lg-6uses 6 out of 12 columns.col-lg-12uses the full width
To center a column, you need to think about how much remaining space is left in the row and how to distribute it.
If a column uses 1 out of 12, then 11 columns remain. Since 11 cannot be split evenly into two whole grid columns, Bootstrap's offset classes alone cannot perfectly center a col-lg-1 column within the grid.
That is why there are really two different meanings of centering here:
- Centering the grid column itself inside the 12-column layout
- Centering the content inside a full-width parent
In Bootstrap 3, offsets work well when the remaining columns can be split evenly. For example:
col-md-6can be centered withcol-md-offset-3col-md-4can be centered with
Mental Model
Think of the Bootstrap grid like a shelf divided into 12 equal slots.
If your box takes up 1 slot, there are 11 empty slots left.
To center the box perfectly, you would want to put half the empty slots on the left and half on the right. But half of 11 is 5.5, and the Bootstrap grid does not support half-slots.
So you have three options:
- put it slightly off-center using whole-slot offsets
- make the parent full width and center the content inside it
- use custom CSS for exact visual centering
The key idea is: Bootstrap columns work in fixed grid units, but visual centering sometimes needs more flexibility than the grid allows.
Syntax and Examples
Bootstrap 3 columns should be placed inside a .row.
Basic grid syntax
<div class="container">
<div class="row">
<div class="col-md-6">Content</div>
</div>
</div>
Centering a column with an offset
This works well when the column width leaves an even number of columns remaining.
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3 centered">
Centered 6-column block
</div>
</div>
</div>
Explanation:
col-md-6uses 6 columns
Step by Step Execution
Consider this example:
<div class="container">
<div class="row text-center">
<div class="col-xs-12">
<div class="centered" style="display:inline-block; width:80px; height:80px; background:red;"></div>
</div>
</div>
</div>
Here is what happens step by step:
-
container- Creates a centered Bootstrap layout area with fixed widths at different screen sizes.
-
row text-centerrowprepares the grid layout correctly.text-centerappliestext-align: centerto its contents.
Real World Use Cases
Centering small elements is common in real projects.
Common examples
- Profile avatars centered in a card header
- Icons centered inside a banner or feature section
- Buttons centered below a form or message
- Loading indicators centered in a page section
- Single-image thumbnails centered in a content area
In dashboards and admin panels
Developers often center:
- empty-state illustrations
- status badges
- call-to-action buttons
- summary widgets
In responsive pages
You may want:
- a full-width parent container
- a child element that keeps its natural width
- equal space on both sides as the screen resizes
That is usually a sign that content centering is more appropriate than grid-column centering.
Real Codebase Usage
In real Bootstrap 3 codebases, developers usually choose among a few common patterns.
1. Use offsets for true grid layouts
When the layout is based on columns and the math works evenly:
<div class="row">
<div class="col-sm-4 col-sm-offset-4">Centered block</div>
</div>
This is common for:
- login forms
- modal-like page sections
- narrow content panels
2. Use full-width columns plus centered content
When the child should be visually centered but not forced into grid math:
<div class="row text-center">
<div class="col-xs-12">
<button class="btn btn-primary">Save</button>
</div>
</div>
This is common for:
Common Mistakes
1. Using the wrong offset class name
Broken code:
<div class="col-lg-1 col-offset-6"></div>
Why it is wrong:
- Bootstrap 3 offset classes include the breakpoint name
col-offset-6does not exist
Correct pattern:
<div class="col-lg-1 col-lg-offset-5"></div>
2. Forgetting the .row
Broken code:
<div class="container">
<div class="col-md-6">Content</div>
</div>
Why it is wrong:
- Bootstrap columns are designed to live inside
.row
Comparisons
| Approach | Best for | Pros | Cons |
|---|---|---|---|
| Bootstrap offset classes | Centering a grid column when the math divides evenly | Uses the grid system cleanly | Cannot perfectly center widths like 1/12 |
text-center + inline-block | Centering small content visually | Simple and responsive | Best for content, not structural grid layout |
margin: 0 auto | Centering fixed-width block elements | Very common and easy | Requires a defined width |
| Empty columns on both sides | Manual grid balancing | Stays inside grid logic | Verbose and still limited by grid fractions |
Offset vs visual centering
Cheat Sheet
Bootstrap 3 centering quick reference
Correct grid structure
<div class="container">
<div class="row">
<div class="col-md-6">...</div>
</div>
</div>
Offset syntax
col-md-offset-3
col-lg-offset-4
Example: centered 6-column block
<div class="col-md-6 col-md-offset-3"></div>
Important rule
A column can be perfectly centered with offsets only when:
(12 - columnWidth) / 2
is a whole number.
Examples
col-md-6->(12 - 6) / 2 = 3✅
FAQ
Can I center a col-lg-1 perfectly in Bootstrap 3 using only offsets?
No. A col-lg-1 leaves 11 columns of free space, and that cannot be divided evenly into two whole-column offsets.
What is the correct Bootstrap 3 offset class format?
Use col-{breakpoint}-offset-{number}, such as col-md-offset-3 or col-lg-offset-5.
Do Bootstrap columns need to be inside a .row?
Yes. In Bootstrap 3, columns should be placed inside .row elements for the grid spacing to work correctly.
How do I center a small image or icon in Bootstrap 3?
A common approach is to use a full-width column and apply text-center to the parent, then make the child inline-block if needed.
When should I use margin: 0 auto instead of grid offsets?
Use margin: 0 auto when the element has a defined width and you want simple visual centering without relying on grid math.
Is text-center enough to center a div?
Not always. It centers inline and inline-block content. A normal block usually still takes the full width.
Mini Project
Description
Build a small Bootstrap 3 demo page that shows three different ways to center content: a centered grid column using offsets, a visually centered small box using text-center, and a fixed-width box centered with margin: 0 auto. This helps you learn when each technique is appropriate.
Goal
Create a page that demonstrates the difference between grid centering and visual centering in Bootstrap 3.
Requirements
- Create a Bootstrap 3 container with at least three separate examples.
- Show one example using a valid offset class.
- Show one example using
text-centerwith an inline-block child. - Show one example using custom CSS with
margin: 0 auto. - Add short labels so it is clear what each example demonstrates.
Keep learning
Related questions
Angular ngClass Conditional Class Binding Explained
Learn how to use Angular ngClass for conditional classes, fix common binding mistakes, and understand why this template error happens.
CSS :not() Selector for Elements Without a Class or Attribute
Learn how to use the CSS :not() selector to target elements that do not have a specific class or attribute, with examples and common pitfalls.
CSS Font Scaling Relative to Container Size: %, em, rem, vw, and Responsive Text
Learn how CSS font scaling really works and how to make text responsive using %, em, rem, vw, clamp(), and media queries.