Tables

Documentation and examples for opt-in styling of tables (given their prevalent use in JavaScript plugins) with Bootstrap.

Examples

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.

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.

Tables - 图1

  1. <table class="table">
  2. <thead>
  3. <tr>
  4. <th scope="col">#</th>
  5. <th scope="col">First</th>
  6. <th scope="col">Last</th>
  7. <th scope="col">Handle</th>
  8. </tr>
  9. </thead>
  10. <tbody>
  11. <tr>
  12. <th scope="row">1</th>
  13. <td>Mark</td>
  14. <td>Otto</td>
  15. <td>@mdo</td>
  16. </tr>
  17. <tr>
  18. <th scope="row">2</th>
  19. <td>Jacob</td>
  20. <td>Thornton</td>
  21. <td>@fat</td>
  22. </tr>
  23. <tr>
  24. <th scope="row">3</th>
  25. <td>Larry</td>
  26. <td>the Bird</td>
  27. <td>@twitter</td>
  28. </tr>
  29. </tbody>
  30. </table>

You can also invert the colors—with light text on dark backgrounds—with .table-dark.

Tables - 图2

  1. <table class="table table-dark">
  2. <thead>
  3. <tr>
  4. <th scope="col">#</th>
  5. <th scope="col">First</th>
  6. <th scope="col">Last</th>
  7. <th scope="col">Handle</th>
  8. </tr>
  9. </thead>
  10. <tbody>
  11. <tr>
  12. <th scope="row">1</th>
  13. <td>Mark</td>
  14. <td>Otto</td>
  15. <td>@mdo</td>
  16. </tr>
  17. <tr>
  18. <th scope="row">2</th>
  19. <td>Jacob</td>
  20. <td>Thornton</td>
  21. <td>@fat</td>
  22. </tr>
  23. <tr>
  24. <th scope="row">3</th>
  25. <td>Larry</td>
  26. <td>the Bird</td>
  27. <td>@twitter</td>
  28. </tr>
  29. </tbody>
  30. </table>

Table head options

Similar to tables and dark tables, use the modifier classes .thead-light or .thead-dark to make <thead>s appear light or dark gray.

Tables - 图3

  1. <table class="table">
  2. <thead class="thead-dark">
  3. <tr>
  4. <th scope="col">#</th>
  5. <th scope="col">First</th>
  6. <th scope="col">Last</th>
  7. <th scope="col">Handle</th>
  8. </tr>
  9. </thead>
  10. <tbody>
  11. <tr>
  12. <th scope="row">1</th>
  13. <td>Mark</td>
  14. <td>Otto</td>
  15. <td>@mdo</td>
  16. </tr>
  17. <tr>
  18. <th scope="row">2</th>
  19. <td>Jacob</td>
  20. <td>Thornton</td>
  21. <td>@fat</td>
  22. </tr>
  23. <tr>
  24. <th scope="row">3</th>
  25. <td>Larry</td>
  26. <td>the Bird</td>
  27. <td>@twitter</td>
  28. </tr>
  29. </tbody>
  30. </table>
  31. <table class="table">
  32. <thead class="thead-light">
  33. <tr>
  34. <th scope="col">#</th>
  35. <th scope="col">First</th>
  36. <th scope="col">Last</th>
  37. <th scope="col">Handle</th>
  38. </tr>
  39. </thead>
  40. <tbody>
  41. <tr>
  42. <th scope="row">1</th>
  43. <td>Mark</td>
  44. <td>Otto</td>
  45. <td>@mdo</td>
  46. </tr>
  47. <tr>
  48. <th scope="row">2</th>
  49. <td>Jacob</td>
  50. <td>Thornton</td>
  51. <td>@fat</td>
  52. </tr>
  53. <tr>
  54. <th scope="row">3</th>
  55. <td>Larry</td>
  56. <td>the Bird</td>
  57. <td>@twitter</td>
  58. </tr>
  59. </tbody>
  60. </table>

Striped rows

Use .table-striped to add zebra-striping to any table row within the <tbody>.

Tables - 图4

  1. <table class="table table-striped">
  2. <thead>
  3. <tr>
  4. <th scope="col">#</th>
  5. <th scope="col">First</th>
  6. <th scope="col">Last</th>
  7. <th scope="col">Handle</th>
  8. </tr>
  9. </thead>
  10. <tbody>
  11. <tr>
  12. <th scope="row">1</th>
  13. <td>Mark</td>
  14. <td>Otto</td>
  15. <td>@mdo</td>
  16. </tr>
  17. <tr>
  18. <th scope="row">2</th>
  19. <td>Jacob</td>
  20. <td>Thornton</td>
  21. <td>@fat</td>
  22. </tr>
  23. <tr>
  24. <th scope="row">3</th>
  25. <td>Larry</td>
  26. <td>the Bird</td>
  27. <td>@twitter</td>
  28. </tr>
  29. </tbody>
  30. </table>

Tables - 图5

  1. <table class="table table-striped table-dark">
  2. <thead>
  3. <tr>
  4. <th scope="col">#</th>
  5. <th scope="col">First</th>
  6. <th scope="col">Last</th>
  7. <th scope="col">Handle</th>
  8. </tr>
  9. </thead>
  10. <tbody>
  11. <tr>
  12. <th scope="row">1</th>
  13. <td>Mark</td>
  14. <td>Otto</td>
  15. <td>@mdo</td>
  16. </tr>
  17. <tr>
  18. <th scope="row">2</th>
  19. <td>Jacob</td>
  20. <td>Thornton</td>
  21. <td>@fat</td>
  22. </tr>
  23. <tr>
  24. <th scope="row">3</th>
  25. <td>Larry</td>
  26. <td>the Bird</td>
  27. <td>@twitter</td>
  28. </tr>
  29. </tbody>
  30. </table>

Bordered table

Add .table-bordered for borders on all sides of the table and cells.

Tables - 图6

  1. <table class="table table-bordered">
  2. <thead>
  3. <tr>
  4. <th scope="col">#</th>
  5. <th scope="col">First</th>
  6. <th scope="col">Last</th>
  7. <th scope="col">Handle</th>
  8. </tr>
  9. </thead>
  10. <tbody>
  11. <tr>
  12. <th scope="row">1</th>
  13. <td>Mark</td>
  14. <td>Otto</td>
  15. <td>@mdo</td>
  16. </tr>
  17. <tr>
  18. <th scope="row">2</th>
  19. <td>Jacob</td>
  20. <td>Thornton</td>
  21. <td>@fat</td>
  22. </tr>
  23. <tr>
  24. <th scope="row">3</th>
  25. <td colspan="2">Larry the Bird</td>
  26. <td>@twitter</td>
  27. </tr>
  28. </tbody>
  29. </table>

Tables - 图7

  1. <table class="table table-bordered table-dark">
  2. <thead>
  3. <tr>
  4. <th scope="col">#</th>
  5. <th scope="col">First</th>
  6. <th scope="col">Last</th>
  7. <th scope="col">Handle</th>
  8. </tr>
  9. </thead>
  10. <tbody>
  11. <tr>
  12. <th scope="row">1</th>
  13. <td>Mark</td>
  14. <td>Otto</td>
  15. <td>@mdo</td>
  16. </tr>
  17. <tr>
  18. <th scope="row">2</th>
  19. <td>Jacob</td>
  20. <td>Thornton</td>
  21. <td>@fat</td>
  22. </tr>
  23. <tr>
  24. <th scope="row">3</th>
  25. <td colspan="2">Larry the Bird</td>
  26. <td>@twitter</td>
  27. </tr>
  28. </tbody>
  29. </table>

Borderless table

Add .table-borderless for a table without borders.

Tables - 图8

  1. <table class="table table-borderless">
  2. <thead>
  3. <tr>
  4. <th scope="col">#</th>
  5. <th scope="col">First</th>
  6. <th scope="col">Last</th>
  7. <th scope="col">Handle</th>
  8. </tr>
  9. </thead>
  10. <tbody>
  11. <tr>
  12. <th scope="row">1</th>
  13. <td>Mark</td>
  14. <td>Otto</td>
  15. <td>@mdo</td>
  16. </tr>
  17. <tr>
  18. <th scope="row">2</th>
  19. <td>Jacob</td>
  20. <td>Thornton</td>
  21. <td>@fat</td>
  22. </tr>
  23. <tr>
  24. <th scope="row">3</th>
  25. <td colspan="2">Larry the Bird</td>
  26. <td>@twitter</td>
  27. </tr>
  28. </tbody>
  29. </table>

.table-borderless can also be used on dark tables.

Tables - 图9

  1. <table class="table table-borderless table-dark">
  2. <thead>
  3. <tr>
  4. <th scope="col">#</th>
  5. <th scope="col">First</th>
  6. <th scope="col">Last</th>
  7. <th scope="col">Handle</th>
  8. </tr>
  9. </thead>
  10. <tbody>
  11. <tr>
  12. <th scope="row">1</th>
  13. <td>Mark</td>
  14. <td>Otto</td>
  15. <td>@mdo</td>
  16. </tr>
  17. <tr>
  18. <th scope="row">2</th>
  19. <td>Jacob</td>
  20. <td>Thornton</td>
  21. <td>@fat</td>
  22. </tr>
  23. <tr>
  24. <th scope="row">3</th>
  25. <td colspan="2">Larry the Bird</td>
  26. <td>@twitter</td>
  27. </tr>
  28. </tbody>
  29. </table>

Hoverable rows

Add .table-hover to enable a hover state on table rows within a <tbody>.

Tables - 图10

  1. <table class="table table-hover">
  2. <thead>
  3. <tr>
  4. <th scope="col">#</th>
  5. <th scope="col">First</th>
  6. <th scope="col">Last</th>
  7. <th scope="col">Handle</th>
  8. </tr>
  9. </thead>
  10. <tbody>
  11. <tr>
  12. <th scope="row">1</th>
  13. <td>Mark</td>
  14. <td>Otto</td>
  15. <td>@mdo</td>
  16. </tr>
  17. <tr>
  18. <th scope="row">2</th>
  19. <td>Jacob</td>
  20. <td>Thornton</td>
  21. <td>@fat</td>
  22. </tr>
  23. <tr>
  24. <th scope="row">3</th>
  25. <td colspan="2">Larry the Bird</td>
  26. <td>@twitter</td>
  27. </tr>
  28. </tbody>
  29. </table>

Tables - 图11

  1. <table class="table table-hover table-dark">
  2. <thead>
  3. <tr>
  4. <th scope="col">#</th>
  5. <th scope="col">First</th>
  6. <th scope="col">Last</th>
  7. <th scope="col">Handle</th>
  8. </tr>
  9. </thead>
  10. <tbody>
  11. <tr>
  12. <th scope="row">1</th>
  13. <td>Mark</td>
  14. <td>Otto</td>
  15. <td>@mdo</td>
  16. </tr>
  17. <tr>
  18. <th scope="row">2</th>
  19. <td>Jacob</td>
  20. <td>Thornton</td>
  21. <td>@fat</td>
  22. </tr>
  23. <tr>
  24. <th scope="row">3</th>
  25. <td colspan="2">Larry the Bird</td>
  26. <td>@twitter</td>
  27. </tr>
  28. </tbody>
  29. </table>

Small table

Add .table-sm to make tables more compact by cutting cell padding in half.

Tables - 图12

  1. <table class="table table-sm">
  2. <thead>
  3. <tr>
  4. <th scope="col">#</th>
  5. <th scope="col">First</th>
  6. <th scope="col">Last</th>
  7. <th scope="col">Handle</th>
  8. </tr>
  9. </thead>
  10. <tbody>
  11. <tr>
  12. <th scope="row">1</th>
  13. <td>Mark</td>
  14. <td>Otto</td>
  15. <td>@mdo</td>
  16. </tr>
  17. <tr>
  18. <th scope="row">2</th>
  19. <td>Jacob</td>
  20. <td>Thornton</td>
  21. <td>@fat</td>
  22. </tr>
  23. <tr>
  24. <th scope="row">3</th>
  25. <td colspan="2">Larry the Bird</td>
  26. <td>@twitter</td>
  27. </tr>
  28. </tbody>
  29. </table>

Tables - 图13

  1. <table class="table table-sm table-dark">
  2. <thead>
  3. <tr>
  4. <th scope="col">#</th>
  5. <th scope="col">First</th>
  6. <th scope="col">Last</th>
  7. <th scope="col">Handle</th>
  8. </tr>
  9. </thead>
  10. <tbody>
  11. <tr>
  12. <th scope="row">1</th>
  13. <td>Mark</td>
  14. <td>Otto</td>
  15. <td>@mdo</td>
  16. </tr>
  17. <tr>
  18. <th scope="row">2</th>
  19. <td>Jacob</td>
  20. <td>Thornton</td>
  21. <td>@fat</td>
  22. </tr>
  23. <tr>
  24. <th scope="row">3</th>
  25. <td colspan="2">Larry the Bird</td>
  26. <td>@twitter</td>
  27. </tr>
  28. </tbody>
  29. </table>

Contextual classes

Use contextual classes to color table rows or individual cells.

Tables - 图14

  1. <!-- On rows -->
  2. <tr class="table-active">...</tr>
  3. <tr class="table-primary">...</tr>
  4. <tr class="table-secondary">...</tr>
  5. <tr class="table-success">...</tr>
  6. <tr class="table-danger">...</tr>
  7. <tr class="table-warning">...</tr>
  8. <tr class="table-info">...</tr>
  9. <tr class="table-light">...</tr>
  10. <tr class="table-dark">...</tr>
  11. <!-- On cells (`td` or `th`) -->
  12. <tr>
  13. <td class="table-active">...</td>
  14. <td class="table-primary">...</td>
  15. <td class="table-secondary">...</td>
  16. <td class="table-success">...</td>
  17. <td class="table-danger">...</td>
  18. <td class="table-warning">...</td>
  19. <td class="table-info">...</td>
  20. <td class="table-light">...</td>
  21. <td class="table-dark">...</td>
  22. </tr>

Regular table background variants are not available with the dark table, however, you may use text or background utilities to achieve similar styles.

Tables - 图15

  1. <!-- On rows -->
  2. <tr class="bg-primary">...</tr>
  3. <tr class="bg-success">...</tr>
  4. <tr class="bg-warning">...</tr>
  5. <tr class="bg-danger">...</tr>
  6. <tr class="bg-info">...</tr>
  7. <!-- On cells (`td` or `th`) -->
  8. <tr>
  9. <td class="bg-primary">...</td>
  10. <td class="bg-success">...</td>
  11. <td class="bg-warning">...</td>
  12. <td class="bg-danger">...</td>
  13. <td class="bg-info">...</td>
  14. </tr>
Conveying meaning to assistive technologies

Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the .sr-only class.

Create responsive tables by wrapping any .table with .table-responsive{-sm|-md|-lg|-xl}, making the table scroll horizontally at each max-width breakpoint of up to (but not including) 576px, 768px, 992px, and 1120px, respectively.

Note that since browsers do not currently support range context queries, we work around the limitations of min- and max- prefixes and viewports with fractional widths (which can occur under certain conditions on high-dpi devices, for instance) by using values with higher precision for these comparisons.

Captions

A <caption> functions like a heading for a table. It helps users with screen readers to find a table and understand what it’s about and decide if they want to read it.

Tables - 图16

  1. <table class="table">
  2. <caption>List of users</caption>
  3. <thead>
  4. <tr>
  5. <th scope="col">#</th>
  6. <th scope="col">First</th>
  7. <th scope="col">Last</th>
  8. <th scope="col">Handle</th>
  9. </tr>
  10. </thead>
  11. <tbody>
  12. <tr>
  13. <th scope="row">1</th>
  14. <td>Mark</td>
  15. <td>Otto</td>
  16. <td>@mdo</td>
  17. </tr>
  18. <tr>
  19. <th scope="row">2</th>
  20. <td>Jacob</td>
  21. <td>Thornton</td>
  22. <td>@fat</td>
  23. </tr>
  24. <tr>
  25. <th scope="row">3</th>
  26. <td>Larry</td>
  27. <td>the Bird</td>
  28. <td>@twitter</td>
  29. </tr>
  30. </tbody>
  31. </table>

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}.

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.

Always responsive

Across every breakpoint, use .table-responsive for horizontally scrolling tables.

Tables - 图17

  1. <div class="table-responsive">
  2. <table class="table">
  3. ...
  4. </table>
  5. </div>

Breakpoint specific

Use .table-responsive{-sm|-md|-lg|-xl} as needed to create responsive tables up to a particular breakpoint. From that breakpoint and up, the table will behave normally and not scroll horizontally.

These tables may appear broken until their responsive styles apply at specific viewport widths.

Tables - 图18

  1. <div class="table-responsive-sm">
  2. <table class="table">
  3. ...
  4. </table>
  5. </div>

Tables - 图19

  1. <div class="table-responsive-md">
  2. <table class="table">
  3. ...
  4. </table>
  5. </div>

Tables - 图20

  1. <div class="table-responsive-lg">
  2. <table class="table">
  3. ...
  4. </table>
  5. </div>

Tables - 图21

  1. <div class="table-responsive-xl">
  2. <table class="table">
  3. ...
  4. </table>
  5. </div>