# Tables for Ghost

HTML card + code injection · Works with any Ghost theme · No JavaScript

Source: https://brightthemes.com/snippets/tables

Comparison and rating tables for posts, with yes and no marks, rating badges and a box that scrolls sideways on phones.

## When to use it
- A roundup of the tools for a job, comparing price, free plan and key features across your picks.
- A membership post comparing your free and paid tiers, feature by feature.
- A product test with a score per category, using Good, Mid and Bad badges for each result.
When not to: For simple data with no marks or badges, a Markdown table in Ghost's **Markdown** card is enough.

## The code

HTML:

```html
<div class="bt-table-comparison" role="region" aria-label="Plan comparison" tabindex="0">
  <table>
    <thead>
      <tr>
        <th scope="col">Feature</th>
        <th scope="col">Basic</th>
        <th scope="col">Standard</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">Custom domain</th>
        <td><span class="bt-table-yes" role="img" aria-label="Yes"></span></td>
        <td><span class="bt-table-yes" role="img" aria-label="Yes"></span></td>
      </tr>
      <tr>
        <th scope="row">Built-in analytics</th>
        <td><span class="bt-table-no" role="img" aria-label="No"></span></td>
        <td><span class="bt-table-yes" role="img" aria-label="Yes"></span></td>
      </tr>
      <tr>
        <th scope="row">Chat support</th>
        <td><span class="bt-table-no" role="img" aria-label="No"></span></td>
        <td><span class="bt-table-yes" role="img" aria-label="Yes"></span></td>
      </tr>
      <tr>
        <th scope="row">Unlimited posts</th>
        <td><span class="bt-table-no" role="img" aria-label="No"></span></td>
        <td><span class="bt-table-yes" role="img" aria-label="Yes"></span></td>
      </tr>
    </tbody>
  </table>
</div>

<div class="bt-table-comparison" role="region" aria-label="Phone ratings" tabindex="0">
  <table>
    <thead>
      <tr>
        <th scope="col">Rating</th>
        <th scope="col">Phone A</th>
        <th scope="col">Phone B</th>
        <th scope="col">Phone C</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">Price</th>
        <td><span class="bt-table-rating bt-table-rating-good">Good</span></td>
        <td><span class="bt-table-rating bt-table-rating-mid">Mid</span></td>
        <td><span class="bt-table-rating bt-table-rating-bad">Bad</span></td>
      </tr>
      <tr>
        <th scope="row">Display</th>
        <td><span class="bt-table-rating bt-table-rating-mid">Mid</span></td>
        <td><span class="bt-table-rating bt-table-rating-good">Good</span></td>
        <td><span class="bt-table-rating bt-table-rating-good">Good</span></td>
      </tr>
      <tr>
        <th scope="row">Camera</th>
        <td><span class="bt-table-rating bt-table-rating-good">Good</span></td>
        <td><span class="bt-table-rating bt-table-rating-bad">Bad</span></td>
        <td><span class="bt-table-rating bt-table-rating-mid">Mid</span></td>
      </tr>
      <tr>
        <th scope="row">Battery</th>
        <td><span class="bt-table-rating bt-table-rating-bad">Bad</span></td>
        <td><span class="bt-table-rating bt-table-rating-good">Good</span></td>
        <td><span class="bt-table-rating bt-table-rating-mid">Mid</span></td>
      </tr>
    </tbody>
  </table>
</div>
```

CSS:

```css
.bt-table-comparison {
  --bt-table-border: color-mix(in srgb, currentColor 15%, transparent);
  --bt-table-stripe: color-mix(in srgb, currentColor 5%, transparent);
  --bt-table-yes: #15803d;
  --bt-table-no: #dc2626;
  --bt-table-good: #15803d;
  --bt-table-mid: #d97706;
  --bt-table-bad: #dc2626;
  max-width: 100%;
  margin: 1.5em 0 2.5em;
  overflow-x: auto;
}

.bt-table-comparison:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.bt-table-comparison table {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
  font-size: 0.95em;
}

.bt-table-comparison th,
.bt-table-comparison td {
  padding: 0.6em 1em;
  border-bottom: 1px solid var(--bt-table-border);
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

.bt-table-comparison th:first-child {
  text-align: left;
}

.bt-table-comparison thead th {
  border-bottom-width: 2px;
  font-weight: 600;
}

.bt-table-comparison tbody th {
  font-weight: 500;
}

.bt-table-comparison tbody tr:nth-child(odd) {
  background-color: var(--bt-table-stripe);
}

.bt-table-comparison .bt-table-yes,
.bt-table-comparison .bt-table-no {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5em;
  height: 1.5em;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  line-height: 1;
}

.bt-table-comparison .bt-table-yes {
  background-color: var(--bt-table-yes);
}

.bt-table-comparison .bt-table-yes::before {
  content: '✓';
}

.bt-table-comparison .bt-table-no {
  background-color: var(--bt-table-no);
}

.bt-table-comparison .bt-table-no::before {
  content: '✕';
}

.bt-table-comparison .bt-table-rating {
  --bt-table-rating: var(--bt-table-mid);
  display: inline-block;
  padding: 0.15em 0.8em;
  border: 1px solid var(--bt-table-rating);
  border-radius: 2em;
  background-color: color-mix(in srgb, var(--bt-table-rating) 15%, transparent);
  font-size: 0.85em;
  font-weight: 700;
}

.bt-table-comparison .bt-table-rating-good {
  --bt-table-rating: var(--bt-table-good);
}

.bt-table-comparison .bt-table-rating-bad {
  --bt-table-rating: var(--bt-table-bad);
}
```

## Add it to your site

1. Copy the **CSS** and paste it in **Settings › Advanced › Code injection › Site header**, between `<style>` and `</style>`. Once per site.
2. In a post, add an **HTML card** (type `/html`) and paste the **HTML**.
3. Change the example text to your own, then publish or update the post.

Tip: save the card as a Ghost snippet to add it to any post from the card menu: how Ghost snippets work, https://brightthemes.com/blog/ghost-snippets

## How it works

Each table is a plain HTML `<table>` inside a `<div class="bt-table-comparison">`. The wrapper scopes the styles, so the snippet never restyles the other tables on your site, and it scrolls sideways when a table is wider than the screen. It is focusable and labeled, so keyboard and screen reader users can reach and scroll it too; change its `aria-label` to describe your table.

The first column and the header row use `<th>`, so screen readers announce the feature and the plan with each cell. Rows are striped and lined in a tint of your theme's text color, which keeps them visible in light and dark themes. Your theme's own table styles, such as fonts, borders and header styles, can still apply on top, so check the result on a post in your theme.

Two kinds of marks fill the cells:

- **Yes and no:** `<span class="bt-table-yes">` and `<span class="bt-table-no">` draw a check or a cross in a colored circle. Their `aria-label` is what screen readers say, and the shape, not only the color, tells them apart.
- **Ratings:** `<span class="bt-table-rating bt-table-rating-good">`, `bt-table-rating-mid` or `bt-table-rating-bad` make a badge. The word in the badge carries the meaning; the color only backs it up.

Ghost has no table card, but its **Markdown** card turns Markdown tables into plain HTML tables your theme styles. Use that for simple data; use this snippet for comparisons that need marks, badges and a scroll box on phones. See [how editor cards work in Ghost](https://brightthemes.com/blog/ghost-editor-cards).

## Customize
| Variable | Default | What it changes |
|---|---|---|
| `--bt-table-border` | `15% of the text color` | The line under each row. |
| `--bt-table-stripe` | `5% of the text color` | The background of every other row. Set it to transparent to turn the stripes off. |
| `--bt-table-yes` | `#15803d` | The circle behind a yes mark (✓). |
| `--bt-table-no` | `#dc2626` | The circle behind a no mark (✕). |
| `--bt-table-good` | `#15803d` | The border and tint of Good badges. |
| `--bt-table-mid` | `#d97706` | The border and tint of Mid badges. |
| `--bt-table-bad` | `#dc2626` | The border and tint of Bad badges. |

It works with every Ghost theme, including ours (https://brightthemes.com/themes). Something not right? Ask support: https://brightthemes.com/support
