2014-07-12 07:34:47 +02:00
---
2015-08-15 07:45:55 +02:00
layout: docs
2014-07-12 07:34:47 +02:00
title: Tables
2016-10-03 03:19:47 +02:00
description: Documentation and examples for styling tables with Bootstrap.
2015-08-10 08:38:16 +02:00
group: content
2014-07-12 07:34:47 +02:00
---
2016-05-08 23:15:34 +02:00
Due to the widespread use of tables across third-party widgets like calendars and date pickers, we've designed our tables to be **opt-in** . Just add the base class `.table` to any `<table>` , then extend with custom styles or our various included modifier classes.
2014-07-12 07:34:47 +02:00
2015-05-29 10:58:52 +02:00
## Contents
* Will be replaced with the ToC, excluding the "Contents" header
{:toc}
2016-05-08 23:15:34 +02:00
## Examples
2016-10-03 03:27:53 +02:00
Using the most basic table markup, here's how `.table` -based tables look in Bootstrap. **All table styles are inherited in Bootstrap 4** , meaning any nested tables will be styled in the same manner as the parent.
2014-07-12 07:34:47 +02:00
{% example html %}
< table class = "table" >
< thead >
< tr >
< th > #< / th >
< th > First Name< / th >
< th > Last Name< / th >
< th > Username< / th >
< / tr >
< / thead >
< tbody >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 1< / th >
2014-07-12 07:34:47 +02:00
< td > Mark< / td >
< td > Otto< / td >
< td > @mdo< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 2< / th >
2014-07-12 07:34:47 +02:00
< td > Jacob< / td >
< td > Thornton< / td >
< td > @fat< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 3< / th >
2014-07-12 07:34:47 +02:00
< td > Larry< / td >
< td > the Bird< / td >
< td > @twitter< / td >
< / tr >
< / tbody >
< / table >
{% endexample %}
2016-05-08 23:15:34 +02:00
You can also invert the colors—with light text on dark backgrounds—with `.table-inverse` .
2014-07-14 09:23:46 +02:00
{% example html %}
< table class = "table table-inverse" >
< thead >
< tr >
< th > #< / th >
< th > First Name< / th >
< th > Last Name< / th >
< th > Username< / th >
< / tr >
< / thead >
< tbody >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 1< / th >
2014-07-14 09:23:46 +02:00
< td > Mark< / td >
< td > Otto< / td >
< td > @mdo< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 2< / th >
2014-07-14 09:23:46 +02:00
< td > Jacob< / td >
< td > Thornton< / td >
< td > @fat< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 3< / th >
2014-07-14 09:23:46 +02:00
< td > Larry< / td >
< td > the Bird< / td >
< td > @twitter< / td >
< / tr >
< / tbody >
< / table >
{% endexample %}
2014-07-14 08:45:34 +02:00
## Table head options
2016-05-08 23:15:34 +02:00
Similar to default and inverse tables, use one of two modifier classes to make `<thead>` s appear light or dark gray.
2014-07-14 08:45:34 +02:00
{% example html %}
< table class = "table" >
< thead class = "thead-inverse" >
< tr >
< th > #< / th >
< th > First Name< / th >
< th > Last Name< / th >
< th > Username< / th >
< / tr >
< / thead >
< tbody >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 1< / th >
2014-07-14 08:45:34 +02:00
< td > Mark< / td >
< td > Otto< / td >
< td > @mdo< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 2< / th >
2014-07-14 08:45:34 +02:00
< td > Jacob< / td >
< td > Thornton< / td >
< td > @fat< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 3< / th >
2014-07-14 08:45:34 +02:00
< td > Larry< / td >
< td > the Bird< / td >
< td > @twitter< / td >
< / tr >
< / tbody >
2015-05-28 00:49:55 +02:00
< / table >
< table class = "table" >
2014-07-14 08:45:34 +02:00
< thead class = "thead-default" >
< tr >
< th > #< / th >
< th > First Name< / th >
< th > Last Name< / th >
< th > Username< / th >
< / tr >
< / thead >
< tbody >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 1< / th >
2014-07-14 08:45:34 +02:00
< td > Mark< / td >
< td > Otto< / td >
< td > @mdo< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 2< / th >
2014-07-14 08:45:34 +02:00
< td > Jacob< / td >
< td > Thornton< / td >
< td > @fat< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 3< / th >
2014-07-14 08:45:34 +02:00
< td > Larry< / td >
< td > the Bird< / td >
< td > @twitter< / td >
< / tr >
< / tbody >
< / table >
{% endexample %}
2014-07-12 07:34:47 +02:00
## Striped rows
Use `.table-striped` to add zebra-striping to any table row within the `<tbody>` .
{% example html %}
< table class = "table table-striped" >
< thead >
< tr >
< th > #< / th >
< th > First Name< / th >
< th > Last Name< / th >
< th > Username< / th >
< / tr >
< / thead >
< tbody >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 1< / th >
2014-07-12 07:34:47 +02:00
< td > Mark< / td >
< td > Otto< / td >
< td > @mdo< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 2< / th >
2014-07-12 07:34:47 +02:00
< td > Jacob< / td >
< td > Thornton< / td >
< td > @fat< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 3< / th >
2014-07-12 07:34:47 +02:00
< td > Larry< / td >
< td > the Bird< / td >
< td > @twitter< / td >
< / tr >
< / tbody >
< / table >
{% endexample %}
2016-05-12 01:28:28 +02:00
{% example html %}
< table class = "table table-striped table-inverse" >
< thead >
< tr >
< th > #< / th >
< th > First Name< / th >
< th > Last Name< / th >
< th > Username< / th >
< / tr >
< / thead >
< tbody >
< tr >
< th scope = "row" > 1< / th >
< td > Mark< / td >
< td > Otto< / td >
< td > @mdo< / td >
< / tr >
< tr >
< th scope = "row" > 2< / th >
< td > Jacob< / td >
< td > Thornton< / td >
< td > @fat< / td >
< / tr >
< tr >
< th scope = "row" > 3< / th >
< td > Larry< / td >
< td > the Bird< / td >
< td > @twitter< / td >
< / tr >
< / tbody >
< / table >
{% endexample %}
2014-07-12 07:34:47 +02:00
## Bordered table
Add `.table-bordered` for borders on all sides of the table and cells.
{% example html %}
< table class = "table table-bordered" >
< thead >
< tr >
< th > #< / th >
< th > First Name< / th >
< th > Last Name< / th >
< th > Username< / th >
< / tr >
< / thead >
< tbody >
< tr >
2014-12-19 07:59:47 +01:00
< th scope = "row" > 1< / th >
2014-07-12 07:34:47 +02:00
< td > Mark< / td >
< td > Otto< / td >
< td > @mdo< / td >
< / tr >
< tr >
2014-12-19 07:59:47 +01:00
< th scope = "row" > 2< / th >
2014-07-12 07:34:47 +02:00
< td > Mark< / td >
< td > Otto< / td >
< td > @TwBootstrap< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 3< / th >
2014-07-12 07:34:47 +02:00
< td > Jacob< / td >
< td > Thornton< / td >
< td > @fat< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 4< / th >
2014-07-12 07:34:47 +02:00
< td colspan = "2" > Larry the Bird< / td >
< td > @twitter< / td >
< / tr >
< / tbody >
< / table >
{% endexample %}
2016-05-12 01:28:28 +02:00
{% example html %}
< table class = "table table-bordered table-inverse" >
< thead >
< tr >
< th > #< / th >
< th > First Name< / th >
< th > Last Name< / th >
< th > Username< / th >
< / tr >
< / thead >
< tbody >
< tr >
< th scope = "row" > 1< / th >
< td > Mark< / td >
< td > Otto< / td >
< td > @mdo< / td >
< / tr >
< tr >
< th scope = "row" > 2< / th >
< td > Mark< / td >
< td > Otto< / td >
< td > @TwBootstrap< / td >
< / tr >
< tr >
< th scope = "row" > 3< / th >
< td > Jacob< / td >
< td > Thornton< / td >
< td > @fat< / td >
< / tr >
< tr >
< th scope = "row" > 4< / th >
< td colspan = "2" > Larry the Bird< / td >
< td > @twitter< / td >
< / tr >
< / tbody >
< / table >
{% endexample %}
2014-07-12 07:34:47 +02:00
## Hoverable rows
Add `.table-hover` to enable a hover state on table rows within a `<tbody>` .
{% example html %}
< table class = "table table-hover" >
< thead >
< tr >
< th > #< / th >
< th > First Name< / th >
< th > Last Name< / th >
< th > Username< / th >
< / tr >
< / thead >
< tbody >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 1< / th >
2014-07-12 07:34:47 +02:00
< td > Mark< / td >
< td > Otto< / td >
< td > @mdo< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 2< / th >
2014-07-12 07:34:47 +02:00
< td > Jacob< / td >
< td > Thornton< / td >
< td > @fat< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 3< / th >
2014-07-12 07:34:47 +02:00
< td colspan = "2" > Larry the Bird< / td >
< td > @twitter< / td >
< / tr >
< / tbody >
< / table >
{% endexample %}
2016-05-12 01:28:28 +02:00
{% example html %}
< table class = "table table-hover table-inverse" >
< thead >
< tr >
< th > #< / th >
< th > First Name< / th >
< th > Last Name< / th >
< th > Username< / th >
< / tr >
< / thead >
< tbody >
< tr >
< th scope = "row" > 1< / th >
< td > Mark< / td >
< td > Otto< / td >
< td > @mdo< / td >
< / tr >
< tr >
< th scope = "row" > 2< / th >
< td > Jacob< / td >
< td > Thornton< / td >
< td > @fat< / td >
< / tr >
< tr >
< th scope = "row" > 3< / th >
< td colspan = "2" > Larry the Bird< / td >
< td > @twitter< / td >
< / tr >
< / tbody >
< / table >
{% endexample %}
2014-09-18 07:14:27 +02:00
## Small table
2014-07-12 07:34:47 +02:00
2014-09-18 07:14:27 +02:00
Add `.table-sm` to make tables more compact by cutting cell padding in half.
2014-07-12 07:34:47 +02:00
{% example html %}
2014-09-18 07:14:27 +02:00
< table class = "table table-sm" >
2014-07-12 07:34:47 +02:00
< thead >
< tr >
< th > #< / th >
< th > First Name< / th >
< th > Last Name< / th >
< th > Username< / th >
< / tr >
< / thead >
< tbody >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 1< / th >
2014-07-12 07:34:47 +02:00
< td > Mark< / td >
< td > Otto< / td >
< td > @mdo< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 2< / th >
2014-07-12 07:34:47 +02:00
< td > Jacob< / td >
< td > Thornton< / td >
< td > @fat< / td >
2016-05-12 01:28:28 +02:00
< / tr >
< tr >
< th scope = "row" > 3< / th >
< td colspan = "2" > Larry the Bird< / td >
< td > @twitter< / td >
< / tr >
< / tbody >
< / table >
{% endexample %}
{% example html %}
< table class = "table table-sm table-inverse" >
< thead >
< tr >
< th > #< / th >
< th > First Name< / th >
< th > Last Name< / th >
< th > Username< / th >
< / tr >
< / thead >
< tbody >
< tr >
< th scope = "row" > 1< / th >
< td > Mark< / td >
< td > Otto< / td >
< td > @mdo< / td >
< / tr >
< tr >
< th scope = "row" > 2< / th >
< td > Jacob< / td >
< td > Thornton< / td >
< td > @fat< / td >
2014-07-12 07:34:47 +02:00
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 3< / th >
2014-07-12 07:34:47 +02:00
< td colspan = "2" > Larry the Bird< / td >
< td > @twitter< / td >
< / tr >
< / tbody >
< / table >
{% endexample %}
## Contextual classes
Use contextual classes to color table rows or individual cells.
2016-11-26 10:45:40 +01:00
< table class = "table table-bordered table-striped table-responsive" >
< colgroup >
< col class = "col-1" >
< col class = "col-7" >
< / colgroup >
< thead >
< tr >
< th > Class< / th >
< th > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< th scope = "row" >
< code > .table-active< / code >
< / th >
< td > Applies the hover color to a particular row or cell< / td >
< / tr >
< tr >
< th scope = "row" >
< code > .table-success< / code >
< / th >
< td > Indicates a successful or positive action< / td >
< / tr >
< tr >
< th scope = "row" >
< code > .table-info< / code >
< / th >
< td > Indicates a neutral informative change or action< / td >
< / tr >
< tr >
< th scope = "row" >
< code > .table-warning< / code >
< / th >
< td > Indicates a warning that might need attention< / td >
< / tr >
< tr >
< th scope = "row" >
< code > .table-danger< / code >
< / th >
< td > Indicates a dangerous or potentially negative action< / td >
< / tr >
< / tbody >
< / table >
2014-07-12 07:34:47 +02:00
2015-04-16 23:07:20 +02:00
< div class = "bd-example" >
2014-07-12 07:34:47 +02:00
< table class = "table" >
< thead >
< tr >
< th > #< / th >
< th > Column heading< / th >
< th > Column heading< / th >
< th > Column heading< / th >
< / tr >
< / thead >
< tbody >
2015-03-31 03:08:01 +02:00
< tr class = "table-active" >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 1< / th >
2014-07-12 07:34:47 +02:00
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 2< / th >
2014-07-12 07:34:47 +02:00
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
2015-03-31 03:08:01 +02:00
< tr class = "table-success" >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 3< / th >
2014-07-12 07:34:47 +02:00
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 4< / th >
2014-07-12 07:34:47 +02:00
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
2015-03-31 03:08:01 +02:00
< tr class = "table-info" >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 5< / th >
2014-07-12 07:34:47 +02:00
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 6< / th >
2014-07-12 07:34:47 +02:00
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
2015-03-31 03:08:01 +02:00
< tr class = "table-warning" >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 7< / th >
2014-07-12 07:34:47 +02:00
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
< tr >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 8< / th >
2014-07-12 07:34:47 +02:00
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
2015-03-31 03:08:01 +02:00
< tr class = "table-danger" >
2014-12-01 06:01:50 +01:00
< th scope = "row" > 9< / th >
2014-07-12 07:34:47 +02:00
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
< / tbody >
< / table >
< / div >
{% highlight html %}
<!-- On rows -->
2015-03-31 03:08:01 +02:00
< tr class = "table-active" > ...< / tr >
< tr class = "table-success" > ...< / tr >
< tr class = "table-warning" > ...< / tr >
< tr class = "table-danger" > ...< / tr >
< tr class = "table-info" > ...< / tr >
2014-07-12 07:34:47 +02:00
<!-- On cells (`td` or `th` ) -->
< tr >
2015-03-31 03:08:01 +02:00
< td class = "table-active" > ...< / td >
< td class = "table-success" > ...< / td >
< td class = "table-warning" > ...< / td >
< td class = "table-danger" > ...< / td >
< td class = "table-info" > ...< / td >
2014-07-12 07:34:47 +02:00
< / tr >
{% endhighlight %}
2016-10-03 18:55:59 +02:00
Regular table background variants are not available with the inverse table, however, you may use [text or background utilities ]({{ site.baseurl }}/utilities/colors/ ) to achieve similar styles.
2016-05-08 23:15:34 +02:00
< div class = "bd-example" >
< table class = "table table-inverse" >
< thead >
< tr >
< th > #< / th >
< th > Column heading< / th >
< th > Column heading< / th >
< th > Column heading< / th >
< / tr >
< / thead >
< tbody >
< tr class = "bg-primary" >
< th scope = "row" > 1< / th >
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
< tr >
< th scope = "row" > 2< / th >
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
< tr class = "bg-success" >
< th scope = "row" > 3< / th >
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
< tr >
< th scope = "row" > 4< / th >
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
< tr class = "bg-info" >
< th scope = "row" > 5< / th >
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
< tr >
< th scope = "row" > 6< / th >
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
< tr class = "bg-warning" >
< th scope = "row" > 7< / th >
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
< tr >
< th scope = "row" > 8< / th >
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
< tr class = "bg-danger" >
< th scope = "row" > 9< / th >
< td > Column content< / td >
< td > Column content< / td >
< td > Column content< / td >
< / tr >
< / tbody >
< / table >
< / div >
2016-05-08 23:16:23 +02:00
{% highlight html %}
<!-- On rows -->
< tr class = "bg-primary" > ...< / tr >
< tr class = "bg-success" > ...< / tr >
< tr class = "bg-warning" > ...< / tr >
< tr class = "bg-danger" > ...< / tr >
< tr class = "bg-info" > ...< / tr >
<!-- On cells (`td` or `th` ) -->
< tr >
< td class = "bg-primary" > ...< / td >
< td class = "bg-success" > ...< / td >
< td class = "bg-warning" > ...< / td >
< td class = "bg-danger" > ...< / td >
< td class = "bg-info" > ...< / td >
< / tr >
{% endhighlight %}
2016-05-08 23:15:34 +02:00
{% capture callout-include %}{% include callout-warning-color-assistive-technologies.md %}{% endcapture %}
{{ callout-include | markdownify }}
2014-07-12 07:34:47 +02:00
## Responsive tables
2016-11-26 10:45:40 +01:00
Create responsive tables by adding `.table-responsive` to any `.table` to make them scroll horizontally on small devices (under 768px). When viewing on anything larger than 768px wide, you will not see any difference in these tables.
2014-07-12 07:34:47 +02:00
2015-04-17 01:56:40 +02:00
{% callout warning %}
#### Vertical clipping/truncation
Responsive tables make use of `overflow-y: hidden` , which clips off any content that goes beyond the bottom or top edges of the table. In particular, this can clip off dropdown menus and other third-party widgets.
{% endcallout %}
2015-04-16 23:07:20 +02:00
< div class = "bd-example" >
2016-11-26 10:45:40 +01:00
< table class = "table table-responsive" >
< thead >
< tr >
< th > #< / th >
< th > Table heading< / th >
< th > Table heading< / th >
< th > Table heading< / th >
< th > Table heading< / th >
< th > Table heading< / th >
< th > Table heading< / th >
< / tr >
< / thead >
< tbody >
< tr >
< th scope = "row" > 1< / th >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< / tr >
< tr >
< th scope = "row" > 2< / th >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< / tr >
< tr >
< th scope = "row" > 3< / th >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< / tr >
< / tbody >
< / table >
2014-07-12 07:34:47 +02:00
2016-11-26 10:45:40 +01:00
< table class = "table table-bordered table-responsive" >
< thead >
< tr >
< th > #< / th >
< th > Table heading< / th >
< th > Table heading< / th >
< th > Table heading< / th >
< th > Table heading< / th >
< th > Table heading< / th >
< th > Table heading< / th >
< / tr >
< / thead >
< tbody >
< tr >
< th scope = "row" > 1< / th >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< / tr >
< tr >
< th scope = "row" > 2< / th >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< / tr >
< tr >
< th scope = "row" > 3< / th >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< td > Table cell< / td >
< / tr >
< / tbody >
2014-07-12 07:34:47 +02:00
< / table >
< / div >
2016-11-26 10:45:40 +01:00
{% highlight html %}
2017-01-01 01:12:28 +01:00
< table class = "table table-responsive" >
2016-11-26 10:45:40 +01:00
...
< / table >
2014-07-12 07:34:47 +02:00
{% endhighlight %}