Table (table)

A table shows information in columns and rows.

đź”— External documentation.

ID Label Description Schema
header Header Drupal expects an array of cells for the header. See template_preprocess_table in core > includes > theme.inc for more information.
colgroups Colgroups Sticked to Drupal structure after preprocessing of the Drupal table element.
rows Rows For the body of the table, Drupal expects an array of rows with each row keyed with the name 'cells', which is an array values for each cell. See template_preprocess_table in core > includes > theme.inc for more information.
footer Footer Drupal expects an array of cells for the footer. See template_preprocess_table in core > includes > theme.inc for more information.
empty Empty Render element used when there is no rows.
caption Caption 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. By default it is displayed at the bottom of the table.
striped Striped A striped table can improve readability by visually grouping row content with alternating background colors.
                        type: boolean

                      
borderless Borderless A borderless table can be useful when you want the information to feel more a part of the text it accompanies and extends.
                        type: boolean

                      
scrollable Scrollable A scrollable table is ideal for dense data.
                        type: boolean

                      
stacked Responsive Stacked A responsive stacked table collapses at narrow widths for better readability on small screens.
                        type: boolean

                      
stacked_header Responsive Stacked - Header Stacks the table cells on narrow screens and visually promotes the first cell of every row into a “header” for that group. Preferred for directories and other lists where the first cell of every row is a name. If you use this variant, you must ensure there is a data-label attribute on each cell of the table that matches the column header.
                        type: boolean

                      
sortable Sortable A sorted column changes the row ordering based on alphabetical or numeric cell values. Requires a caption.
                        type: boolean

                      
compact Compact Reduces the row height and vertical spacing to display more table rows within a limited space. Should only be used with dense, numerical data, not text content. Pairs well with scrollable and striped variants, but is not suitable for use with stacked variants.
                        type: boolean

                      
header_columns Number of columns in the header Used to display properly the empty message if the table is empty. Leave empty for automatic value.
                        type: number

                      
            id: table
label: Table
description: 'A table shows information in columns and rows.'
group: Other
homepage: 'https://designsystem.digital.gov/components/table/'
slots:
    header:
        id: header
        label: Header
        description: 'Drupal expects an array of cells for the header. See template_preprocess_table in core > includes > theme.inc for more information.'
    colgroups:
        id: colgroups
        label: Colgroups
        description: 'Sticked to Drupal structure after preprocessing of the Drupal table element.'
    rows:
        id: rows
        label: Rows
        description: "For the body of the table, Drupal expects an array of rows with each row keyed with the name 'cells', which is an array values for each cell. See template_preprocess_table in core > includes > theme.inc for more information."
    footer:
        id: footer
        label: Footer
        description: 'Drupal expects an array of cells for the footer. See template_preprocess_table in core > includes > theme.inc for more information.'
    empty:
        id: empty
        label: Empty
        description: 'Render element used when there is no rows.'
    caption:
        id: caption
        label: Caption
        description: "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. By default it is displayed at the bottom of the table."
props:
    striped:
        id: striped
        label: Striped
        description: 'A striped table can improve readability by visually grouping row content with alternating background colors.'
        schema:
            type: boolean
    borderless:
        id: borderless
        label: Borderless
        description: 'A borderless table can be useful when you want the information to feel more a part of the text it accompanies and extends.'
        schema:
            type: boolean
    scrollable:
        id: scrollable
        label: Scrollable
        description: 'A scrollable table is ideal for dense data.'
        schema:
            type: boolean
    stacked:
        id: stacked
        label: 'Responsive Stacked'
        description: 'A responsive stacked table collapses at narrow widths for better readability on small screens.'
        schema:
            type: boolean
    stacked_header:
        id: stacked_header
        label: 'Responsive Stacked - Header'
        description: 'Stacks the table cells on narrow screens and visually promotes the first cell of every row into a “header” for that group. Preferred for directories and other lists where the first cell of every row is a name. If you use this variant, you must ensure there is a data-label attribute on each cell of the table that matches the column header.'
        schema:
            type: boolean
    sortable:
        id: sortable
        label: Sortable
        description: 'A sorted column changes the row ordering based on alphabetical or numeric cell values. Requires a caption.'
        schema:
            type: boolean
    compact:
        id: compact
        label: Compact
        description: 'Reduces the row height and vertical spacing to display more table rows within a limited space. Should only be used with dense, numerical data, not text content. Pairs well with scrollable and striped variants, but is not suitable for use with stacked variants.'
        schema:
            type: boolean
    header_columns:
        id: header_columns
        label: 'Number of columns in the header'
        description: 'Used to display properly the empty message if the table is empty. Leave empty for automatic value.'
        schema:
            type: number
examples:
    preview:
        id: preview
        label: Preview
        renderable:
            '@component': table
            header:
                -
                    content: 'Table head A'
                -
                    content: 'Table head B'
                -
                    content: 'Table head C'
                -
                    content: 'Table head D'
                -
                    content: 'Table head E'
                -
                    content: 'Table head F'
                -
                    content: 'Table head G'
                -
                    content: 'Table head H'
            rows:
                -
                    cells:
                        -
                            content: 'Cell A1'
                        -
                            content: 'Cell A2'
                        -
                            content: 'Cell A3'
                        -
                            content: 'Cell A4'
                        -
                            content: 'Cell A5'
                        -
                            content: 'Cell A6'
                        -
                            content: 'Cell A7'
                        -
                            content: 'Cell A8'
                -
                    cells:
                        -
                            content: 'Cell B1'
                        -
                            content: 'Cell B2'
                        -
                            content: 'Cell B3'
                        -
                            content: 'Cell B4'
                        -
                            content: 'Cell B5'
                        -
                            content: 'Cell B6'
                        -
                            content: 'Cell B7'
                        -
                            content: 'Cell B8'
                -
                    cells:
                        -
                            content: 'Cell C1'
                        -
                            content: 'Cell C2'
                        -
                            content: 'Cell C3'
                        -
                            content: 'Cell C4'
                        -
                            content: 'Cell C5'
                        -
                            content: 'Cell C6'
                        -
                            content: 'Cell C7'
                        -
                            content: 'Cell C8'
                -
                    cells:
                        -
                            content: 'Cell D1'
                        -
                            content: 'Cell D2'
                        -
                            content: 'Cell D3'
                        -
                            content: 'Cell D4'
                        -
                            content: 'Cell D5'
                        -
                            content: 'Cell D6'
                        -
                            content: 'Cell D7'
                        -
                            content: 'Cell D8'
            footer:
                -
                    cells:
                        -
                            content: Footer
                        -
                            content: Footer
                        -
                            content: Footer
                        -
                            content: Footer
                        -
                            content: Footer
                        -
                            content: Footer
                        -
                            content: Footer
                        -
                            content: Footer
            caption: 'Example table (caption)'
            striped: true
            scrollable: true
            stacked: true
            sortable: true

          
Example table (caption)
Table head A Table head B Table head C Table head D Table head E Table head F Table head G Table head H
Cell A1 Cell A2 Cell A3 Cell A4 Cell A5 Cell A6 Cell A7 Cell A8
Cell B1 Cell B2 Cell B3 Cell B4 Cell B5 Cell B6 Cell B7 Cell B8
Cell C1 Cell C2 Cell C3 Cell C4 Cell C5 Cell C6 Cell C7 Cell C8
Cell D1 Cell D2 Cell D3 Cell D4 Cell D5 Cell D6 Cell D7 Cell D8
Footer Footer Footer Footer Footer Footer Footer Footer
<div class="usa-table-container--scrollable" tabindex="0"> <table class="usa-table usa-table--striped usa-table--stacked usa-table--sortable"> <caption>Example table (caption)</caption> <thead > <tr> <th data-sortable="true" scope="col"> Table head A</th> <th data-sortable="true" scope="col"> Table head B</th> <th data-sortable="true" scope="col"> Table head C</th> <th data-sortable="true" scope="col"> Table head D</th> <th data-sortable="true" scope="col"> Table head E</th> <th data-sortable="true" scope="col"> Table head F</th> <th data-sortable="true" scope="col"> Table head G</th> <th data-sortable="true" scope="col"> Table head H</th> </tr> </thead> <tbody > <tr > <td>Cell A1</td> <td>Cell A2</td> <td>Cell A3</td> <td>Cell A4</td> <td>Cell A5</td> <td>Cell A6</td> <td>Cell A7</td> <td>Cell A8</td> </tr> <tr > <td>Cell B1</td> <td>Cell B2</td> <td>Cell B3</td> <td>Cell B4</td> <td>Cell B5</td> <td>Cell B6</td> <td>Cell B7</td> <td>Cell B8</td> </tr> <tr > <td>Cell C1</td> <td>Cell C2</td> <td>Cell C3</td> <td>Cell C4</td> <td>Cell C5</td> <td>Cell C6</td> <td>Cell C7</td> <td>Cell C8</td> </tr> <tr > <td>Cell D1</td> <td>Cell D2</td> <td>Cell D3</td> <td>Cell D4</td> <td>Cell D5</td> <td>Cell D6</td> <td>Cell D7</td> <td>Cell D8</td> </tr> </tbody> <tfoot > <tr > <td>Footer</td> <td>Footer</td> <td>Footer</td> <td>Footer</td> <td>Footer</td> <td>Footer</td> <td>Footer</td> <td>Footer</td> </tr> </tfoot> </table> <div class="usa-sr-only usa-table__announcement-region" aria-live="polite"></div> </div>