Table Structure
Documentation and examples for opt-in styling of tables (given their prevalent use in JavaScript plugins) with Bootstrap.
Table Overview
Due to the widespread use of <table>
elements across third-party widgets like calendars and date pickers, Bootstrap’s tables are opt-in. Add the base class .table
to any <table>
, then extend with our optional modifier classes or custom styles. All table styles are not inherited in Bootstrap, meaning any nested tables can be styled independent from the parent.
Using the most basic table markup, here’s how .table
-based tables look in Bootstrap.
These classes can also be added to table variants:
Bordered tables
Add .table-bordered
for borders on all sides of the table and cells.
Hoverable rows
Add .table-hover
to enable a hover state on table rows within a <tbody>
.
Table head
Similar to tables and dark tables, use the modifier classes .table-light
or .table-dark
to make <thead>
s appear light or dark gray.
Vertical alignment
Table cells of <thead>
are always vertical aligned to the bottom. Table cells in <tbody>
inherit their alignment from <table>
and are aligned to the top by default.
Nesting
Border styles, active styles, and table variants are not inherited by nested tables.
How nesting works
To prevent any styles from leaking to nested tables, we use the child combinator (>
) selector in our CSS. Since we need to target all the td
s and th
s in the thead
, tbody
, and tfoot
, our selector would look pretty long without it. As such, we use the rather odd looking .table > :not(caption) > * > *
selector to target all td
s and th
s of the .table
, but none of any potential nested tables.
Note that if you add <tr>
s as direct children of a table, those <tr>
will be wrapped in a <tbody>
by default, thus making our selectors work as intended.
Responsive tables
Responsive tables allow tables to be scrolled horizontally with ease. Make any table responsive across all viewports by wrapping a .table
with .table-responsive
. Or, pick a maximum breakpoint with which to have a responsive table up to by using .table-responsive{-sm|-md|-lg|-xl|-xxl}
.
Navs and tabs
Navigation available in Bootstrap share general markup and styles, from the base .nav
class to the active and disabled states. Swap modifier classes to switch between each style.
The base .nav
component is built with flexbox and provide a strong foundation for building all types of navigation components. It includes some style overrides (for working with lists), some link padding for larger hit areas, and basic disabled styling.
Use the tab JavaScript plugin—include it individually or through the compiled bootstrap.js
file—to extend our navigational tabs and pills to create tabbable panes of local content.
JavaScript behavior
To help fit your needs, this works with <ul>
-based markup, as shown above, or with any arbitrary “roll your own” markup. Note that if you’re using <nav>
, you shouldn’t add role="tablist"
directly to it, as this would override the element’s native role as a navigation landmark. Instead, switch to an alternative element (in the example below, a simple <div>
) and wrap the <nav>
around it.
Last updated