Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Bootstrap Tables

Bootstrap Tables

Bootstrap provides a clean layout for creating tables. The table below lists some table elements supported by Bootstrap:

、
tag Description
), used to identify table columns.)。 .
Adds basic styles to a table.
The container element for the table header row (
The container element for table rows in the table body (
A container element for a group of table cells appearing on a single row ( or )。
The default table cell.
A special table cell used to identify a column or row (depending on scope and position). It must be used within
A description or summary of the content stored in the table.

Table classes

The following styles can be used with tables:

Example

<table class=">

table table-striped

"

<

caption

Striped table layout

caption

<

thead

<

tr

<

th

Name

th

<

th

City

th

<

th

Zip code

th

tr

thead

<

tbody

<

tr

<

td

Tanmay

td

<

td

Bangalore

td

<

td

560001

td

tr

<

tr

<

td

Sachin

td

<

td

Mumbai

td

<

td

400003

td

tr

<

tr

<

td

Uma

td

<

td

Pune

td

<

td

411027

td

tr

tbody

table

Try it »

The result is as follows:

Bordered table

By adding the .table-bordered class, you will see borders around every element, with the whole table having rounded corners, as shown in the example below:

Example

<table class=">

table table-bordered

"

<

caption

Bordered table layout

caption

<

thead

<

tr

<

th

Name

th

<

th

City

th

<

th

Zip code

th

tr

thead

<

tbody

<

tr

<

td

Tanmay

td

<

td

Bangalore

td

<

td

560001

td

tr

<

tr

<

td

Sachin

td

<

td

Mumbai

td

<

td

400003

td

tr

<

tr

<

td

Uma

td

<

td

Pune

td

<

td

411027

td

tr

tbody

table

Try it »

The result is as follows:

Hover table

By adding the .table-hover class, a light gray background appears when the pointer hovers over a row, as shown in the example below:

Example

<table class=">

table table-hover

"

<

caption

Hover table layout

caption

<

thead

<

tr

<

th

Name

th

<

th

City

th

<

th

Zip code

th

tr

thead

<

tbody

<

tr

<

td

Tanmay

td

<

td

Bangalore

td

<

td

560001

td

tr

<

tr

<

td

Sachin

td

<

td

Mumbai

td

<

td

400003

td

tr

<

tr

<

td

Uma

td

<

td

Pune

td

<

td

411027

td

tr

tbody

table

Try it »

The result is as follows:

Condensed table

By adding the *.table-condensed* class, the cell padding is halved to make the table look more compact, as shown in the example below. This is useful when you want information to look more compact.

Example

<table class=">

table table-condensed

"

<

caption

Condensed table layout

caption

<

thead

<

tr

<

th

Name

th

<

th

City

th

<

th

Zip code

th

tr

thead

<

tbody

<

tr

<

td

Tanmay

td

<

td

Bangalore

td

<

td

560001

td

tr

<

tr

<

td

Sachin

td

<

td

Mumbai

td

<

td

400003

td

tr

<

tr

<

td

Uma

td

<

td

Pune

td

<

td

411027

td

tr

tbody

table

Try it »

The result is as follows:

Context Class

The contextual classes listed in the table below allow you to change the background color of table rows or individual cells.

, , as shown in the example below:
class Description Example
.table For any add basic styles (horizontal dividers only) add zebra stripes within (not supported in IE8) enable the hover state on any row within
Try it
.table-striped in
Try it
.table-bordered add borders to all table cells Try it
.table-hover in
Try it
.table-condensed make the table more compact Try it
combine all table classes Try it

and class

The classes in the table below can be applied to table rows or cells:

class Description Example
.active Apply hover color to a row or cell Try it
.success Indicates a successful action Try it
.info Indicates an informational change Try it
.warning Indicates a warning action Try it
.danger Indicates a dangerous action Try it

Basic table

If you want a basic table with only padding and horizontal dividers, add the class .table, as shown in the example below:

Example

<

table

class

=

"

table

"

<

caption

Basic table layout

caption

<

thead

<

tr

<

th

Name

th

<

th

City

th

tr

thead

<

tbody

<

tr

<

td

Tanmay

td

<

td

Bangalore

td

tr

<

tr

<

td

Sachin

td

<

td

Mumbai

td

tr

tbody

table

Try it »

The result is as follows:

Optional table classes

Besides the basic table markup and the .table class, there are other classes you can use to style the markup. These classes are introduced below.

Striped table

By adding the .table-striped class, you will see stripes on rows within

class Description
.active Apply hover color to a specific row or cell
.success Indicates a successful or positive action
.warning Indicates a warning that needs attention
.danger Indicates a dangerous or potentially negative action

These classes can be applied to

or 。

Example

<

table

class

=

"

table

"

<

caption

Contextual table layout

caption

<thead>
<tr>
<th Product th>
<th>

Payment date

th

<th State th tr thead>
<tbody>
<tr class="active">
<td>

Product 1

td

<

td

23/11/2013

td

<

td

Pending shipment

td

tr

<tr class="success">
<td>

Product 2

td

<

td

10/11/2013

td

<

td

In transit

td

tr

<tr class="warning">
<td>

Product 3

td

<

td

20/10/2013

td

<

td

Pending confirmation

td

tr

<tr class="danger">
<td>

Product 4

td

<

td

20/10/2013

td

<

td

Returned

td

tr

tbody

table

Try it »

The result is as follows:

Responsive table

By wrapping any .table in a .table-responsive class, you can make the table scroll horizontally to fit small devices (less than 768px). When viewed on larger devices wider than 768px, you will not see any difference.

Example

<

div

class

=

"

table-responsive

"

<

table

class

=

"

table

"

<

caption

Responsive table layout

caption

<thead>
<tr>
<th Product th>
<th>

Payment date

th

<

th

State

th

tr

thead

<

tbody

<

tr

<

td

Product 1

td

<

td

23/11/2013

td

<

td

Pending shipment

td

tr

<

tr

<

td

Product 2

td

<

td

10/11/2013

td

<

td

In transit

td

tr

<

tr

<

td

Product 3

td

<

td

20/10/2013

td

<

td

Pending confirmation

td

tr

<

tr

<

td

Product 4

td

<

td

20/10/2013

td

<

td

Returned

td

tr

tbody

table

div

Try it »

The result is as follows: