Tables

Documentation and examples for styling DITA tables with Bootstrap classes.

Overview

Due to the widespread use of <table> elements across third-party widgets like calendars and date pickers, Bootstrap’s tables are opt-in. Extend with optional modifier output classes or custom styles. All table styles are not inherited in Bootstrap, meaning any nested tables can be styled independent from the parent.

Using the most basic table markup, here’s how the default DITA Bootstrap .table-based tables look in Bootstrap.

Figure 1. Bootstrap Table
<table>
  <tgroup cols="2">
    <thead>
      <row>
        <entry>Animal</entry>
        <entry>Gestation</entry>
      </row>
    </thead>
    <tbody>
      <row>
        <entry>Elephant (African and Asian)</entry>
        <entry>19-22 months</entry>
      </row>
      <row>
        <entry>Giraffe</entry>
        <entry>15 months</entry>
      </row>
      <row>
        <entry>Rhinoceros</entry>
        <entry>14-16 months</entry>
      </row>
      <row>
        <entry>Hippopotamus</entry>
        <entry>7 1/2 months</entry>
      </row>
    </tbody>
  </tgroup>
</table>
<table>
  ...etc
</table>

Variants

Use contextual classes to color tables, table rows or individual cells.

Figure 2. Table Variants
<table color="primary" padding="1" width="100">
  <tgroup cols="2">
    <thead>
      <row>
        <entry>Animal</entry>
        <entry>Gestation</entry>
      </row>
    </thead>
    <tbody>
      <row color="info">
        <entry>Elephant (African and Asian)</entry>
        <entry>19-22 months</entry>
      </row>
      <row color="success">
        <entry>Giraffe</entry>
        <entry>15 months</entry>
      </row>
      <row>
        <entry>Rhinoceros</entry>
        <entry color="danger">14-16 months</entry>
      </row>
      <row>
        <entry>Hippopotamus</entry>
        <entry>7 1/2 months</entry>
      </row>
    </tbody>
  </tgroup>
</table>
<table outputclass="table-primary p-1 w-100">
  <tgroup cols="2">
    <thead>
      <row>
        <entry>Animal</entry>
        <entry>Gestation</entry>
      </row>
    </thead>
    <tbody>
      <row outputclass="table-info">
        <entry>Elephant (African and Asian)</entry>
        <entry>19-22 months</entry>
      </row>
      <row outputclass="table-success">
        <entry>Giraffe</entry>
        <entry>15 months</entry>
      </row>
      <row>
        <entry>Rhinoceros</entry>
        <entry outputclass="table-danger">14-16 months</entry>
      </row>
      <row>
        <entry>Hippopotamus</entry>
        <entry>7 1/2 months</entry>
      </row>
    </tbody>
  </tgroup>
</table>

Striped rows

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

Figure 3. Striped rows
<table striped="yes">
  ...etc
</table>
<table outputclass="table-striped">
  ...etc
</table>

Striped columns

Use @striped-columns="yes" to add zebra-striping to any table column within the <tbody>.

Figure 4. Striped columns
<table striped-columns="yes">
  ...etc
</table>
<table outputclass="table-striped-columns">
  ...etc
</table>

Bordered tables

Add @rowsep="1" and @colsep="1" for borders on all sides of the table and cells.

Figure 5. Bordered tables
<table rowsep="1" colsep="1">
  ...etc
</table>
<table rowsep="1" colsep="1">
  ...etc
</table>

Tables without borders

Add @rowsep="0" and @colsep="0" for a table without borders.

Figure 6. Tables without borders
<table rowsep="0" colsep="0">
  ...etc
</table>
<table rowsep="0" colsep="0">
  ...etc
</table>

Table group dividers

Add a thicker border, darker between table groups—<thead> and <tbody>, with @divider="yes" on the table.

Figure 7. Table group dividers
<table divider="yes">
  ...
  <tbody>
  ...etc
  </tbody>
</table>
<tbody outputclass="table-group-divider">
  ...etc
</tbody>

Vertical alignment

Table cells of <thead> are always vertical aligned to the bottom. Table cells in <tbody> inherit their alignment from <table> and are aligned to the top by default. Use the @valign attribute to re-align where needed.

Figure 8. Vertical alignment
<table outputclass="align-middle">
  <tgroup cols="4">
    <thead>
      <row>
        <entry valign="top">...</entry>
        <entry valign="bottom">...</entry>
        <entry valign="middle">...</entry>
        <entry>...</entry>
      </row>
    </thead>
    <tbody>
      <row>
        ...
      </row>
      <row valign="bottom">
        ...
      </row>
      <row>
        <entry>...</entry>
        <entry>...</entry>
        <entry valign="top">...</entry>
        <entry>...</entry>
      </row>
    </tbody>
  </tgroup>
</table>
<table outputclass="align-middle">
  <tgroup cols="4">
    <thead>
      <row>
        <entry valign="top">...</entry>
        <entry valign="bottom">...</entry>
        <entry valign="middle">...</entry>
        <entry>...</entry>
      </row>
    </thead>
    <tbody>
      <row>
        ...
      </row>
      <row valign="bottom">
        ...
      </row>
      <row>
        <entry>...</entry>
        <entry>...</entry>
        <entry valign="top">...</entry>
        <entry>...</entry>
      </row>
    </tbody>
  </tgroup>
</table>

Table head

Similar to tables and dark tables, use the modifier @color="light" or @color="dark" to make <thead> elements appear light or dark gray.

Figure 9. Table head 1
<table>
  <tgroup>
    <thead color="light">
      ...etc
    </thead>
  </tgroup>
</table>
<table>
  <tgroup>
    <thead outputclass="table-light">
      ...etc
    </thead>
  </tgroup>
</table>
Figure 10. Table head 2
<table>
  <tgroup>
    <thead color="dark">
      ...etc
    </thead>
  </tgroup>
</table>
<table>
  <tgroup>
    <thead outputclass="table-dark">
      ...etc
    </thead>
  </tgroup>
</table>