Menu

Menu

On this page

On this page

Table

Provides style variants for displaying tabular data.

npm install @vrembem/table
Copied!
SCSS
@use "@vrembem/table";
Copied!

Options

Table is built as a Sass module. Sass options are used to control CSS output, while design token CSS variables control the styling of the component. Below are the available configuration options.

Sass

Table comes with the following Sass configuration options that can be set using either the config module or Sass with clause methods.

SCSS
@use "@vrembem/table" with (
  $config: (
    // Toggle for outputting table--mobile modifier breakpoint variants
    // @type boolean
    "table-mobile": (
      "breakpoints": true,
      "attr": "data-mobile-label"
    )
  )
);
Copied!

Design tokens

Table uses design token CSS variables in a reference and fallback pattern. Variables are referenced in the component's styles but are not directly defined; instead, they are provided with sensible fallbacks.

VariableFallback
--vb-table-foreground
Copied!
inherit
Copied!
--vb-table-background
Copied!
var(--vb-background)
Copied!
--vb-table-padding
Copied!
0.5em 0.75em
Copied!
--vb-table-vertical-align
Copied!
top
Copied!
--vb-table-header-foreground
Copied!
var(--vb-foreground)
Copied!
--vb-table-border-width
Copied!
var(--vb-border-width)
Copied!
--vb-table-border-style
Copied!
var(--vb-border-style)
Copied!
--vb-table-border-color
Copied!
var(--vb-border-color)
Copied!
--vb-table-foreground-hover
Copied!
inherit
Copied!
--vb-table-background-hover
Copied!
hsl(var(--vb-primary-hs) 50% / 15%)
Copied!
--vb-table-background-striped
Copied!
--vb-table-mobile-label-width
Copied!
8em
Copied!
--vb-table-mobile-label-spacing
Copied!
0.75em
Copied!
--vb-table-mobile-label-foreground
Copied!
inherit
Copied!
--vb-table-mobile-label-background
Copied!
transparent
Copied!

Basic usage

For basic table styles, only the table component class is required. Use proper HTML table markup and styles should apply as expected.

Example of a table caption.
NameMassClassVariant
Locust20tLightLCT-1V
Shadow Hawk55tMediumSHD-2H
Thunderbolt65tHeavyTDR-5S
BattleMaster85tAssaultBLR-1G
HTML
<table class="table">
  <caption>Example of a table caption.</caption>
  <thead>
    <tr>
      <th>Name</th>
      <th>Mass</th>
      <th>Class</th>
      <th>Variant</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Locust</td>
      <td>20t</td>
      <td>Light</td>
      <td>LCT-1V</td>
    </tr>
    <tr>
      <td>Shadow Hawk</td>
      <td>55t</td>
      <td>Medium</td>
      <td>SHD-2H</td>
    </tr>
    <tr>
      <td>Thunderbolt</td>
      <td>65t</td>
      <td>Heavy</td>
      <td>TDR-5S</td>
    </tr>
    <tr>
      <td>BattleMaster</td>
      <td>85t</td>
      <td>Assault</td>
      <td>BLR-1G</td>
    </tr>
  </tbody>
</table>
Copied!

Overflow utility

For simple responsive table styles, wrap your tables in a div with the overflow-auto utility. This provides horizontal scrolling when tables can't fit in their container.

BookPagesQuote
The Hobbit272"Do you wish me a good morning, or mean that it is a good morning whether I want it or not; or that you feel good this morning; or that it is a morning to be good on?"
The Fellowship of the Ring377"I wish it need not have happened in my time," said Frodo. "So do I," said Gandalf, "and so do all who live to see such times. But that is not for them to decide. All we have to decide is what to do with the time that is given us."
The Two Towers322"War must be, while we defend our lives against a destroyer who would devour all; but I do not love the bright sword for its sharpness, nor the arrow for its swiftness, nor the warrior for his glory. I love only that which they defend."
The Return of the King277"But I have been too deeply hurt, Sam. I tried to save the Shire, and it has been saved, but not for me. It must often be so, Sam, when things are in danger: some one has to give them up, lose them, so that others may keep them."
HTML
<div class="overflow-auto">
  <table class="table">
    ...
  </table>
</div>
Copied!

Hug content

Use the hug-content table utility when a table cell should fit the size of its contents. This is useful for columns with compact content like checkboxes, icons, or action buttons that shouldn't take up more space than necessary.

NameMassClassVariant
Locust20tLightLCT-1V
Shadow Hawk55tMediumSHD-2H
Thunderbolt65tHeavyTDR-5S
BattleMaster85tAssaultBLR-1G
HTML
<table class="table">
  <thead>
    <tr>
      <th class="hug-content"></th>
      ...
    </tr>
  </thead>
  <tbody>
    ...
  </tbody>
</table>
Copied!

table--ellipsis

Switches a table layout to fixed and adds ellipsis overflow styles to table cells and headers.

BookPagesQuote
The Hobbit272"Do you wish me a good morning, or mean that it is a good morning whether I want it or not; or that you feel good this morning; or that it is a morning to be good on?"
The Fellowship of the Ring377"I wish it need not have happened in my time," said Frodo. "So do I," said Gandalf, "and so do all who live to see such times. But that is not for them to decide. All we have to decide is what to do with the time that is given us."
The Two Towers322"War must be, while we defend our lives against a destroyer who would devour all; but I do not love the bright sword for its sharpness, nor the arrow for its swiftness, nor the warrior for his glory. I love only that which they defend."
The Return of the King277"But I have been too deeply hurt, Sam. I tried to save the Shire, and it has been saved, but not for me. It must often be so, Sam, when things are in danger: some one has to give them up, lose them, so that others may keep them."
HTML
<table class="table table--ellipsis">
  ...
</table>
Copied!

Space will be split equally between columns when table--ellipsis is applied. For more control over specific column widths, use the <colgroup> and <col> elements and set their desired widths as needed.

BookPagesQuote
The Hobbit272"Do you wish me a good morning, or mean that it is a good morning whether I want it or not; or that you feel good this morning; or that it is a morning to be good on?"
The Fellowship of the Ring377"I wish it need not have happened in my time," said Frodo. "So do I," said Gandalf, "and so do all who live to see such times. But that is not for them to decide. All we have to decide is what to do with the time that is given us."
The Two Towers322"War must be, while we defend our lives against a destroyer who would devour all; but I do not love the bright sword for its sharpness, nor the arrow for its swiftness, nor the warrior for his glory. I love only that which they defend."
The Return of the King277"But I have been too deeply hurt, Sam. I tried to save the Shire, and it has been saved, but not for me. It must often be so, Sam, when things are in danger: some one has to give them up, lose them, so that others may keep them."
HTML
<table class="table table--ellipsis">
  <colgroup>
    <col />
    <col style="width: 5em;" />
    <col />
  </colgroup>
  ...
</table>
Copied!

table--hover

Adds hover, focus and focus-within state styles for table row (<tr>) elements.

NameMassClassVariant
Jenner35tLightJR7-D
Hunchback50tMediumHBK-4G
Catapult65tHeavyCPLT-C1
Atlas100tAssaultAS7-D
HTML
<table class="table table--hover">
  ...
</table>
Copied!

table--mobile

A modifier that adds mobile styles to a table so that it's easier to read on mobile devices. This is done by using the data-mobile-label attribute on table cells that should correspond to the table column header for that specific cell.

NameMassClassVariant
Jenner35tLightJR7-F
Hunchback50tMediumHBK-4P
HTML
<table class="table table--mobile">
  <thead>
    <tr>
      <th>key</th>
      <th>value</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td data-mobile-label="key">...</td>
      <td data-mobile-label="value">...</td>
    </tr>
  </tbody>
</table>
Copied!

The mobile label value will be truncated if it exceeds the width set by --vb-table-mobile-label-width CSS variable. The mobile label attribute used can be changed using the attr key in the table-mobile config options map.

Breakpoint variants

This modifier come with media breakpoint variants. This allows changing styles based on a specific breakpoint key in the breakpoints config options map. Breakpoint variants output can be toggled using the breakpoints key in the table-mobile config options map (default: true).

Available variants

  • xs:table--mobile
  • sm:table--mobile
  • md:table--mobile
  • lg:table--mobile
  • xl:table--mobile

table--padding-[key]

Adjust the padding of a table's <th>, <td>, and <caption> elements. These modifiers are generated using key/value pairs of the table-padding config options map.

NameMassClassVariant
Griffin55tMediumGRF-1N
Wolverine55tMediumWVR-6R
NameMassClassVariant
Griffin55tMediumGRF-1N
Wolverine55tMediumWVR-6R
HTML
<table class="table table--padding-sm">...</table>
<table class="table table--padding-lg">...</table>
Copied!

Available variants

  • table--padding-sm
  • table--padding-md
  • table--padding-lg

Breakpoint variants

These modifiers come with media breakpoint variants. This allows changing styles based on a specific breakpoint key in the breakpoints config options map. Breakpoint variants output can be toggled using the breakpoints key in the table-padding config options map (default: true).

Current view-port width: ...

NameMassClassVariant
Griffin55tMediumGRF-1N
Wolverine55tMediumWVR-6R
HTML
<table class="table table--padding-sm lg:table--padding-md xl:table--padding-lg">
  ...
</table>
Copied!

Available variants

  • sm:table--padding-[key]
  • md:table--padding-[key]
  • lg:table--padding-[key]

table--striped

Adds zebra styled rows to a table to help increase its readability. This is done by alternating the background color of rows to help guide the reader's eye.

NameMassClassVariant
Firestarter35tLightFS9-A
Uziel50tMediumUZL-6P
Crusader65tHeavyCRD-6T
Cyclops90tAssaultCP-11-P
HTML
<table class="table table--striped">
  ...
</table>
Copied!

table--style-[key]

Adds table styles based on the provided value.

NameMassClassVariant
Griffin55tMediumGRF-2N
Wolverine55tMediumWVR-7K
HTML
<table class="table table--style-rowed">
  ...
</table>
Copied!
NameMassClassVariant
Griffin55tMediumGRF-2N
Wolverine55tMediumWVR-7K
HTML
<table class="table table--style-bordered">
  ...
</table>
Copied!

Available variants

  • table--style-rowed
  • table--style-bordered