tables.md 18.4 KB
Newer Older
Mark Otto's avatar
Mark Otto committed
1
---
Mark Otto's avatar
Mark Otto committed
2
layout: docs
Mark Otto's avatar
Mark Otto committed
3
title: Tables
4
description: Documentation and examples for opt-in styling of tables (given their prevalent use in JavaScript plugins) with Bootstrap.
Mark Otto's avatar
Mark Otto committed
5
group: content
Mark Otto's avatar
Mark Otto committed
6
toc: true
Mark Otto's avatar
Mark Otto committed
7
8
---

Mark Otto's avatar
Mark Otto committed
9
10
## Examples

Mark Otto's avatar
Mark Otto committed
11
12
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.

13
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.
Mark Otto's avatar
Mark Otto committed
14

m5o's avatar
m5o committed
15
{% capture example %}
Mark Otto's avatar
Mark Otto committed
16
17
18
<table class="table">
  <thead>
    <tr>
19
      <th scope="col">#</th>
20
21
22
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
Mark Otto's avatar
Mark Otto committed
23
24
25
26
    </tr>
  </thead>
  <tbody>
    <tr>
Mark Otto's avatar
Mark Otto committed
27
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
28
29
30
31
32
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
33
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
34
35
36
37
38
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
39
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
40
41
42
43
44
45
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
m5o's avatar
m5o committed
46
47
{% endcapture %}
{% include example.html content=example %}
Mark Otto's avatar
Mark Otto committed
48

49
You can also invert the colors—with light text on dark backgrounds—with `.table-dark`.
Mark Otto's avatar
Mark Otto committed
50

m5o's avatar
m5o committed
51
{% capture example %}
52
<table class="table table-dark">
Mark Otto's avatar
Mark Otto committed
53
54
  <thead>
    <tr>
55
      <th scope="col">#</th>
56
57
58
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
Mark Otto's avatar
Mark Otto committed
59
60
61
62
    </tr>
  </thead>
  <tbody>
    <tr>
Mark Otto's avatar
Mark Otto committed
63
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
64
65
66
67
68
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
69
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
70
71
72
73
74
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
75
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
76
77
78
79
80
81
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
m5o's avatar
m5o committed
82
83
{% endcapture %}
{% include example.html content=example %}
Mark Otto's avatar
Mark Otto committed
84

Mark Otto's avatar
Mark Otto committed
85
86
## Table head options

87
Similar to tables and dark tables, use the modifier classes `.thead-light` or `.thead-dark` to make `<thead>`s appear light or dark gray.
Mark Otto's avatar
Mark Otto committed
88

m5o's avatar
m5o committed
89
{% capture example %}
Mark Otto's avatar
Mark Otto committed
90
<table class="table">
91
  <thead class="thead-dark">
Mark Otto's avatar
Mark Otto committed
92
    <tr>
93
      <th scope="col">#</th>
94
95
96
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
Mark Otto's avatar
Mark Otto committed
97
98
99
100
    </tr>
  </thead>
  <tbody>
    <tr>
Mark Otto's avatar
Mark Otto committed
101
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
102
103
104
105
106
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
107
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
108
109
110
111
112
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
113
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
114
115
116
117
118
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
119
120
121
</table>

<table class="table">
122
  <thead class="thead-light">
Mark Otto's avatar
Mark Otto committed
123
    <tr>
124
      <th scope="col">#</th>
125
126
127
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
Mark Otto's avatar
Mark Otto committed
128
129
130
131
    </tr>
  </thead>
  <tbody>
    <tr>
Mark Otto's avatar
Mark Otto committed
132
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
133
134
135
136
137
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
138
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
139
140
141
142
143
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
144
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
145
146
147
148
149
150
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
m5o's avatar
m5o committed
151
152
{% endcapture %}
{% include example.html content=example %}
Mark Otto's avatar
Mark Otto committed
153

Mark Otto's avatar
Mark Otto committed
154
155
156
157
## Striped rows

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

m5o's avatar
m5o committed
158
{% capture example %}
Mark Otto's avatar
Mark Otto committed
159
160
161
<table class="table table-striped">
  <thead>
    <tr>
162
      <th scope="col">#</th>
163
164
165
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
Mark Otto's avatar
Mark Otto committed
166
167
168
169
    </tr>
  </thead>
  <tbody>
    <tr>
Mark Otto's avatar
Mark Otto committed
170
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
171
172
173
174
175
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
176
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
177
178
179
180
181
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
182
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
183
184
185
186
187
188
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
m5o's avatar
m5o committed
189
190
{% endcapture %}
{% include example.html content=example %}
Mark Otto's avatar
Mark Otto committed
191

m5o's avatar
m5o committed
192
{% capture example %}
193
<table class="table table-striped table-dark">
194
195
  <thead>
    <tr>
196
      <th scope="col">#</th>
197
198
199
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
      <th scope="row">3</th>
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
m5o's avatar
m5o committed
223
224
{% endcapture %}
{% include example.html content=example %}
225

Mark Otto's avatar
Mark Otto committed
226
227
228
229
## Bordered table

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

m5o's avatar
m5o committed
230
{% capture example %}
Mark Otto's avatar
Mark Otto committed
231
232
233
<table class="table table-bordered">
  <thead>
    <tr>
234
      <th scope="col">#</th>
235
236
237
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
Mark Otto's avatar
Mark Otto committed
238
239
240
241
    </tr>
  </thead>
  <tbody>
    <tr>
242
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
243
244
245
246
247
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
248
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
249
250
251
252
253
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
254
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
255
256
257
258
259
      <td colspan="2">Larry the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
m5o's avatar
m5o committed
260
261
{% endcapture %}
{% include example.html content=example %}
Mark Otto's avatar
Mark Otto committed
262

m5o's avatar
m5o committed
263
{% capture example %}
264
<table class="table table-bordered table-dark">
265
266
  <thead>
    <tr>
267
      <th scope="col">#</th>
268
269
270
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
287
      <th scope="row">3</th>
288
289
290
291
292
      <td colspan="2">Larry the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
m5o's avatar
m5o committed
293
294
{% endcapture %}
{% include example.html content=example %}
295

296
297
298
299
## Borderless table

Add `.table-borderless` for a table without borders.

m5o's avatar
m5o committed
300
{% capture example %}
301
302
303
304
<table class="table table-borderless">
  <thead>
    <tr>
      <th scope="col">#</th>
Mark Otto's avatar
Mark Otto committed
305
306
307
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
324
      <th scope="row">3</th>
325
326
327
328
329
      <td colspan="2">Larry the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
m5o's avatar
m5o committed
330
331
{% endcapture %}
{% include example.html content=example %}
332

Mark Otto's avatar
Mark Otto committed
333
334
`.table-borderless` can also be used on dark tables.

m5o's avatar
m5o committed
335
{% capture example %}
336
337
338
339
<table class="table table-borderless table-dark">
  <thead>
    <tr>
      <th scope="col">#</th>
Mark Otto's avatar
Mark Otto committed
340
341
342
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
343
344
    </tr>
  </thead>
345
346
347
348
349
350
351
352
353
354
355
356
357
358
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
359
      <th scope="row">3</th>
360
361
362
363
364
      <td colspan="2">Larry the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
m5o's avatar
m5o committed
365
366
{% endcapture %}
{% include example.html content=example %}
367

Mark Otto's avatar
Mark Otto committed
368
369
370
371
## Hoverable rows

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

m5o's avatar
m5o committed
372
{% capture example %}
Mark Otto's avatar
Mark Otto committed
373
374
375
<table class="table table-hover">
  <thead>
    <tr>
376
      <th scope="col">#</th>
377
378
379
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
Mark Otto's avatar
Mark Otto committed
380
381
382
383
    </tr>
  </thead>
  <tbody>
    <tr>
Mark Otto's avatar
Mark Otto committed
384
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
385
386
387
388
389
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
390
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
391
392
393
394
395
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
396
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
397
398
399
400
401
      <td colspan="2">Larry the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
m5o's avatar
m5o committed
402
403
{% endcapture %}
{% include example.html content=example %}
Mark Otto's avatar
Mark Otto committed
404

m5o's avatar
m5o committed
405
{% capture example %}
406
<table class="table table-hover table-dark">
407
408
  <thead>
    <tr>
409
      <th scope="col">#</th>
410
411
412
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
      <th scope="row">3</th>
      <td colspan="2">Larry the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
m5o's avatar
m5o committed
435
436
{% endcapture %}
{% include example.html content=example %}
437

438
## Small table
Mark Otto's avatar
Mark Otto committed
439

440
Add `.table-sm` to make tables more compact by cutting cell padding in half.
Mark Otto's avatar
Mark Otto committed
441

m5o's avatar
m5o committed
442
{% capture example %}
443
<table class="table table-sm">
Mark Otto's avatar
Mark Otto committed
444
445
  <thead>
    <tr>
446
      <th scope="col">#</th>
447
448
449
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
Mark Otto's avatar
Mark Otto committed
450
451
452
453
    </tr>
  </thead>
  <tbody>
    <tr>
Mark Otto's avatar
Mark Otto committed
454
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
455
456
457
458
459
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
460
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
461
462
463
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
464
465
466
467
468
469
470
471
    </tr>
    <tr>
      <th scope="row">3</th>
      <td colspan="2">Larry the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
m5o's avatar
m5o committed
472
473
{% endcapture %}
{% include example.html content=example %}
474

m5o's avatar
m5o committed
475
{% capture example %}
476
<table class="table table-sm table-dark">
477
478
  <thead>
    <tr>
479
      <th scope="col">#</th>
480
481
482
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
483
484
485
486
487
488
489
490
491
492
493
494
495
496
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
Mark Otto's avatar
Mark Otto committed
497
498
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
499
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
500
501
502
503
504
      <td colspan="2">Larry the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
m5o's avatar
m5o committed
505
506
{% endcapture %}
{% include example.html content=example %}
Mark Otto's avatar
Mark Otto committed
507
508
509
510
511

## Contextual classes

Use contextual classes to color table rows or individual cells.

512
<div class="bd-example">
Mark Otto's avatar
Mark Otto committed
513
514
515
  <table class="table">
    <thead>
      <tr>
516
517
518
        <th scope="col">Class</th>
        <th scope="col">Heading</th>
        <th scope="col">Heading</th>
Mark Otto's avatar
Mark Otto committed
519
520
521
      </tr>
    </thead>
    <tbody>
522
      <tr class="table-active">
523
        <th scope="row">Active</th>
524
525
        <td>Cell</td>
        <td>Cell</td>
Mark Otto's avatar
Mark Otto committed
526
527
      </tr>
      <tr>
528
        <th scope="row">Default</th>
529
530
        <td>Cell</td>
        <td>Cell</td>
Mark Otto's avatar
Mark Otto committed
531
      </tr>
532
533
534
535

      {% for color in site.data.theme-colors %}
      <tr class="table-{{ color.name }}">
        <th scope="row">{{ color.name | capitalize }}</th>
536
537
        <td>Cell</td>
        <td>Cell</td>
538
      </tr>{% endfor %}
Mark Otto's avatar
Mark Otto committed
539
540
541
542
543
544
    </tbody>
  </table>
</div>

{% highlight html %}
<!-- On rows -->
545
<tr class="table-active">...</tr>
546
547
{% for color in site.data.theme-colors %}
<tr class="table-{{ color.name }}">...</tr>{% endfor %}
Mark Otto's avatar
Mark Otto committed
548
549
550

<!-- On cells (`td` or `th`) -->
<tr>
551
  <td class="table-active">...</td>
552
553
  {% for color in site.data.theme-colors %}
  <td class="table-{{ color.name }}">...</td>{% endfor %}
Mark Otto's avatar
Mark Otto committed
554
555
556
</tr>
{% endhighlight %}

557
Regular table background variants are not available with the dark table, however, you may use [text or background utilities]({{ site.baseurl }}/docs/{{ site.docs_version }}/utilities/colors/) to achieve similar styles.
Mark Otto's avatar
Mark Otto committed
558
559

<div class="bd-example">
560
  <table class="table table-dark">
Mark Otto's avatar
Mark Otto committed
561
562
    <thead>
      <tr>
563
        <th scope="col">#</th>
564
565
        <th scope="col">Heading</th>
        <th scope="col">Heading</th>
Mark Otto's avatar
Mark Otto committed
566
567
568
569
570
      </tr>
    </thead>
    <tbody>
      <tr class="bg-primary">
        <th scope="row">1</th>
571
572
        <td>Cell</td>
        <td>Cell</td>
Mark Otto's avatar
Mark Otto committed
573
574
575
      </tr>
      <tr>
        <th scope="row">2</th>
576
577
        <td>Cell</td>
        <td>Cell</td>
Mark Otto's avatar
Mark Otto committed
578
579
580
      </tr>
      <tr class="bg-success">
        <th scope="row">3</th>
581
582
        <td>Cell</td>
        <td>Cell</td>
Mark Otto's avatar
Mark Otto committed
583
584
585
      </tr>
      <tr>
        <th scope="row">4</th>
586
587
        <td>Cell</td>
        <td>Cell</td>
Mark Otto's avatar
Mark Otto committed
588
589
590
      </tr>
      <tr class="bg-info">
        <th scope="row">5</th>
591
592
        <td>Cell</td>
        <td>Cell</td>
Mark Otto's avatar
Mark Otto committed
593
594
595
      </tr>
      <tr>
        <th scope="row">6</th>
596
597
        <td>Cell</td>
        <td>Cell</td>
Mark Otto's avatar
Mark Otto committed
598
599
600
      </tr>
      <tr class="bg-warning">
        <th scope="row">7</th>
601
602
        <td>Cell</td>
        <td>Cell</td>
Mark Otto's avatar
Mark Otto committed
603
604
605
      </tr>
      <tr>
        <th scope="row">8</th>
606
607
        <td>Cell</td>
        <td>Cell</td>
Mark Otto's avatar
Mark Otto committed
608
609
610
      </tr>
      <tr class="bg-danger">
        <th scope="row">9</th>
611
612
        <td>Cell</td>
        <td>Cell</td>
Mark Otto's avatar
Mark Otto committed
613
614
615
616
617
      </tr>
    </tbody>
  </table>
</div>

Mark Otto's avatar
Mark Otto committed
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
{% highlight html %}
<!-- On rows -->
<tr class="bg-primary">...</tr>
<tr class="bg-success">...</tr>
<tr class="bg-warning">...</tr>
<tr class="bg-danger">...</tr>
<tr class="bg-info">...</tr>

<!-- On cells (`td` or `th`) -->
<tr>
  <td class="bg-primary">...</td>
  <td class="bg-success">...</td>
  <td class="bg-warning">...</td>
  <td class="bg-danger">...</td>
  <td class="bg-info">...</td>
</tr>
{% endhighlight %}

636
{% include callout-warning-color-assistive-technologies.md %}
Mark Otto's avatar
Mark Otto committed
637

638
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.
639

640
{% include callout-info-mediaqueries-breakpoints.md %}
Mark Otto's avatar
Mark Otto committed
641

642
## Captions
643

644
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.
645

m5o's avatar
m5o committed
646
{% capture example %}
647
648
649
650
651
<table class="table">
  <caption>List of users</caption>
  <thead>
    <tr>
      <th scope="col">#</th>
652
653
654
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
      <th scope="row">3</th>
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
m5o's avatar
m5o committed
678
679
{% endcapture %}
{% include example.html content=example %}
680
681
682

## Responsive tables

683
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}`.
Mark Otto's avatar
Mark Otto committed
684

685
{% capture callout %}
686
##### Vertical clipping/truncation
687
688

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.
689
690
{% endcapture %}
{% include callout.html content=callout type="warning" %}
691

692
693
### Always responsive

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

696
<div class="bd-example">
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
  <div class="table-responsive">
    <table class="table">
      <thead>
        <tr>
          <th scope="col">#</th>
          <th scope="col">Heading</th>
          <th scope="col">Heading</th>
          <th scope="col">Heading</th>
          <th scope="col">Heading</th>
          <th scope="col">Heading</th>
          <th scope="col">Heading</th>
          <th scope="col">Heading</th>
          <th scope="col">Heading</th>
          <th scope="col">Heading</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th scope="row">1</th>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
        </tr>
        <tr>
          <th scope="row">2</th>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
        </tr>
        <tr>
          <th scope="row">3</th>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
          <td>Cell</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>

{% highlight html %}
<div class="table-responsive">
  <table class="table">
    ...
759
  </table>
760
761
762
763
764
765
</div>
{% endhighlight %}

### 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.
Mark Otto's avatar
Mark Otto committed
766

Mark Otto's avatar
Mark Otto committed
767
768
**These tables may appear broken until their responsive styles apply at specific viewport widths.**

769
{% for bp in site.data.breakpoints %}{% unless bp.breakpoint == "xs" %}
Mark Otto's avatar
Mark Otto committed
770
<div class="bd-example">
771
772
<div class="table-responsive{{ bp.abbr }}">
  <table class="table">
773
774
    <thead>
      <tr>
775
        <th scope="col">#</th>
776
777
778
779
780
        <th scope="col">Heading</th>
        <th scope="col">Heading</th>
        <th scope="col">Heading</th>
        <th scope="col">Heading</th>
        <th scope="col">Heading</th>
781
782
783
        <th scope="col">Heading</th>
        <th scope="col">Heading</th>
        <th scope="col">Heading</th>
784
785
786
787
788
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">1</th>
789
790
791
792
793
        <td>Cell</td>
        <td>Cell</td>
        <td>Cell</td>
        <td>Cell</td>
        <td>Cell</td>
794
795
796
        <td>Cell</td>
        <td>Cell</td>
        <td>Cell</td>
797
798
799
      </tr>
      <tr>
        <th scope="row">2</th>
800
801
802
803
804
        <td>Cell</td>
        <td>Cell</td>
        <td>Cell</td>
        <td>Cell</td>
        <td>Cell</td>
805
806
807
        <td>Cell</td>
        <td>Cell</td>
        <td>Cell</td>
808
809
810
      </tr>
      <tr>
        <th scope="row">3</th>
811
812
813
814
815
        <td>Cell</td>
        <td>Cell</td>
        <td>Cell</td>
        <td>Cell</td>
        <td>Cell</td>
816
817
818
        <td>Cell</td>
        <td>Cell</td>
        <td>Cell</td>
819
820
      </tr>
    </tbody>
Mark Otto's avatar
Mark Otto committed
821
822
  </table>
</div>
823
824
</div>
{% highlight html %}
825
826
827
828
829
<div class="table-responsive{{ bp.abbr }}">
  <table class="table">
    ...
  </table>
</div>
830
{% endhighlight %}
Mark Otto's avatar
Mark Otto committed
831
{% endunless %}{% endfor %}