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:
-
Set a variable. Colors, sizes, and spacing are CSS
variables, like
--ts-counter-accent. -
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.
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
| Selector | What it is |
|---|---|
.ts-counter | The badge |
.ts-counter__dot | The dot |
.ts-counter__label | The text |
.ts-counter--pill | The style: also --minimal, --solid, --outline |
[data-interactive="true"] | Clicking goes to the square |
[data-empty="true"] | The count is zero |
Variables
| Variable | Changes |
|---|---|
--ts-counter-accent | Dot, solid fill, outline border, focus ring |
--ts-counter-bg | Background |
--ts-counter-ink | Text color |
--ts-counter-border-color | Border color |
--ts-counter-border-width | Border width |
--ts-counter-shadow | Shadow |
--ts-counter-radius | Corner roundness |
--ts-counter-font-size | Size (spacing and dot grow with it) |
--ts-counter-pad-y, --ts-counter-pad-x | Padding |
--ts-counter-gap | Space between dot and text |
--ts-counter-dot-color | Dot color |
--ts-counter-dot-size | Dot size |
--ts-counter-focus-color | Keyboard 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
| Selector | What it is |
|---|---|
.ts-reactions | The row of buttons |
.ts-reactions__button | One reaction |
.ts-reactions__emoji | The emoji |
.ts-reactions__count | The number |
[data-reaction="heart"] | One reaction by name: heart, thumbs-up, clap, laugh, wow, fire |
[aria-pressed="true"] | The visitor has reacted |
Variables
| Variable | Changes |
|---|---|
--ts-reactions-accent | Pressed border, pressed tint, focus ring |
--ts-reactions-bg | Button background |
--ts-reactions-ink | Text color |
--ts-reactions-border-color | Border color |
--ts-reactions-border-width | Border width |
--ts-reactions-shadow | Shadow |
--ts-reactions-radius | Corner roundness |
--ts-reactions-font-size | Size (spacing grows with it) |
--ts-reactions-pad-y, --ts-reactions-pad-x | Button padding |
--ts-reactions-gap | Space between buttons |
--ts-reactions-button-gap | Space between emoji and number |
--ts-reactions-emoji-size | Emoji size |
--ts-reactions-pressed-bg | Pressed background |
--ts-reactions-pressed-border-color | Pressed border |
--ts-reactions-pressed-ink | Pressed text color |
--ts-reactions-focus-color | Keyboard focus ring |
Good to know
-
The snippet's
accentwins over your CSS. To set the accent in CSS, tick "Use the default accent color" in your admin page, or delete theaccentline 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.