# Subscribe forms for Ghost

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

Source: https://brightthemes.com/snippets/subscribe-forms

A sign-up form inside a post where readers choose their topics, built on Ghost's own member sign-up and labels, with no extra script.

## When to use it
- A site that covers several topics, so you can send each topic's posts only to members with that label.
- A publication in two languages, where readers pick the one they want to receive.
- A welcome or about page, where new readers say what they came for before your first issue.
When not to: For a plain email form, or one label for everyone, Ghost's **Signup** card needs no code.

## The code

HTML:

```html
<div class="bt-subscribe-form-box">
  <h3 class="bt-subscribe-form-title">Get the weekly letter</h3>
  <p class="bt-subscribe-form-text">Stories about the world's hidden wonders, in your inbox every Friday. Pick the topics you want.</p>
  <form class="bt-subscribe-form" data-members-form="signup">
    <fieldset class="bt-subscribe-form-topics">
      <legend class="bt-subscribe-form-hidden">Topics</legend>
      <label class="bt-subscribe-form-topic">
        <input type="checkbox" value="Technology" data-members-label checked onchange="this.toggleAttribute('data-members-label', this.checked)">
        <span>Technology</span>
      </label>
      <label class="bt-subscribe-form-topic">
        <input type="checkbox" value="Science" data-members-label checked onchange="this.toggleAttribute('data-members-label', this.checked)">
        <span>Science</span>
      </label>
      <label class="bt-subscribe-form-topic">
        <input type="checkbox" value="Travel" onchange="this.toggleAttribute('data-members-label', this.checked)">
        <span>Travel</span>
      </label>
    </fieldset>
    <div class="bt-subscribe-form-row">
      <label class="bt-subscribe-form-field">
        <span class="bt-subscribe-form-hidden">Email address</span>
        <input type="email" data-members-email placeholder="you@example.com" autocomplete="email" required>
      </label>
      <button type="submit">Subscribe</button>
    </div>
    <p class="bt-subscribe-form-note">Free, one email a week. Unsubscribe any time.</p>
    <div aria-live="polite">
      <p class="bt-subscribe-form-success">Check your inbox and select the link to confirm.</p>
      <p class="bt-subscribe-form-error">Something went wrong. <span data-members-error></span></p>
    </div>
  </form>
</div>
```

CSS:

```css
.bt-subscribe-form-box {
  --bt-subscribe-accent: var(--ghost-accent-color, #4433ff);
  --bt-subscribe-button-text: #fff;
  --bt-subscribe-line: color-mix(in srgb, currentColor 14%, transparent);
  --bt-subscribe-radius: 12px;
  --bt-subscribe-success: #15803d;
  --bt-subscribe-error: #dc2626;
  box-sizing: border-box;
  margin: 2em 0;
  padding: 1.75em;
  border: 1px solid var(--bt-subscribe-line);
  border-radius: var(--bt-subscribe-radius);
  background-color: color-mix(in srgb, currentColor 2%, transparent);
}

.bt-subscribe-form-box *,
.bt-subscribe-form-box *::before {
  box-sizing: border-box;
}

.bt-subscribe-form-box .bt-subscribe-form-title {
  margin: 0 0 0.35em;
  padding: 0;
  border: 0;
  font-family: inherit;
  font-size: 1.25em;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: inherit;
}

.bt-subscribe-form-box .bt-subscribe-form-text {
  margin: 0 0 1.25em;
  font-size: 0.95em;
  line-height: 1.55;
  opacity: 0.8;
}

/* Topics as pills: a real checkbox, hidden, and the pill drawn on its label */
.bt-subscribe-form-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  margin: 0 0 1em;
  padding: 0;
  border: 0;
}

.bt-subscribe-form-topic {
  position: relative;
  cursor: pointer;
}

.bt-subscribe-form-topic input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.bt-subscribe-form-topic span {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  min-height: 2.25em;
  padding: 0 0.9em;
  border: 1px solid var(--bt-subscribe-line);
  border-radius: 999px;
  font-size: 0.875em;
  font-weight: 500;
  line-height: 1;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}

.bt-subscribe-form-topic span::before {
  width: 0.7em;
  height: 0.4em;
  margin-top: -0.2em;
  border-bottom: 2px solid currentColor;
  border-left: 2px solid currentColor;
  transform: rotate(-45deg);
  content: '';
}

.bt-subscribe-form-topic input:not(:checked) + span::before {
  display: none;
}

.bt-subscribe-form-topic input:checked + span {
  border-color: var(--bt-subscribe-accent);
  background-color: color-mix(in srgb, var(--bt-subscribe-accent) 10%, transparent);
  color: var(--bt-subscribe-accent);
}

.bt-subscribe-form-topic input:focus-visible + span {
  outline: 2px solid var(--bt-subscribe-accent);
  outline-offset: 2px;
}

.bt-subscribe-form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
}

.bt-subscribe-form-field {
  flex: 999 1 14em;
}

.bt-subscribe-form-field input,
.bt-subscribe-form button {
  width: 100%;
  min-height: 2.75em;
  margin: 0;
  padding: 0 1em;
  border-radius: 8px;
  font: inherit;
}

.bt-subscribe-form-field input {
  border: 1px solid color-mix(in srgb, currentColor 30%, transparent);
  background-color: #fff;
  color: #1a1a1a;
}

.bt-subscribe-form button {
  flex: 1 0 auto;
  width: auto;
  border: 0;
  background-color: var(--bt-subscribe-accent);
  color: var(--bt-subscribe-button-text);
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s;
}

.bt-subscribe-form button:hover {
  filter: brightness(1.1);
}

.bt-subscribe-form-field input:focus-visible,
.bt-subscribe-form button:focus-visible {
  outline: 2px solid var(--bt-subscribe-accent);
  outline-offset: 2px;
}

.bt-subscribe-form.loading button {
  opacity: 0.6;
  pointer-events: none;
}

.bt-subscribe-form-box .bt-subscribe-form-note {
  margin: 0.75em 0 0;
  font-size: 0.8em;
  opacity: 0.7;
  line-height: 1.5;
}

.bt-subscribe-form-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.bt-subscribe-form-success,
.bt-subscribe-form-error {
  display: none;
  margin: 0.75em 0 0;
  font-size: 0.9em;
  font-weight: 600;
}

.bt-subscribe-form.success .bt-subscribe-form-success,
.bt-subscribe-form.error .bt-subscribe-form-error {
  display: block;
}

.bt-subscribe-form-success::before {
  color: var(--bt-subscribe-success);
  content: '✓ ';
}

.bt-subscribe-form-error::before {
  color: var(--bt-subscribe-error);
  content: '✕ ';
}

@media (prefers-reduced-motion: reduce) {
  .bt-subscribe-form-topic span,
  .bt-subscribe-form button {
    transition: none;
  }
}
```

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

Ghost handles any form on your site with `data-members-form="signup"`, so the form needs no script of its own. When a reader enters their email, Ghost sends them a link to confirm, and adds a class to the form while it works: `loading`, then `success` or `error`. The CSS uses those classes to show the right message, and Ghost puts its error text in the `data-members-error` span. Sign-ups have to be open in **Settings › Membership › Access**.

Each topic is a real checkbox, drawn as a pill, with a `data-members-label` attribute when it's chosen, and its `value` becomes a label on the new member, so you can segment your list. Ghost applies every input that has the attribute, ticked or not, so the small `onchange` handler adds the attribute when a reader chooses a topic and removes it when they don't. Travel starts unchosen, so it starts without the attribute. Change the values to your own labels, or remove the topics to keep a plain email form. For more on labels, see [how to segment members with labels](https://brightthemes.com/blog/ghost-member-labels); to add a name field or choose newsletters, see [custom subscription forms in Ghost](https://brightthemes.com/blog/ghost-subscription-forms).

For a plain form, Ghost has its own: the editor's **Signup** card adds a styled form to a post and can give everyone who signs up the same label, and **Settings › Growth › Signup forms** makes a form to embed on other sites. Use this snippet when readers should choose their own topics.

Emails can't send forms, so the form doesn't work in a newsletter; use the **Call to action** card there.

## Customize
| Variable | Default | What it changes |
|---|---|---|
| `--bt-subscribe-accent` | `var(--ghost-accent-color, #4433ff)` | The button and the chosen topics. Defaults to your site's accent color. |
| `--bt-subscribe-button-text` | `#fff` | The button's text color. Use a dark color if your accent is light. |
| `--bt-subscribe-line` | `color-mix(in srgb, currentColor 14%, transparent)` | The box's border and the topic pills' outline, from your theme's text color, so it works on light and dark themes. |
| `--bt-subscribe-radius` | `12px` | The box's corner radius. |
| `--bt-subscribe-success` | `#15803d` | The check in front of the success message. |
| `--bt-subscribe-error` | `#dc2626` | The cross in front of the error message. |

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