tables.mdx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. ---
  2. title: Tables
  3. summary: Tables are useful interface elements that allow you to visualize data and arrange it in a clear way. Thanks to that, users can browse a lot of information at once and a good table design will help you take care of its clarity.
  4. bootstrapLink: content/tables/
  5. description: Visualize data clearly with tables.
  6. ---
  7. ## Basic Table
  8. The basic table design has light padding and the presented data is separated with horizontal dividers. It helps provide users with all the necessary information, without overwhelming them with visuals.
  9. The `.table` class adds basic styling to a table:
  10. ```html example height="360px" scrollable
  11. <div class="table-responsive">
  12. <table class="table table-vcenter">
  13. <thead>
  14. <tr>
  15. <th>Name</th>
  16. <th>Title</th>
  17. <th>Email</th>
  18. <th>Role</th>
  19. <th class="w-1"></th>
  20. </tr>
  21. </thead>
  22. <tbody>
  23. <tr>
  24. <td>Paweł Kuna</td>
  25. <td class="text-secondary">UI Designer, Training</td>
  26. <td class="text-secondary">
  27. <a href="#" class="text-reset">paweluna@howstuffworks.com</a>
  28. </td>
  29. <td class="text-secondary">User</td>
  30. <td>
  31. <a href="#">Edit</a>
  32. </td>
  33. </tr>
  34. <tr>
  35. <td>Jeffie Lewzey</td>
  36. <td class="text-secondary">Chemical Engineer, Support</td>
  37. <td class="text-secondary">
  38. <a href="#" class="text-reset">jlewzey1@seesaa.net</a>
  39. </td>
  40. <td class="text-secondary">Admin</td>
  41. <td>
  42. <a href="#">Edit</a>
  43. </td>
  44. </tr>
  45. <tr>
  46. <td>Mallory Hulme</td>
  47. <td class="text-secondary">Geologist IV, Support</td>
  48. <td class="text-secondary">
  49. <a href="#" class="text-reset">mhulme2@domainmarket.com</a>
  50. </td>
  51. <td class="text-secondary">User</td>
  52. <td>
  53. <a href="#">Edit</a>
  54. </td>
  55. </tr>
  56. <tr>
  57. <td>Dunn Slane</td>
  58. <td class="text-secondary">Research Nurse, Sales</td>
  59. <td class="text-secondary">
  60. <a href="#" class="text-reset">dslane3@epa.gov</a>
  61. </td>
  62. <td class="text-secondary">Owner</td>
  63. <td>
  64. <a href="#">Edit</a>
  65. </td>
  66. </tr>
  67. <tr>
  68. <td>Emmy Levet</td>
  69. <td class="text-secondary">VP Product Management, Accounting</td>
  70. <td class="text-secondary">
  71. <a href="#" class="text-reset">elevet4@senate.gov</a>
  72. </td>
  73. <td class="text-secondary">Admin</td>
  74. <td>
  75. <a href="#">Edit</a>
  76. </td>
  77. </tr>
  78. </tbody>
  79. </table>
  80. </div>
  81. ```
  82. ## Responsive tables
  83. Use the `.table-responsive` class across each breakpoint for horizontal scrolling tables. If you want to create responsive tables up to a specific breakpoint, use `.table-responsive{-sm|-md|-lg|-xl}`. From that breakpoint and up, the table will behave normally, rather than scroll horizontally.
  84. ```html example height="12rem"
  85. <table class="table table-responsive">
  86. <thead>
  87. <tr>
  88. <th>#</th>
  89. <th class="text-nowrap">Heading 1</th>
  90. <th class="text-nowrap">Heading 2</th>
  91. <th class="text-nowrap">Heading 3</th>
  92. <th class="text-nowrap">Heading 4</th>
  93. <th class="text-nowrap">Heading 5</th>
  94. <th class="text-nowrap">Heading 6</th>
  95. <th class="text-nowrap">Heading 7</th>
  96. <th class="text-nowrap">Heading 8</th>
  97. <th class="text-nowrap">Heading 9</th>
  98. <th class="text-nowrap">Heading 10</th>
  99. </tr>
  100. </thead>
  101. <tbody>
  102. <tr>
  103. <th>1</th>
  104. <td>Cell</td>
  105. <td>Cell</td>
  106. <td>Cell</td>
  107. <td>Cell</td>
  108. <td>Cell</td>
  109. <td>Cell</td>
  110. <td>Cell</td>
  111. <td>Cell</td>
  112. <td>Cell</td>
  113. <td>Cell</td>
  114. </tr>
  115. <tr>
  116. <th>2</th>
  117. <td>Cell</td>
  118. <td>Cell</td>
  119. <td>Cell</td>
  120. <td>Cell</td>
  121. <td>Cell</td>
  122. <td>Cell</td>
  123. <td>Cell</td>
  124. <td>Cell</td>
  125. <td>Cell</td>
  126. <td>Cell</td>
  127. </tr>
  128. </tbody>
  129. </table>
  130. ```
  131. ## No wrap
  132. If you don't want the table cell content to wrap to another line, use the `table-nowrap` class.
  133. ```html example height="10rem"
  134. <div class="table-responsive">
  135. <table class="table table-vcenter table-nowrap">
  136. <thead>
  137. <tr>
  138. <th>Name</th>
  139. <th>Title</th>
  140. <th>Email</th>
  141. <th>Role</th>
  142. <th></th>
  143. <th class="w-1"></th>
  144. </tr>
  145. </thead>
  146. <tbody>
  147. <tr>
  148. <td>Paweł Kuna</td>
  149. <td class="text-secondary">UI Designer, Training</td>
  150. <td class="text-secondary">
  151. <a href="#" class="text-reset">paweluna@howstuffworks.com</a>
  152. </td>
  153. <td class="text-secondary">User</td>
  154. <td>
  155. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi, commodi cupiditate
  156. debitis deserunt expedita hic incidunt iste modi molestiae nesciunt non nostrum
  157. perferendis perspiciatis placeat praesentium quaerat quo repellendus, voluptates.
  158. </td>
  159. <td>
  160. <a href="#">Edit</a>
  161. </td>
  162. </tr>
  163. </tbody>
  164. </table>
  165. </div>
  166. ```
  167. ```html
  168. <div class="table-responsive">
  169. <table class="table table-vcenter table-nowrap">
  170. <thead>
  171. <tr>
  172. <th>Name</th>
  173. <th>Title</th>
  174. <th>Email</th>
  175. <th>Role</th>
  176. <th></th>
  177. <th class="w-1"></th>
  178. </tr>
  179. </thead>
  180. <tbody>
  181. <tr>
  182. <td>Paweł Kuna</td>
  183. <td class="text-secondary">UI Designer, Training</td>
  184. <td class="text-secondary">
  185. <a href="#" class="text-reset">paweluna@howstuffworks.com</a>
  186. </td>
  187. <td class="text-secondary">User</td>
  188. <td>
  189. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi, commodi cupiditate
  190. debitis deserunt expedita hic incidunt iste modi molestiae nesciunt non nostrum
  191. perferendis perspiciatis placeat praesentium quaerat quo repellendus, voluptates.
  192. </td>
  193. <td>
  194. <a href="#">Edit</a>
  195. </td>
  196. </tr>
  197. <tr>
  198. <td>Jeffie Lewzey</td>
  199. <td class="text-secondary">Chemical Engineer, Support</td>
  200. <td class="text-secondary">
  201. <a href="#" class="text-reset">jlewzey1@seesaa.net</a>
  202. </td>
  203. <td class="text-secondary">Admin</td>
  204. <td>
  205. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi, commodi cupiditate
  206. debitis deserunt expedita hic incidunt iste modi molestiae nesciunt non nostrum
  207. perferendis perspiciatis placeat praesentium quaerat quo repellendus, voluptates.
  208. </td>
  209. <td>
  210. <a href="#">Edit</a>
  211. </td>
  212. </tr>
  213. <tr>
  214. <td>Mallory Hulme</td>
  215. <td class="text-secondary">Geologist IV, Support</td>
  216. <td class="text-secondary">
  217. <a href="#" class="text-reset">mhulme2@domainmarket.com</a>
  218. </td>
  219. <td class="text-secondary">User</td>
  220. <td>
  221. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi, commodi cupiditate
  222. debitis deserunt expedita hic incidunt iste modi molestiae nesciunt non nostrum
  223. perferendis perspiciatis placeat praesentium quaerat quo repellendus, voluptates.
  224. </td>
  225. <td>
  226. <a href="#">Edit</a>
  227. </td>
  228. </tr>
  229. <tr>
  230. <td>Dunn Slane</td>
  231. <td class="text-secondary">Research Nurse, Sales</td>
  232. <td class="text-secondary">
  233. <a href="#" class="text-reset">dslane3@epa.gov</a>
  234. </td>
  235. <td class="text-secondary">Owner</td>
  236. <td>
  237. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi, commodi cupiditate
  238. debitis deserunt expedita hic incidunt iste modi molestiae nesciunt non nostrum
  239. perferendis perspiciatis placeat praesentium quaerat quo repellendus, voluptates.
  240. </td>
  241. <td>
  242. <a href="#">Edit</a>
  243. </td>
  244. </tr>
  245. <tr>
  246. <td>Emmy Levet</td>
  247. <td class="text-secondary">VP Product Management, Accounting</td>
  248. <td class="text-secondary">
  249. <a href="#" class="text-reset">elevet4@senate.gov</a>
  250. </td>
  251. <td class="text-secondary">Admin</td>
  252. <td>
  253. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi, commodi cupiditate
  254. debitis deserunt expedita hic incidunt iste modi molestiae nesciunt non nostrum
  255. perferendis perspiciatis placeat praesentium quaerat quo repellendus, voluptates.
  256. </td>
  257. <td>
  258. <a href="#">Edit</a>
  259. </td>
  260. </tr>
  261. </tbody>
  262. </table>
  263. </div>
  264. ```
  265. ## Table Variants
  266. ```html example height="360px" scrollable
  267. <table class="table">
  268. <thead>
  269. <tr>
  270. <th scope="col">Class</th>
  271. <th scope="col">Heading</th>
  272. <th scope="col">Heading</th>
  273. </tr>
  274. </thead>
  275. <tbody>
  276. <tr>
  277. <th scope="row">Default</th>
  278. <td>Cell</td>
  279. <td>Cell</td>
  280. </tr>
  281. <tr class="table-primary">
  282. <th scope="row">Primary</th>
  283. <td>Cell</td>
  284. <td>Cell</td>
  285. </tr>
  286. <tr class="table-secondary">
  287. <th scope="row">Secondary</th>
  288. <td>Cell</td>
  289. <td>Cell</td>
  290. </tr>
  291. <tr class="table-success">
  292. <th scope="row">Success</th>
  293. <td>Cell</td>
  294. <td>Cell</td>
  295. </tr>
  296. <tr class="table-danger">
  297. <th scope="row">Danger</th>
  298. <td>Cell</td>
  299. <td>Cell</td>
  300. </tr>
  301. <tr class="table-warning">
  302. <th scope="row">Warning</th>
  303. <td>Cell</td>
  304. <td>Cell</td>
  305. </tr>
  306. <tr class="table-info">
  307. <th scope="row">Info</th>
  308. <td>Cell</td>
  309. <td>Cell</td>
  310. </tr>
  311. <tr class="table-light">
  312. <th scope="row">Light</th>
  313. <td>Cell</td>
  314. <td>Cell</td>
  315. </tr>
  316. <tr class="table-dark">
  317. <th scope="row">Dark</th>
  318. <td>Cell</td>
  319. <td>Cell</td>
  320. </tr>
  321. </tbody>
  322. </table>
  323. ```
  324. ## Table with sticky header
  325. ```html example scrollable
  326. <table class="table">
  327. <thead class="sticky-top">
  328. <tr>
  329. <th scope="col">Class</th>
  330. <th scope="col">Heading</th>
  331. <th scope="col">Heading</th>
  332. </tr>
  333. </thead>
  334. <tbody>
  335. <tr>
  336. <th scope="row">Default</th>
  337. <td>Cell</td>
  338. <td>Cell</td>
  339. </tr>
  340. <tr>
  341. <th scope="row">Primary</th>
  342. <td>Cell</td>
  343. <td>Cell</td>
  344. </tr>
  345. <tr>
  346. <th scope="row">Secondary</th>
  347. <td>Cell</td>
  348. <td>Cell</td>
  349. </tr>
  350. <tr>
  351. <th scope="row">Success</th>
  352. <td>Cell</td>
  353. <td>Cell</td>
  354. </tr>
  355. <tr>
  356. <th scope="row">Danger</th>
  357. <td>Cell</td>
  358. <td>Cell</td>
  359. </tr>
  360. <tr>
  361. <th scope="row">Warning</th>
  362. <td>Cell</td>
  363. <td>Cell</td>
  364. </tr>
  365. <tr>
  366. <th scope="row">Info</th>
  367. <td>Cell</td>
  368. <td>Cell</td>
  369. </tr>
  370. <tr>
  371. <th scope="row">Light</th>
  372. <td>Cell</td>
  373. <td>Cell</td>
  374. </tr>
  375. <tr class="table-dark">
  376. <th scope="row">Dark</th>
  377. <td>Cell</td>
  378. <td>Cell</td>
  379. </tr>
  380. </tbody>
  381. </table>
  382. ```