TownSquare Docs

TownSquare docs

Style the counter and reactions

Both look good with no setup. To make them match your site, add a few lines of CSS to your own stylesheet. Your CSS always wins, so you never need !important.

Every example on this page is live. The CSS you see is exactly what styles the preview above it.

The basics

There are two ways to change something:

  1. Set a variable. Colors, sizes, and spacing are CSS variables, like --ts-counter-accent.
  2. Style a part directly. Every part has a class, like .ts-counter__dot. Any CSS property works.

Put your rules wherever you like. On :root they change every counter and reaction bar on your site. On a wrapper, only the ones inside it.

Example: use your brand color

:root {
  --ts-counter-accent: #7c3aed;
  --ts-reactions-accent: #7c3aed;
}

Tap a reaction to see the accent on a pressed button.

Counter

The counter comes in four styles. Pick one in your admin page, or set variant in the snippet.

Pill, minimal, solid, and outline.

Square, bold, no dot

.ts-counter {
  --ts-counter-radius: 4px;
  font-weight: 600;
}
.ts-counter__dot {
  display: none;
}

Bigger

.ts-counter {
  --ts-counter-font-size: 1.1rem;
  --ts-counter-dot-size: 0.7em;
}

Your own colors

.ts-counter {
  --ts-counter-bg: #1f2937;
  --ts-counter-ink: #f9fafb;
  --ts-counter-dot-color: #34d399;
}

Reactions

Rounded squares and bigger emoji

.ts-reactions {
  --ts-reactions-radius: 8px;
  --ts-reactions-emoji-size: 1.4em;
}

A red heart when pressed

Each button has a data-reaction name, and aria-pressed="true" once the visitor has reacted. Combine them to style one reaction.

.ts-reactions__button[data-reaction="heart"][aria-pressed="true"] {
  --ts-reactions-pressed-bg: #ffe4e6;
  --ts-reactions-pressed-border-color: #e11d48;
}

Tap the heart to try it.

Emoji only

.ts-reactions__count {
  display: none;
}

Outlined buttons

.ts-reactions {
  --ts-reactions-bg: transparent;
  --ts-reactions-border-color: #d6d3d1;
}

Dark mode

Both follow the visitor's light or dark setting on their own. If your site has its own dark mode switch, set the colors under that class:

.dark {
  --ts-counter-ink: #f5f5f4;
  --ts-reactions-ink: #f5f5f4;
  --ts-reactions-bg: #292524;
}

Counter reference

What the counter is made of:

<button class="ts-counter ts-counter--pill">
  <span class="ts-counter__dot"></span>
  <span class="ts-counter__label">5 people here</span>
</button>

It's a <span> instead of a button when clicking can't take visitors anywhere.

Parts and states

SelectorWhat it is
.ts-counterThe badge
.ts-counter__dotThe dot
.ts-counter__labelThe text
.ts-counter--pillThe style: also --minimal, --solid, --outline
[data-interactive="true"]Clicking goes to the square
[data-empty="true"]The count is zero

Variables

VariableChanges
--ts-counter-accentDot, solid fill, outline border, focus ring
--ts-counter-bgBackground
--ts-counter-inkText color
--ts-counter-border-colorBorder color
--ts-counter-border-widthBorder width
--ts-counter-shadowShadow
--ts-counter-radiusCorner roundness
--ts-counter-font-sizeSize (spacing and dot grow with it)
--ts-counter-pad-y, --ts-counter-pad-xPadding
--ts-counter-gapSpace between dot and text
--ts-counter-dot-colorDot color
--ts-counter-dot-sizeDot size
--ts-counter-focus-colorKeyboard focus ring

Reactions reference

What the reaction bar is made of:

<div class="ts-reactions">
  <button class="ts-reactions__button" data-reaction="heart" aria-pressed="false">
    <span class="ts-reactions__emoji">❤️</span>
    <span class="ts-reactions__count">12</span>
  </button>
  …
</div>

Parts and states

SelectorWhat it is
.ts-reactionsThe row of buttons
.ts-reactions__buttonOne reaction
.ts-reactions__emojiThe emoji
.ts-reactions__countThe number
[data-reaction="heart"]One reaction by name: heart, thumbs-up, clap, laugh, wow, fire
[aria-pressed="true"]The visitor has reacted

Variables

VariableChanges
--ts-reactions-accentPressed border, pressed tint, focus ring
--ts-reactions-bgButton background
--ts-reactions-inkText color
--ts-reactions-border-colorBorder color
--ts-reactions-border-widthBorder width
--ts-reactions-shadowShadow
--ts-reactions-radiusCorner roundness
--ts-reactions-font-sizeSize (spacing grows with it)
--ts-reactions-pad-y, --ts-reactions-pad-xButton padding
--ts-reactions-gapSpace between buttons
--ts-reactions-button-gapSpace between emoji and number
--ts-reactions-emoji-sizeEmoji size
--ts-reactions-pressed-bgPressed background
--ts-reactions-pressed-border-colorPressed border
--ts-reactions-pressed-inkPressed text color
--ts-reactions-focus-colorKeyboard focus ring

Good to know

  • The snippet's accent wins over your CSS. To set the accent in CSS, tick "Use the default accent color" in your admin page, or delete the accent line from the snippet.
  • A hidden badge stays hidden. If your site is paused or the key is wrong, the badge hides itself, even if your CSS sets display.
  • Only use the names on this page. Variables that start with --_ts- are internal and may change.