Bootstrap Tables

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

TagDescription
<table>Adds basic styling to the table.
<thead>The container element for the table header row (<tr>), used to identify table columns.
<tbody>The container element for table rows (<tr>) in the table body.
<tr>A container element for a group of table cells (<td> or <th>) that appear on a single row.
<td>Default table cell.
<th>A special table cell used to identify a column or row (depending on scope and position). Must be used within <thead>.
<caption>A description or summary of the content stored in the table.

Table Classes

The following table styles can be used in tables:

Class Description Example
.table Adds basic styling to any <table> (only horizontal dividers) Try it
.table-striped Adds zebra-striping to rows within <tbody> (IE8 not supported) Try it
.table-bordered Adds borders to all table cells. Try it
.table-hover Enables a hover state on any row within <tbody> Try it
.table-condensed Makes the table more compact. Try it
Combine all table classes. Try it

<tr>, <th>, and <td> Classes

The classes in the table below can be used on table rows or cells:

Class Description Example
.active Applies the hover color to a row or cell. Try it
.success Indicates a successful action. Try it
.info Indicates an informational change action. 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 shown below:

基本的表格

Optional Table Classes

In addition to the basic table markup and the `.table` class, there are also some classes that can be used to style the markup. These classes are introduced below.

Striped Table

By adding.table-stripedclass, you will see stripes on rows within <tbody>, as shown in the example below:

Example

<table class="table table-striped"> <caption>Striped Table Layout</caption> <thead> <tr> <th>Name</th> <th>City</th> <th>Postal 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 shown below:

条纹表格

Bordered Table

By adding.table-borderedclass, you will see borders around every element, and the entire table is rounded, 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>Postal 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 shown below:

边框表格

Hover Table

By adding.table-hoverclass, a light gray background will appear 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</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 Yourself »

The result is as follows:

悬停表格

Condensed Table

By adding.table-condensed class, the row padding is cut in half to make the table look more compact, as shown in the example below. This is very useful when you want the 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</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 Yourself »

The result is as follows:

精简表格

Contextual Classes

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

ClassDescription
.activeApplies the hover color to a particular row or cell.
.successIndicates a successful or positive action.
.warningIndicates a warning that requires attention.
.dangerIndicates a dangerous or potentially negative action.

These classes can be applied to <tr>, <td>, or <th>.

Example

<table class="table"> <caption>Contextual Table Layout</caption> <thead> <tr> <th>Product</th> <th>Payment Date</th> <th>Status</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>Shipping</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 Yourself »

The result is as follows:

上下文类

Responsive Table

By wrapping any.tableinside a.table-responsiveclass, you can make the table scroll horizontally to fit small devices (less than 768px).

Example

<div class="table-responsive"> <table class="table"> <caption>Responsive Table Layout</caption> <thead> <tr> <th>Product</th> <th>Payment Date</th> <th>Status</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>Shipping</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 Yourself »

The result is as follows:

响应式表格
Other Extensions