Tables are a critical component of web design, allowing the clear and structured display of data. However, without proper formatting, tables can appear cluttered and hard to read. One key technique for improving table legibility is adding padding – extra whitespace around the content – to table cells.
In this comprehensive guide, we‘ll explore multiple methods for adding padding to table cells when using the popular Bootstrap framework.
Prerequisites for Following Along
To practice the padding techniques shown here, you‘ll need:
- Basic knowledge of HTML and CSS
- Bootstrap 4 or higher added to your project
- A text or code editor like VS Code
I‘ll also provide code snippets you can drop into an HTML file to quickly test padding effects.
Now, let‘s start exploring approaches for padding Bootstrap tables!
Using Bootstrap‘s Spacing Utilities
One of the easiest ways to add padding in Bootstrap is by using the built-in spacing utility classes. These generate margins and padding on elements through CSS.
Some key spacing utilities include:
- p: Sets padding on all sides
- pt: Sets padding specifically on the top
- pr: Sets padding on the right
- px: Sets left and right padding
The number value after the utility indicates the padding amount in pixels. For example:
<td class="px-5">Cell with 5px left/right padding</td>
Let‘s see this in a complete table example:
<table class="table">
<thead>
<tr>
<th class="px-4">Product</th>
<th class="px-4">Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Widget</td>
<td>$5.00</td>
</tr>
</tbody>
</table>
This pads the left and right of the header cells by 4 pixels, improving text separation and alignment:

Spacing utilities enable quick, class-based padding without writing any CSS. Bootstrap has many other spacing utilities to explore for margins and positional adjustments too.
Next let’s look at some key CSS properties that offer more advanced padding control.
Using CSS Padding Properties
For greater flexibility over table padding, you can directly use CSS padding properties.
Some key points:
- Applies to nearly all HTML elements
- Accepts pixel, em, rem, or % based values
- Can set a single value for equal padding on all sides
- Can specify vertical then horizontal padding
Let‘s walk through examples of both single value and expanded value use cases.
Single Value Padding
To set a 10px padding space evenly within every cell, use:
.table td {
padding: 10px;
}
In this single value syntax, all sides receive 10px padding.
To pad the overall table, wrap it in a <div> with a class and target that:
.table-container {
padding: 20px;
}
<div class="table-container">
<table class="table">
...
</table>
</div>
Padding Shorthand Values
For more control over spacing, the padding property can accept:
- Top padding first
- Right padding second
- Bottom padding third
- Left padding fourth
So the syntax looks like:
padding: 10px 20px 15px 5px;
This would add:
- 10px top
- 20px right
- 15px bottom
- 5px left
You can easily adjust cell and table padding exactly how you‘d like in this manner.
Now that we‘ve covered core methods for adding padding, let’s walk through some real-world applications.
Use Cases and Best Practices for Applying Padding
As mentioned earlier, padding improves aesthetics and legibility. But where specifically should padding be leveraged?
Uniformly Padding Table Bodies
It‘s common to apply light 10-15px padding to full table bodies for better text separation:
.table tbody td {
padding: 15px;
}
You’ll frequently see this in more robust web dashboards and admin UIs:

Uniform padding carries the eye down rows smoothly. But avoid going overboard, or tables become too spaced out.
Highlighting Columns with Side Padding
In many data tables, certain columns carry more important values users should scan for, like names, metrics, and categories.
Adding extra left/right padding selectively calls out these columns:
/* Highlight Name column */
.table td:nth-child(1) {
padding-left: 30px;
padding-right: 30px;
}
This makes key columns visually pop more:

The effect stays subtle enough to not appear distracting. Use this technique judiciously on columns users should pay attention to.
Adding Whitespace Around Nested Elements
When you nest other components like dropdowns or badges within table cells, extra padding prevents a cramped appearance:
/* Pad cells containing badges */
.table td .badge {
padding: 4px 8px;
}
The outcome looks more polished:

Generally keep padding consistent among like elements to maintain alignment across rows.
Creating Cell Separation with Border Spacing
If you want gap space carved out between all cells instead of overlayed on top, use the border-spacing CSS property on the table instead of cell padding:
.table {
border-spacing: 10px;
}
Border spacing literally forces space between element borders:

This can create an appealing striped effect while still aligning text tops properly. However be aware that border-spacing isn‘t fully supported on some older browsers.
When to Avoid Additional Padding
While padding often improves tables, there are a few cases where you‘ll want to omit it:
Tighter Corporate Tables
For formal business data presentation, excessive padding diminishes the hardline, grid-oriented aesthetic expected. Stick to subtler padding unless whitespace is explicitly needed.
Tables Already Encapsulated as Widgets
If building an admin dashboard for example, complete tables may live within dedicated cards or widgets that already provide outer padding. Adding cell or row padding stacks whitespace in a disruptive way here.
Spacing Provided by Alternate Properties
In some contexts, padding can interfere with positioning or sizing dependent on tight element bounding boxes. Carefully consider if padding is layering onto extraneous layout spacing already in effect.
Use good CSS judgement! Now let‘s conclude with a final lightning round of useful padding-related properties.
Advanced Padding Techniques
Here are a few more deep cut padding properties that occasionally help polish table presentation:
Box Sizing for Padding Control
The box-sizing property can help padding avoid increasing element widths:
.table td {
box-sizing: border-box;
padding: 15px;
}
Text Indent for Aligned Content
Similar to padding but for only text, text-indent uniformly indents all text lines within an element:
.table td {
text-indent: 20px;
}
Great for formal reports and grids.
Line Height for Single Line Cells
To vertically center text in table header cells for example:
.table th {
line-height: 2;
}
Putting It All Together
That wraps up major methods and use cases for padding Bootstrap table elements! Padding seems simple but requires taste and restraint. Some key pointers in review:
🚀 Use Bootstrap spacing utilities classes for quick padding via predefined styles
🚀 Lean on the CSS padding property for granular control over individual sides
🚀 Pad entire table bodies evenly for clean interior spacing
🚀 Call attention to important columns by increasing left/right padding
🚀 Nest HTML elements benefit from extra padding too
🚀 For gutters between ALL cells, border-spacing does the trick
🚀 Avoid padding when it stacks onto existing container whitespace
There are plenty more niche padding tactics, but these tips will handle most common table scenarios. Confidently use padding now to enhance table clarity and presentation!


