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
8
9
10
11
12
13
14
15
16
17
18
19
20
21

## 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
22
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
23
24
25
26
27
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
28
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
29
30
31
32
33
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
34
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
35
36
37
38
39
40
41
42
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
{% endexample %}

Mark Otto's avatar
Mark Otto committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
## 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
57
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
58
59
60
61
62
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
63
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
64
65
66
67
68
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
69
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
70
71
72
73
74
75
76
77
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
{% endexample %}

Mark Otto's avatar
Mark Otto committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
## 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
94
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
95
96
97
98
99
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
100
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
101
102
103
104
105
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
106
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
  <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
122
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
123
124
125
126
127
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
128
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
129
130
131
132
133
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
134
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
135
136
137
138
139
140
141
142
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
{% endexample %}

Mark Otto's avatar
Mark Otto committed
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
## 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
159
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
160
161
162
163
164
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
165
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
166
167
168
169
170
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
171
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
      <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>
196
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
197
198
199
200
201
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
202
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
203
204
205
206
207
      <td>Mark</td>
      <td>Otto</td>
      <td>@TwBootstrap</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
208
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
209
210
211
212
213
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
214
      <th scope="row">4</th>
Mark Otto's avatar
Mark Otto committed
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
      <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
238
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
239
240
241
242
243
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
244
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
245
246
247
248
249
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
250
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
251
252
253
254
255
256
257
      <td colspan="2">Larry the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>
{% endexample %}

258
## Small table
Mark Otto's avatar
Mark Otto committed
259

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

{% example html %}
263
<table class="table table-sm">
Mark Otto's avatar
Mark Otto committed
264
265
266
267
268
269
270
271
272
273
  <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
274
      <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
275
276
277
278
279
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
280
      <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
281
282
283
284
285
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
Mark Otto's avatar
Mark Otto committed
286
      <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
      <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
312
        <th scope="row">
313
          <code>.table-active</code>
Mark Otto's avatar
Mark Otto committed
314
        </th>
Mark Otto's avatar
Mark Otto committed
315
316
317
        <td>Applies the hover color to a particular row or cell</td>
      </tr>
      <tr>
Mark Otto's avatar
Mark Otto committed
318
        <th scope="row">
319
          <code>.table-success</code>
Mark Otto's avatar
Mark Otto committed
320
        </th>
Mark Otto's avatar
Mark Otto committed
321
322
323
        <td>Indicates a successful or positive action</td>
      </tr>
      <tr>
Mark Otto's avatar
Mark Otto committed
324
        <th scope="row">
325
          <code>.table-info</code>
Mark Otto's avatar
Mark Otto committed
326
        </th>
Mark Otto's avatar
Mark Otto committed
327
328
329
        <td>Indicates a neutral informative change or action</td>
      </tr>
      <tr>
Mark Otto's avatar
Mark Otto committed
330
        <th scope="row">
331
          <code>.table-warning</code>
Mark Otto's avatar
Mark Otto committed
332
        </th>
Mark Otto's avatar
Mark Otto committed
333
334
335
        <td>Indicates a warning that might need attention</td>
      </tr>
      <tr>
Mark Otto's avatar
Mark Otto committed
336
        <th scope="row">
337
          <code>.table-danger</code>
Mark Otto's avatar
Mark Otto committed
338
        </th>
Mark Otto's avatar
Mark Otto committed
339
340
341
342
343
344
        <td>Indicates a dangerous or potentially negative action</td>
      </tr>
    </tbody>
  </table>
</div>

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

{% highlight html %}
<!-- On rows -->
416
417
418
419
420
<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
421
422
423

<!-- On cells (`td` or `th`) -->
<tr>
424
425
426
427
428
  <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
429
430
431
432
433
434
435
</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.

436
<div class="bd-callout bd-callout-warning" id="callout-tables-responsive-overflow">
Mark Otto's avatar
Mark Otto committed
437
438
439
440
  <h4>Vertical clipping/truncation</h4>
  <p>Responsive tables make use of <code>overflow-y: hidden</code>, 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.</p>
</div>

441
<div class="bd-callout bd-callout-warning">
Mark Otto's avatar
Mark Otto committed
442
443
444
445
446
447
448
449
450
451
  <h4>Firefox and fieldsets</h4>
  <p>Firefox has some awkward fieldset styling involving <code>width</code> that interferes with the responsive table. This cannot be overriden without a Firefox-specific hack that we <strong>don't</strong> provide in Bootstrap:</p>
{% highlight css %}
@-moz-document url-prefix() {
  fieldset { display: table-cell; }
}
{% endhighlight %}
  <p>For more information, read <a href="http://stackoverflow.com/questions/17408815/fieldset-resizes-wrong-appears-to-have-unremovable-min-width-min-content/17863685#17863685">this Stack Overflow answer</a>.</p>
</div>

452
<div class="bd-example">
Mark Otto's avatar
Mark Otto committed
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
  <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
468
          <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
469
470
471
472
473
474
475
476
          <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
477
          <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
478
479
480
481
482
483
484
485
          <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
486
          <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
          <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
513
          <th scope="row">1</th>
Mark Otto's avatar
Mark Otto committed
514
515
516
517
518
519
520
521
          <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
522
          <th scope="row">2</th>
Mark Otto's avatar
Mark Otto committed
523
524
525
526
527
528
529
530
          <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
531
          <th scope="row">3</th>
Mark Otto's avatar
Mark Otto committed
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
          <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 %}
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569


### 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
570
      <th scope="row">1</th>
571
572
573
574
575
576
577
578
      <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
579
      <th scope="row">2</th>
580
581
582
583
584
585
586
587
      <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
588
      <th scope="row">3</th>
589
590
591
592
593
594
595
596
597
598
      <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 %}