# Alert boxes for Ghost

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

Source: https://brightthemes.com/snippets/alert-boxes

Note, info, warning, danger and success boxes to highlight part of a post, each with its own color, icon and label.

## When to use it
- A warning in a tutorial before a step that can't be undone, such as deleting members or changing a domain.
- A note at the top of an older post saying what has changed since, with a link to the update.
- A success box after setup steps, telling readers what they should see if it worked.
- An affiliate or sponsor disclosure in reviews, in the same style and place in every post.
When not to: For a one-off tip, or anything that has to show in the newsletter, Ghost's **Callout** card does the job with no CSS.

## The code

HTML:

```html
<div class="bt-alert-box">
  <p><strong>Note:</strong> This box uses the default, neutral style.</p>
</div>

<div class="bt-alert-box bt-alert-box-info">
  <p><strong>Info:</strong> The new issue goes out every Friday morning.</p>
</div>

<div class="bt-alert-box bt-alert-box-warning">
  <p><strong>Warning:</strong> Back up your site before you change the theme.</p>
</div>

<div class="bt-alert-box bt-alert-box-danger">
  <p><strong>Danger:</strong> Deleting your account can't be undone.</p>
</div>

<div class="bt-alert-box bt-alert-box-success">
  <p><strong>Success:</strong> Your settings are saved.</p>
</div>
```

CSS:

```css
.bt-alert-box {
  --bt-alert-box-color: #6b7280;
  --bt-alert-box-info: #2563eb;
  --bt-alert-box-warning: #d97706;
  --bt-alert-box-danger: #dc2626;
  --bt-alert-box-success: #15803d;
  --bt-alert-box-radius: 4px;
  --bt-alert-box-accent: var(--bt-alert-box-color);
  --bt-alert-box-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 11v5.5'/%3E%3Ccircle cx='12' cy='7.75' r='1.15' fill='black' stroke='none'/%3E%3C/svg%3E");
  --bt-alert-box-rule: 4px;
  --bt-alert-box-tint: 8%;
  position: relative;
  box-sizing: border-box;
  margin: 1em 0 1.5em;
  padding: 1em 1.25em 1em 3.25em;
  border: 0;
  border-left: var(--bt-alert-box-rule) solid var(--bt-alert-box-accent);
  border-radius: var(--bt-alert-box-radius);
  background-color: color-mix(in srgb, var(--bt-alert-box-accent) var(--bt-alert-box-tint), transparent);
  line-height: 1.5;
}

.bt-alert-box::before {
  position: absolute;
  /* centred on the first line: the box's 1em padding plus half its 1.5 line, in the icon's own 0.875em, less half the
     icon's 1.5em height */
  top: calc((1em + 0.75em) / 0.875 - 0.75em);
  left: 1em;
  width: 1.5em;
  height: 1.5em;
  /* the icon is an SVG mask (a circle and its mark) filled with the type's color: drawn, not a font glyph, so every
     mark sits in the middle of its circle */
  background-color: var(--bt-alert-box-accent);
  -webkit-mask: var(--bt-alert-box-icon) center / contain no-repeat;
  mask: var(--bt-alert-box-icon) center / contain no-repeat;
  font-size: 0.875em;
  content: '';
}

.bt-alert-box > :first-child {
  margin-top: 0;
}

.bt-alert-box > :last-child {
  margin-bottom: 0;
}

.bt-alert-box.bt-alert-box-info {
  --bt-alert-box-accent: var(--bt-alert-box-info);
}

.bt-alert-box.bt-alert-box-warning {
  --bt-alert-box-accent: var(--bt-alert-box-warning);
  --bt-alert-box-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 6.75v6.5'/%3E%3Ccircle cx='12' cy='16.75' r='1.15' fill='black' stroke='none'/%3E%3C/svg%3E");
}

.bt-alert-box.bt-alert-box-danger {
  --bt-alert-box-accent: var(--bt-alert-box-danger);
  --bt-alert-box-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M8.75 8.75l6.5 6.5M15.25 8.75l-6.5 6.5'/%3E%3C/svg%3E");
}

.bt-alert-box.bt-alert-box-success {
  --bt-alert-box-accent: var(--bt-alert-box-success);
  --bt-alert-box-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M7.75 12.5l2.75 2.75 5.75-6'/%3E%3C/svg%3E");
}
```

## 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

An alert box is a `<div class="bt-alert-box">` with a second class for its type: `bt-alert-box-info`, `bt-alert-box-warning`, `bt-alert-box-danger` or `bt-alert-box-success`, or none for a neutral note. The prefix keeps a theme's own `.info` or `.success` rules away from it. The type sets one color, which the CSS uses for the rule on the left, the background tint and the outlined icon. The text keeps your theme's own color, so it stays readable in light and dark themes.

Color is never the only signal: the icon and the bold label at the start of the text say what kind of box it is too. Keep a label when you write your own. Inside the box you can use any HTML: several paragraphs, a list or links.

To add a type of your own, copy one of the type rules in the CSS, give it a new class name, and set `--bt-alert-box-accent` in it, and `--bt-alert-box-icon` to an SVG `url(…)` (a 24×24 drawing in black; it's used as a mask, filled with the type's color).

Ghost's editor has its own **Callout** card, a highlighted box with an emoji and a background color, which needs no code and also works in newsletters. Use it for a quick tip; use this snippet when you want the same types across your posts. The CSS from code injection doesn't reach emails, so in a newsletter these boxes show as plain text. See [how editor cards work in Ghost](https://brightthemes.com/blog/ghost-editor-cards) and [how code injection works](https://brightthemes.com/blog/ghost-code-injection).

## Customize
| Variable | Default | What it changes |
|---|---|---|
| `--bt-alert-box-color` | `#6b7280` | The color of the default, neutral note. |
| `--bt-alert-box-info` | `#2563eb` | The color of info boxes. |
| `--bt-alert-box-warning` | `#d97706` | The color of warning boxes (an amber dark enough for its icon to read on the tint). |
| `--bt-alert-box-danger` | `#dc2626` | The color of danger boxes. |
| `--bt-alert-box-success` | `#15803d` | The color of success boxes. |
| `--bt-alert-box-rule` | `4px` | The width of the colored rule on the left. |
| `--bt-alert-box-tint` | `8%` | How much of the box's color tints its background. 0% for no background. |
| `--bt-alert-box-radius` | `4px` | The corner radius. |

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