tables.md 13 KB
Newer Older
Mark Otto's avatar
Mark Otto committed
1
2
3
4
5
---
layout: page
title: Tables
---

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

Mark Otto's avatar
Mark Otto committed
8
9
10
11
12
## Contents

* Will be replaced with the ToC, excluding the "Contents" header
{:toc}

Mark Otto's avatar
Mark Otto committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
## Basic example

{% example html %}
<table class="table">
  <thead>
    <tr>
      <th>#</th>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Username</th>
    </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
46
47
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
{% endexample %}

Mark Otto's avatar
Mark Otto committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
## Inverse table

{% example html %}
<table class="table table-inverse">
  <thead>
    <tr>
      <th>#</th>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Username</th>
    </tr>
  </thead>
  <tbody>
    <tr>
Mark Otto's avatar
Mark Otto committed
62
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
63
64
65
66
67
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
68
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
69
70
71
72
73
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
74
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
75
76
77
78
79
80
81
82
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
{% endexample %}

Mark Otto's avatar
Mark Otto committed
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
## Table head options

Use one of two modifier classes to make `<thead>`s appear light or dark gray.

{% example html %}
<table class="table">
  <thead class="thead-inverse">
    <tr>
      <th>#</th>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Username</th>
    </tr>
  </thead>
  <tbody>
    <tr>
Mark Otto's avatar
Mark Otto committed
99
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
100
101
102
103
104
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
105
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
106
107
108
109
110
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
111
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
112
113
114
115
116
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
117
118
119
</table>

<table class="table">
Mark Otto's avatar
Mark Otto committed
120
121
122
123
124
125
126
127
128
129
  <thead class="thead-default">
    <tr>
      <th>#</th>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Username</th>
    </tr>
  </thead>
  <tbody>
    <tr>
Mark Otto's avatar
Mark Otto committed
130
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
131
132
133
134
135
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
136
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
137
138
139
140
141
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
142
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
143
144
145
146
147
148
149
150
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
{% endexample %}

Mark Otto's avatar
Mark Otto committed
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
## Striped rows

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

{% example html %}
<table class="table table-striped">
  <thead>
    <tr>
      <th>#</th>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Username</th>
    </tr>
  </thead>
  <tbody>
    <tr>
Mark Otto's avatar
Mark Otto committed
167
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
168
169
170
171
172
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
173
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
174
175
176
177
178
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
179
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
{% endexample %}

## Bordered table

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

{% example html %}
<table class="table table-bordered">
  <thead>
    <tr>
      <th>#</th>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Username</th>
    </tr>
  </thead>
  <tbody>
    <tr>
204
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
205
206
207
208
209
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
210
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
211
212
213
214
215
      <td>Mark</td>
      <td>Otto</td>
      <td>@TwBootstrap</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
216
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
217
218
219
220
221
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
222
      <th scope="row">4</th>
Mark Otto's avatar
Mark Otto committed
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
      <td colspan="2">Larry the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
{% endexample %}

## Hoverable rows

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

{% example html %}
<table class="table table-hover">
  <thead>
    <tr>
      <th>#</th>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Username</th>
    </tr>
  </thead>
  <tbody>
    <tr>
Mark Otto's avatar
Mark Otto committed
246
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
247
248
249
250
251
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
252
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
253
254
255
256
257
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
258
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
259
260
261
262
263
264
265
      <td colspan="2">Larry the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
{% endexample %}

266
## Small table
Mark Otto's avatar
Mark Otto committed
267

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

{% example html %}
271
<table class="table table-sm">
Mark Otto's avatar
Mark Otto committed
272
273
274
275
276
277
278
279
280
281
  <thead>
    <tr>
      <th>#</th>
      <th>First Name</th>
      <th>Last Name</th>
      <th>Username</th>
    </tr>
  </thead>
  <tbody>
    <tr>
Mark Otto's avatar
Mark Otto committed
282
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
283
284
285
286
287
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
288
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
289
290
291
292
293
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
294
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
      <td colspan="2">Larry the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
{% endexample %}

## Contextual classes

Use contextual classes to color table rows or individual cells.

<div class="table-responsive">
  <table class="table table-bordered table-striped">
    <colgroup>
      <col class="col-xs-1">
      <col class="col-xs-7">
    </colgroup>
    <thead>
      <tr>
        <th>Class</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
Mark Otto's avatar
Mark Otto committed
320
        <th scope="row">
321
          <code>.table-active</code>
Mark Otto's avatar
Mark Otto committed
322
        </th>
Mark Otto's avatar
Mark Otto committed
323
324
325
        <td>Applies the hover color to a particular row or cell</td>
      </tr>
      <tr>
Mark Otto's avatar
Mark Otto committed
326
        <th scope="row">
327
          <code>.table-success</code>
Mark Otto's avatar
Mark Otto committed
328
        </th>
Mark Otto's avatar
Mark Otto committed
329
330
331
        <td>Indicates a successful or positive action</td>
      </tr>
      <tr>
Mark Otto's avatar
Mark Otto committed
332
        <th scope="row">
333
          <code>.table-info</code>
Mark Otto's avatar
Mark Otto committed
334
        </th>
Mark Otto's avatar
Mark Otto committed
335
336
337
        <td>Indicates a neutral informative change or action</td>
      </tr>
      <tr>
Mark Otto's avatar
Mark Otto committed
338
        <th scope="row">
339
          <code>.table-warning</code>
Mark Otto's avatar
Mark Otto committed
340
        </th>
Mark Otto's avatar
Mark Otto committed
341
342
343
        <td>Indicates a warning that might need attention</td>
      </tr>
      <tr>
Mark Otto's avatar
Mark Otto committed
344
        <th scope="row">
345
          <code>.table-danger</code>
Mark Otto's avatar
Mark Otto committed
346
        </th>
Mark Otto's avatar
Mark Otto committed
347
348
349
350
351
352
        <td>Indicates a dangerous or potentially negative action</td>
      </tr>
    </tbody>
  </table>
</div>

353
<div class="bd-example">
Mark Otto's avatar
Mark Otto committed
354
355
356
357
358
359
360
361
362
363
  <table class="table">
    <thead>
      <tr>
        <th>#</th>
        <th>Column heading</th>
        <th>Column heading</th>
        <th>Column heading</th>
      </tr>
    </thead>
    <tbody>
364
      <tr class="table-active">
Mark Otto's avatar
Mark Otto committed
365
        <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
366
367
368
369
370
        <td>Column content</td>
        <td>Column content</td>
        <td>Column content</td>
      </tr>
      <tr>
Mark Otto's avatar
Mark Otto committed
371
        <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
372
373
374
375
        <td>Column content</td>
        <td>Column content</td>
        <td>Column content</td>
      </tr>
376
      <tr class="table-success">
Mark Otto's avatar
Mark Otto committed
377
        <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
378
379
380
381
382
        <td>Column content</td>
        <td>Column content</td>
        <td>Column content</td>
      </tr>
      <tr>
Mark Otto's avatar
Mark Otto committed
383
        <th scope="row">4</th>
Mark Otto's avatar
Mark Otto committed
384
385
386
387
        <td>Column content</td>
        <td>Column content</td>
        <td>Column content</td>
      </tr>
388
      <tr class="table-info">
Mark Otto's avatar
Mark Otto committed
389
        <th scope="row">5</th>
Mark Otto's avatar
Mark Otto committed
390
391
392
393
394
        <td>Column content</td>
        <td>Column content</td>
        <td>Column content</td>
      </tr>
      <tr>
Mark Otto's avatar
Mark Otto committed
395
        <th scope="row">6</th>
Mark Otto's avatar
Mark Otto committed
396
397
398
399
        <td>Column content</td>
        <td>Column content</td>
        <td>Column content</td>
      </tr>
400
      <tr class="table-warning">
Mark Otto's avatar
Mark Otto committed
401
        <th scope="row">7</th>
Mark Otto's avatar
Mark Otto committed
402
403
404
405
406
        <td>Column content</td>
        <td>Column content</td>
        <td>Column content</td>
      </tr>
      <tr>
Mark Otto's avatar
Mark Otto committed
407
        <th scope="row">8</th>
Mark Otto's avatar
Mark Otto committed
408
409
410
411
        <td>Column content</td>
        <td>Column content</td>
        <td>Column content</td>
      </tr>
412
      <tr class="table-danger">
Mark Otto's avatar
Mark Otto committed
413
        <th scope="row">9</th>
Mark Otto's avatar
Mark Otto committed
414
415
416
417
418
419
420
421
422
423
        <td>Column content</td>
        <td>Column content</td>
        <td>Column content</td>
      </tr>
    </tbody>
  </table>
</div>

{% highlight html %}
<!-- On rows -->
424
425
426
427
428
<tr class="table-active">...</tr>
<tr class="table-success">...</tr>
<tr class="table-warning">...</tr>
<tr class="table-danger">...</tr>
<tr class="table-info">...</tr>
Mark Otto's avatar
Mark Otto committed
429
430
431

<!-- On cells (`td` or `th`) -->
<tr>
432
433
434
435
436
  <td class="table-active">...</td>
  <td class="table-success">...</td>
  <td class="table-warning">...</td>
  <td class="table-danger">...</td>
  <td class="table-info">...</td>
Mark Otto's avatar
Mark Otto committed
437
438
439
440
441
442
443
</tr>
{% endhighlight %}

## Responsive tables

Create responsive tables by wrapping any `.table` in `.table-responsive` to make them scroll horizontally on small devices (under 768px). When viewing on anything larger than 768px wide, you will not see any difference in these tables.

444
445
446
447
448
449
450
451
452
453
{% callout warning %}
#### 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.
{% endcallout %}

{% callout warning %}
#### Firefox and fieldsets

Firefox has some awkward fieldset styling involving `width` that interferes with the responsive table. This cannot be overriden without a Firefox-specific hack that we **don't** provide in Bootstrap:
Mark Otto's avatar
Mark Otto committed
454

Mark Otto's avatar
Mark Otto committed
455
456
457
458
459
{% highlight css %}
@-moz-document url-prefix() {
  fieldset { display: table-cell; }
}
{% endhighlight %}
460
461
462

For more information, read [this Stack Overflow answer](http://stackoverflow.com/questions/17408815/fieldset-resizes-wrong-appears-to-have-unremovable-min-width-min-content/17863685#17863685).
{% endcallout %}
Mark Otto's avatar
Mark Otto committed
463

464
<div class="bd-example">
Mark Otto's avatar
Mark Otto committed
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
  <div class="table-responsive">
    <table class="table">
      <thead>
        <tr>
          <th>#</th>
          <th>Table heading</th>
          <th>Table heading</th>
          <th>Table heading</th>
          <th>Table heading</th>
          <th>Table heading</th>
          <th>Table heading</th>
        </tr>
      </thead>
      <tbody>
        <tr>
Mark Otto's avatar
Mark Otto committed
480
          <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
481
482
483
484
485
486
487
488
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
        </tr>
        <tr>
Mark Otto's avatar
Mark Otto committed
489
          <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
490
491
492
493
494
495
496
497
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
        </tr>
        <tr>
Mark Otto's avatar
Mark Otto committed
498
          <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
        </tr>
      </tbody>
    </table>
  </div>

  <div class="table-responsive">
    <table class="table table-bordered">
      <thead>
        <tr>
          <th>#</th>
          <th>Table heading</th>
          <th>Table heading</th>
          <th>Table heading</th>
          <th>Table heading</th>
          <th>Table heading</th>
          <th>Table heading</th>
        </tr>
      </thead>
      <tbody>
        <tr>
Mark Otto's avatar
Mark Otto committed
525
          <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
526
527
528
529
530
531
532
533
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
        </tr>
        <tr>
Mark Otto's avatar
Mark Otto committed
534
          <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
535
536
537
538
539
540
541
542
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
        </tr>
        <tr>
Mark Otto's avatar
Mark Otto committed
543
          <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
          <td>Table cell</td>
        </tr>
      </tbody>
    </table>
  </div>
</div>

{% highlight html %}
<div class="table-responsive">
  <table class="table">
    ...
  </table>
</div>
{% endhighlight %}
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581


### Reflow

{% example html %}
<table class="table table-reflow">
  <thead>
    <tr>
      <th>#</th>
      <th>Table heading</th>
      <th>Table heading</th>
      <th>Table heading</th>
      <th>Table heading</th>
      <th>Table heading</th>
      <th>Table heading</th>
    </tr>
  </thead>
  <tbody>
    <tr>
Mark Otto's avatar
Mark Otto committed
582
      <th scope="row">1</th>
583
584
585
586
587
588
589
590
      <td>Table cell</td>
      <td>Table cell</td>
      <td>Table cell</td>
      <td>Table cell</td>
      <td>Table cell</td>
      <td>Table cell</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
591
      <th scope="row">2</th>
592
593
594
595
596
597
598
599
      <td>Table cell</td>
      <td>Table cell</td>
      <td>Table cell</td>
      <td>Table cell</td>
      <td>Table cell</td>
      <td>Table cell</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
600
      <th scope="row">3</th>
601
602
603
604
605
606
607
608
609
610
      <td>Table cell</td>
      <td>Table cell</td>
      <td>Table cell</td>
      <td>Table cell</td>
      <td>Table cell</td>
      <td>Table cell</td>
    </tr>
  </tbody>
</table>
{% endexample %}