Tables

In this guide, you'll learn how to configure and create tables.

Requirements

You’ll need to upgrade Hugo to v0.134.0 or later, and enable the markup.goldmark.parser.attribute.block.

hugo.toml

1[markup]
2  [markup.goldmark]
3    [markup.goldmark.parser]
4      [markup.goldmark.parser.attribute]
5        block = true

hugo.yaml

1markup:
2  goldmark:
3    parser:
4      attribute:
5        block: true

hugo.json

 1{
 2   "markup": {
 3      "goldmark": {
 4         "parser": {
 5            "attribute": {
 6               "block": true
 7            }
 8         }
 9      }
10   }
11}

Site Parameters

align

NameContextTypeRequiredDefaultSinceExample
alignhb.tablesstring----

Vertical alignment.

Available options: top, middle, bottom.

bordered

NameContextTypeRequiredDefaultSinceExample
borderedhb.tablesboolean-true--

Whether to enable borders globally.

border_style

NameContextTypeRequiredDefaultSinceExample
border_stylehb.tablesstring----

Border style.

Available options: danger, dark, light, info, primary, secondary, success, warning.

group_divider

NameContextTypeRequiredDefaultSinceExample
group_dividerhb.tablesboolean-false--

Whether to add a thicker border, darker between table groups.

hover

NameContextTypeRequiredDefaultSinceExample
hoverhb.tablesboolean-true--

Whether to enable a hover state on tables.

striped

NameContextTypeRequiredDefaultSinceExample
stripedhb.tablesboolean-true--

Whether to add zebra-striping on table rows.

striped_columns

NameContextTypeRequiredDefaultSinceExample
striped_columnshb.tablesboolean-false--

Whether to add zebra-striping on table columns.

style

NameContextTypeRequiredDefaultSinceExample
stylehb.tablesstring----

Table style.

Available options: danger, dark, light, info, primary, secondary, success, warning.

thead_style

NameContextTypeRequiredDefaultSinceExample
thead_stylehb.tablesstring----

Table header style.

Available options: danger, dark, light, info, primary, secondary, success, warning.

Site Parameters Example

hugo.toml

 1[params]
 2  [params.hb]
 3    [params.hb.tables]
 4      align = ''
 5      border_style = ''
 6      bordered = true
 7      group_divider = false
 8      hover = true
 9      striped = true
10      striped_columns = false
11      style = ''
12      thead_style = ''

hugo.yaml

 1params:
 2  hb:
 3    tables:
 4      align: ""
 5      border_style: ""
 6      bordered: true
 7      group_divider: false
 8      hover: true
 9      striped: true
10      striped_columns: false
11      style: ""
12      thead_style: ""

hugo.json

 1{
 2   "params": {
 3      "hb": {
 4         "tables": {
 5            "align": "",
 6            "border_style": "",
 7            "bordered": true,
 8            "group_divider": false,
 9            "hover": true,
10            "striped": true,
11            "striped_columns": false,
12            "style": "",
13            "thead_style": ""
14         }
15      }
16   }
17}

Table Attributes

_align

NameContextTypeRequiredDefaultSinceExample
_align-string-hb.tables.align--

Vertical alignment.

Available options: top, middle, bottom.

_borderless

NameContextTypeRequiredDefaultSinceExample
_borderless-boolean-false--

Whether to remove border.

_bordered

NameContextTypeRequiredDefaultSinceExample
_bordered-boolean-hb.tables.bordered--

Whether to enable border.

_border_style

NameContextTypeRequiredDefaultSinceExample
_border_style-string----

Border style.

Available options: danger, dark, light, info, primary, secondary, success, warning.

_caption

NameContextTypeRequiredDefaultSinceExample
_caption-string----

Caption.

_group_divider

NameContextTypeRequiredDefaultSinceExample
_group_divider-boolean-hb.tables.group_divider--

Whether to add a thicker border, darker between table groups.

_hover

NameContextTypeRequiredDefaultSinceExample
_hover-boolean-hb.tables.hover--

Whether to enable a hover state on tables.

_striped

NameContextTypeRequiredDefaultSinceExample
_striped-boolean-hb.tables.striped--

Whether to add zebra-striping on table rows.

_striped_columns

NameContextTypeRequiredDefaultSinceExample
_striped_columns-boolean-hb.tables.striped_columns--

Whether to add zebra-striping on table columns.

_size

NameContextTypeRequiredDefaultSinceExample
_size-string----

Table size.

Available options: sm.

_style

NameContextTypeRequiredDefaultSinceExample
_style-string----

Table style.

Available options: danger, dark, light, info, primary, secondary, success, warning.

_thead

NameContextTypeRequiredDefaultSinceExample
_thead-boolean-truev0.15.1-

Whether to show the header.

_thead_style

NameContextTypeRequiredDefaultSinceExample
_thead_style-string----

Table header style.

Available options: danger, dark, light, info, primary, secondary, success, warning.

Examples

Default Tables

The style depends on the default configurations.

Source
1| Default Table |
2| --- |
3| Foo |
4| Bar |
Result
Default Table
Foo
Bar

Horizontal Alignments

Source
1| Left | Center | Right |
2| :- | :-: | -: |
3| 1 | 2 | 3 |
4| 1 | 2 | 3 |
5| 1 | 2 | 3 |
Result
LeftCenterRight
123
123
123

Vertical Alignments

Source
1| Heading 1 | Heading 2 |
2| --- | --- |
3| `top` | This here is some placeholder text, intended to take up quite a bit of vertical space, to demonstrate how the vertical alignment works in the preceding cells. |
4{_align=top}
Result
Heading 1Heading 2
topThis here is some placeholder text, intended to take up quite a bit of vertical space, to demonstrate how the vertical alignment works in the preceding cells.
Source
1| Heading 1 | Heading 2 |
2| --- | --- |
3| `middle` | This here is some placeholder text, intended to take up quite a bit of vertical space, to demonstrate how the vertical alignment works in the preceding cells. |
4{_align=middle}
Result
Heading 1Heading 2
middleThis here is some placeholder text, intended to take up quite a bit of vertical space, to demonstrate how the vertical alignment works in the preceding cells.
Source
1| Heading 1 | Heading 2 |
2| --- | --- |
3| `bottom` | This here is some placeholder text, intended to take up quite a bit of vertical space, to demonstrate how the vertical alignment works in the preceding cells. |
4{_align=bottom}
Result
Heading 1Heading 2
bottomThis here is some placeholder text, intended to take up quite a bit of vertical space, to demonstrate how the vertical alignment works in the preceding cells.

Table with Captions

Source
1| Name | Age | Role |
2| --- | :-: | :-: |
3| Foo | 35 | Leader |
4| Bar | 23 | Developer |
5{_caption="Members"}
Result
Members
NameAgeRole
Foo35Leader
Bar23Developer

Table Styles

Source
1| Primary Table |
2| --- |
3| Foo |
4| Bar |
5{_style=primary}
Result
Primary Table
Foo
Bar
Source
1| Danger Table |
2| --- |
3| Foo |
4| Bar |
5{_style=danger}
Result
Danger Table
Foo
Bar
Source
1| Dark Table |
2| --- |
3| Foo |
4| Bar |
5{_style=dark}
Result
Dark Table
Foo
Bar

Bordered Tables with Border Styles

Source
1| Primary Bordered Table |
2| --- |
3| Foo |
4| Bar |
5{_border_style=primary}
Result
Primary Bordered Table
Foo
Bar
Source
1| Danger Bordered Table |
2| --- |
3| Foo |
4| Bar |
5{_border_style=danger}
Result
Danger Bordered Table
Foo
Bar

Borderless Tables

Source
1| Borderless Table |
2| --- |
3| Foo |
4| Bar |
5{_borderless=true}
Result
Borderless Table
Foo
Bar

Small Tables

Source
1| Small Table |
2| --- |
3| Foo |
4| Bar |
5{_size=sm}
Result
Small Table
Foo
Bar

Table Header Styles

Source
1| Primary Header |
2| --- |
3| Foo |
4| Bar |
5{_thead_style=primary}
Result
Primary Header
Foo
Bar
Source
1| Danger Header |
2| --- |
3| Foo |
4| Bar |
5{_thead_style=danger}
Result
Danger Header
Foo
Bar
Source
1| Dark Header |
2| --- |
3| Foo |
4| Bar |
5{_thead_style=dark}
Result
Dark Header
Foo
Bar

Table Without Header

Source
1| | | |
2|-|-|-|
3| 1 | 1 | 1 |
4| 2 | 2 | 2 |
5| 3 | 3 | 3 |
6| 4 | 4 | 4 |
7{_thead=false}
Result
111
222
333
444
razonyang
Saturday, November 9, 2024 Wednesday, September 4, 2024