Navigation

v2.1.0
Content

Reaction

Emoji answers to a message, each with its count, that a press adds to.

On this page

A reaction is an emoji a reader leaves under a message, with how many others left it. Each one is a flat pill of the chip tone around a native checkbox: a press adds the reader's own and a second press takes it back. The count is a CSS counter, so it goes up and down with the box and needs no script.

Reaction

<ol class="max-w(400) w-full mx-auto m(0) p(0)">  <li class="message">    <span class="avatar avatar-sm message-avatar">      <img class="avatar-image" src="/demo/portrait-1.svg" alt="Ada">    </span>    <div class="message-bubble">The new previews are live. Have a look before the review.</div>    <div class="reaction-group" role="group" aria-label="Reactions to Ada's message">      <label class="reaction" style="--count: 3">        <input type="checkbox" class="reaction-input" name="reaction" value="👍" aria-label="Thumbs up, 3 others" checked>        <span class="reaction-emoji" aria-hidden="true">👍</span>        <span class="reaction-count" aria-hidden="true"></span>      </label>      <label class="reaction" style="--count: 2">        <input type="checkbox" class="reaction-input" name="reaction" value="🎉" aria-label="Party popper, 2 others">        <span class="reaction-emoji" aria-hidden="true">🎉</span>        <span class="reaction-count" aria-hidden="true"></span>      </label>      <label class="reaction" style="--count: 1">        <input type="checkbox" class="reaction-input" name="reaction" value="👀" aria-label="Eyes, 1 other">        <span class="reaction-emoji" aria-hidden="true">👀</span>        <span class="reaction-count" aria-hidden="true"></span>      </label>    </div>    <span class="message-meta">Ada · 14:03</span>  </li>  <li class="message message-sent">    <div class="message-bubble">On it. The dark ones look right.</div>    <div class="reaction-group" role="group" aria-label="Reactions to your message">      <label class="reaction" style="--count: 1">        <input type="checkbox" class="reaction-input" name="reaction-reply" value="❤️" aria-label="Heart, 1 other">        <span class="reaction-emoji" aria-hidden="true">❤️</span>        <span class="reaction-count" aria-hidden="true"></span>      </label>    </div>  </li></ol>
<ol className="max-w(400) w-full mx-auto m(0) p(0)">  <li className="message">    <span className="avatar avatar-sm message-avatar">      <img className="avatar-image" src="/demo/portrait-1.svg" alt="Ada" />    </span>    <div className="message-bubble">The new previews are live. Have a look before the review.</div>    <div className="reaction-group" role="group" aria-label="Reactions to Ada's message">      <label className="reaction" style={{ '--count': '3' } as React.CSSProperties}>        <input type="checkbox" className="reaction-input" name="reaction" value="👍" aria-label="Thumbs up, 3 others" defaultChecked />        <span className="reaction-emoji" aria-hidden="true">👍</span>        <span className="reaction-count" aria-hidden="true"></span>      </label>      <label className="reaction" style={{ '--count': '2' } as React.CSSProperties}>        <input type="checkbox" className="reaction-input" name="reaction" value="🎉" aria-label="Party popper, 2 others" />        <span className="reaction-emoji" aria-hidden="true">🎉</span>        <span className="reaction-count" aria-hidden="true"></span>      </label>      <label className="reaction" style={{ '--count': '1' } as React.CSSProperties}>        <input type="checkbox" className="reaction-input" name="reaction" value="👀" aria-label="Eyes, 1 other" />        <span className="reaction-emoji" aria-hidden="true">👀</span>        <span className="reaction-count" aria-hidden="true"></span>      </label>    </div>    <span className="message-meta">Ada · 14:03</span>  </li>  <li className="message message-sent">    <div className="message-bubble">On it. The dark ones look right.</div>    <div className="reaction-group" role="group" aria-label="Reactions to your message">      <label className="reaction" style={{ '--count': '1' } as React.CSSProperties}>        <input type="checkbox" className="reaction-input" name="reaction-reply" value="❤️" aria-label="Heart, 1 other" />        <span className="reaction-emoji" aria-hidden="true">❤️</span>        <span className="reaction-count" aria-hidden="true"></span>      </label>    </div>  </li></ol>
<ol class="max-w(400) w-full mx-auto m(0) p(0)">  <li class="message">    <span class="avatar avatar-sm message-avatar">      <img class="avatar-image" src="/demo/portrait-1.svg" alt="Ada">    </span>    <div class="message-bubble">The new previews are live. Have a look before the review.</div>    <div class="reaction-group" role="group" aria-label="Reactions to Ada's message">      <label class="reaction" style="--count: 3">        <input type="checkbox" class="reaction-input" name="reaction" value="👍" aria-label="Thumbs up, 3 others" checked>        <span class="reaction-emoji" aria-hidden="true">👍</span>        <span class="reaction-count" aria-hidden="true"></span>      </label>      <label class="reaction" style="--count: 2">        <input type="checkbox" class="reaction-input" name="reaction" value="🎉" aria-label="Party popper, 2 others">        <span class="reaction-emoji" aria-hidden="true">🎉</span>        <span class="reaction-count" aria-hidden="true"></span>      </label>      <label class="reaction" style="--count: 1">        <input type="checkbox" class="reaction-input" name="reaction" value="👀" aria-label="Eyes, 1 other">        <span class="reaction-emoji" aria-hidden="true">👀</span>        <span class="reaction-count" aria-hidden="true"></span>      </label>    </div>    <span class="message-meta">Ada · 14:03</span>  </li>  <li class="message message-sent">    <div class="message-bubble">On it. The dark ones look right.</div>    <div class="reaction-group" role="group" aria-label="Reactions to your message">      <label class="reaction" style="--count: 1">        <input type="checkbox" class="reaction-input" name="reaction-reply" value="❤️" aria-label="Heart, 1 other">        <span class="reaction-emoji" aria-hidden="true">❤️</span>        <span class="reaction-count" aria-hidden="true"></span>      </label>    </div>  </li></ol>
<template>  <ol class="max-w(400) w-full mx-auto m(0) p(0)">    <li class="message">      <span class="avatar avatar-sm message-avatar">        <img class="avatar-image" src="/demo/portrait-1.svg" alt="Ada">      </span>      <div class="message-bubble">The new previews are live. Have a look before the review.</div>      <div class="reaction-group" role="group" aria-label="Reactions to Ada's message">        <label class="reaction" style="--count: 3">          <input type="checkbox" class="reaction-input" name="reaction" value="👍" aria-label="Thumbs up, 3 others" checked>          <span class="reaction-emoji" aria-hidden="true">👍</span>          <span class="reaction-count" aria-hidden="true"></span>        </label>        <label class="reaction" style="--count: 2">          <input type="checkbox" class="reaction-input" name="reaction" value="🎉" aria-label="Party popper, 2 others">          <span class="reaction-emoji" aria-hidden="true">🎉</span>          <span class="reaction-count" aria-hidden="true"></span>        </label>        <label class="reaction" style="--count: 1">          <input type="checkbox" class="reaction-input" name="reaction" value="👀" aria-label="Eyes, 1 other">          <span class="reaction-emoji" aria-hidden="true">👀</span>          <span class="reaction-count" aria-hidden="true"></span>        </label>      </div>      <span class="message-meta">Ada · 14:03</span>    </li>    <li class="message message-sent">      <div class="message-bubble">On it. The dark ones look right.</div>      <div class="reaction-group" role="group" aria-label="Reactions to your message">        <label class="reaction" style="--count: 1">          <input type="checkbox" class="reaction-input" name="reaction-reply" value="❤️" aria-label="Heart, 1 other">          <span class="reaction-emoji" aria-hidden="true">❤️</span>          <span class="reaction-count" aria-hidden="true"></span>        </label>      </div>    </li>  </ol></template>
Press a reaction to add yours, and again to take it back.

Put a reaction-group after the bubble: under a received message it starts where the bubble starts, under a sent one it ends where the bubble ends. Name the group with aria-label, and say whose message it answers when there are several on the screen.

#The count

Set --count on each reaction to how many others gave it, not counting the reader. The pill starts its counter there, and the checked box adds one, so a reaction the reader has given shows one more than --count. Leave reaction-count empty and the counter writes the number into it; write text inside it, such as 1.2k, when the number is too large to count by one, and that text is shown instead.

#States

At rest a reaction is a flat pill on one contour, and its count is muted. Under the pointer the contour is firmer; under a press the pill sinks into a well and the emoji is pushed in with it. Given, it takes the library's selected state: an ink hairline, a faint tint of ink and the count in strong ink. A disabled box, such as one in a closed thread, lies flat with its emoji faded.

States

<div class="reaction-group" role="group" aria-label="Reactions">  <label class="reaction" style="--count: 2">    <input type="checkbox" class="reaction-input" name="reaction-states" value="👏" aria-label="Clapping, 2 others">    <span class="reaction-emoji" aria-hidden="true">👏</span>    <span class="reaction-count" aria-hidden="true"></span>  </label>  <label class="reaction" style="--count: 2">    <input type="checkbox" class="reaction-input" name="reaction-states" value="❤️" aria-label="Heart, 2 others" checked>    <span class="reaction-emoji" aria-hidden="true">❤️</span>    <span class="reaction-count" aria-hidden="true"></span>  </label>  <label class="reaction">    <input type="checkbox" class="reaction-input" name="reaction-states" value="🔥" aria-label="Fire, 1,214 others">    <span class="reaction-emoji" aria-hidden="true">🔥</span>    <span class="reaction-count" aria-hidden="true">1.2k</span>  </label>  <label class="reaction" style="--count: 4">    <input type="checkbox" class="reaction-input" name="reaction-states" value="👍" aria-label="Thumbs up, 4 others" disabled>    <span class="reaction-emoji" aria-hidden="true">👍</span>    <span class="reaction-count" aria-hidden="true"></span>  </label></div>
<div className="reaction-group" role="group" aria-label="Reactions">  <label className="reaction" style={{ '--count': '2' } as React.CSSProperties}>    <input type="checkbox" className="reaction-input" name="reaction-states" value="👏" aria-label="Clapping, 2 others" />    <span className="reaction-emoji" aria-hidden="true">👏</span>    <span className="reaction-count" aria-hidden="true"></span>  </label>  <label className="reaction" style={{ '--count': '2' } as React.CSSProperties}>    <input type="checkbox" className="reaction-input" name="reaction-states" value="❤️" aria-label="Heart, 2 others" defaultChecked />    <span className="reaction-emoji" aria-hidden="true">❤️</span>    <span className="reaction-count" aria-hidden="true"></span>  </label>  <label className="reaction">    <input type="checkbox" className="reaction-input" name="reaction-states" value="🔥" aria-label="Fire, 1,214 others" />    <span className="reaction-emoji" aria-hidden="true">🔥</span>    <span className="reaction-count" aria-hidden="true">1.2k</span>  </label>  <label className="reaction" style={{ '--count': '4' } as React.CSSProperties}>    <input type="checkbox" className="reaction-input" name="reaction-states" value="👍" aria-label="Thumbs up, 4 others" disabled />    <span className="reaction-emoji" aria-hidden="true">👍</span>    <span className="reaction-count" aria-hidden="true"></span>  </label></div>
<div class="reaction-group" role="group" aria-label="Reactions">  <label class="reaction" style="--count: 2">    <input type="checkbox" class="reaction-input" name="reaction-states" value="👏" aria-label="Clapping, 2 others">    <span class="reaction-emoji" aria-hidden="true">👏</span>    <span class="reaction-count" aria-hidden="true"></span>  </label>  <label class="reaction" style="--count: 2">    <input type="checkbox" class="reaction-input" name="reaction-states" value="❤️" aria-label="Heart, 2 others" checked>    <span class="reaction-emoji" aria-hidden="true">❤️</span>    <span class="reaction-count" aria-hidden="true"></span>  </label>  <label class="reaction">    <input type="checkbox" class="reaction-input" name="reaction-states" value="🔥" aria-label="Fire, 1,214 others">    <span class="reaction-emoji" aria-hidden="true">🔥</span>    <span class="reaction-count" aria-hidden="true">1.2k</span>  </label>  <label class="reaction" style="--count: 4">    <input type="checkbox" class="reaction-input" name="reaction-states" value="👍" aria-label="Thumbs up, 4 others" disabled>    <span class="reaction-emoji" aria-hidden="true">👍</span>    <span class="reaction-count" aria-hidden="true"></span>  </label></div>
<template>  <div class="reaction-group" role="group" aria-label="Reactions">    <label class="reaction" style="--count: 2">      <input type="checkbox" class="reaction-input" name="reaction-states" value="👏" aria-label="Clapping, 2 others">      <span class="reaction-emoji" aria-hidden="true">👏</span>      <span class="reaction-count" aria-hidden="true"></span>    </label>    <label class="reaction" style="--count: 2">      <input type="checkbox" class="reaction-input" name="reaction-states" value="❤️" aria-label="Heart, 2 others" checked>      <span class="reaction-emoji" aria-hidden="true">❤️</span>      <span class="reaction-count" aria-hidden="true"></span>    </label>    <label class="reaction">      <input type="checkbox" class="reaction-input" name="reaction-states" value="🔥" aria-label="Fire, 1,214 others">      <span class="reaction-emoji" aria-hidden="true">🔥</span>      <span class="reaction-count" aria-hidden="true">1.2k</span>    </label>    <label class="reaction" style="--count: 4">      <input type="checkbox" class="reaction-input" name="reaction-states" value="👍" aria-label="Thumbs up, 4 others" disabled>      <span class="reaction-emoji" aria-hidden="true">👍</span>      <span class="reaction-count" aria-hidden="true"></span>    </label>  </div></template>

#Adding a reaction

reaction-add is a round button at the end of the row, with a face and a plus, that opens the page's emoji picker: a popover of quiet square buttons, each holding a reaction-emoji. The button stays sunk while the popover right after it is open. Choosing an emoji gives that reaction, and adds its pill when nobody has given it yet; that last step is the page's, so the picker needs a few lines of script. Everything else on this page works without one.

Adding a reaction

<div class="reaction-group" id="reactions" role="group" aria-label="Reactions">  <label class="reaction" style="--count: 4">    <input type="checkbox" class="reaction-input" name="reaction" value="👍" aria-label="Thumbs up, 4 others">    <span class="reaction-emoji" aria-hidden="true">👍</span>    <span class="reaction-count" aria-hidden="true"></span>  </label>  <label class="reaction" style="--count: 1">    <input type="checkbox" class="reaction-input" name="reaction" value="🚀" aria-label="Rocket, 1 other">    <span class="reaction-emoji" aria-hidden="true">🚀</span>    <span class="reaction-count" aria-hidden="true"></span>  </label>  <button type="button" class="reaction-add" popovertarget="reaction-picker" aria-label="Add a reaction"></button>  <div class="popover p(4)" id="reaction-picker" popover>    <div class="grid grid-cols(6) gap(2)">      <button type="button" class="btn btn-quiet btn-square btn-sm" value="👍" aria-label="Thumbs up">        <span class="reaction-emoji" aria-hidden="true">👍</span>      </button>      <button type="button" class="btn btn-quiet btn-square btn-sm" value="❤️" aria-label="Heart">        <span class="reaction-emoji" aria-hidden="true">❤️</span>      </button>      <button type="button" class="btn btn-quiet btn-square btn-sm" value="😂" aria-label="Laughing">        <span class="reaction-emoji" aria-hidden="true">😂</span>      </button>      <button type="button" class="btn btn-quiet btn-square btn-sm" value="🎉" aria-label="Party popper">        <span class="reaction-emoji" aria-hidden="true">🎉</span>      </button>      <button type="button" class="btn btn-quiet btn-square btn-sm" value="👀" aria-label="Eyes">        <span class="reaction-emoji" aria-hidden="true">👀</span>      </button>      <button type="button" class="btn btn-quiet btn-square btn-sm" value="🚀" aria-label="Rocket">        <span class="reaction-emoji" aria-hidden="true">🚀</span>      </button>    </div>  </div></div><script>const picker = document.getElementById('reaction-picker')const reactions = document.getElementById('reactions')picker.addEventListener('click', function (event) {  const option = event.target.closest('button')  if (!option) return  let input = Array.from(reactions.querySelectorAll('.reaction-input')).find(function (each) { return each.value === option.value })  if (!input) {    const reaction = document.createElement('label')    const emoji = document.createElement('span')    const count = document.createElement('span')    input = document.createElement('input')    reaction.className = 'reaction'    input.type = 'checkbox'    input.className = 'reaction-input'    input.name = 'reaction'    input.value = option.value    input.setAttribute('aria-label', option.getAttribute('aria-label') + ', no others')    emoji.className = 'reaction-emoji'    emoji.textContent = option.value    emoji.setAttribute('aria-hidden', 'true')    count.className = 'reaction-count'    count.setAttribute('aria-hidden', 'true')    reaction.append(input, emoji, count)    reactions.insertBefore(reaction, reactions.querySelector('.reaction-add'))  }  if (!input.checked) input.click()  picker.hidePopover()})</script>
Open the picker and choose an emoji that is not in the row yet.

#In a thread

In a thread the row follows the words of a comment, a little further from them than one paragraph from the next.

In a thread

<div class="card max-w(480) mx-auto">  <ol class="thread">    <li class="thread-item">      <span class="thread-avatar"><span class="avatar">GH</span></span>      <div class="thread-body">        <p class="thread-header">          <span class="thread-author">Grace Hopper</span>          <time class="thread-meta" datetime="2026-11-12T09:12">2h</time>        </p>        <p class="thread-text">          The contracts ship on Tuesday, the framework components the week after.        </p>        <div class="reaction-group" role="group" aria-label="Reactions to Grace Hopper's comment">          <label class="reaction" style="--count: 5">            <input type="checkbox" class="reaction-input" name="reaction-thread" value="👍" aria-label="Thumbs up, 5 others">            <span class="reaction-emoji" aria-hidden="true">👍</span>            <span class="reaction-count" aria-hidden="true"></span>          </label>          <label class="reaction" style="--count: 2">            <input type="checkbox" class="reaction-input" name="reaction-thread" value="🚀" aria-label="Rocket, 2 others" checked>            <span class="reaction-emoji" aria-hidden="true">🚀</span>            <span class="reaction-count" aria-hidden="true"></span>          </label>        </div>      </div>      <ol class="thread-replies">        <li class="thread-item">          <span class="thread-avatar"><span class="avatar avatar-sm">AL</span></span>          <div class="thread-body">            <p class="thread-header">              <span class="thread-author">Ada Lovelace</span>              <time class="thread-meta" datetime="2026-11-12T10:05">1h</time>            </p>            <p class="thread-text">Then the release notes go out on Monday.</p>          </div>        </li>      </ol>    </li>  </ol></div>
<div className="card max-w(480) mx-auto">  <ol className="thread">    <li className="thread-item">      <span className="thread-avatar"><span className="avatar">GH</span></span>      <div className="thread-body">        <p className="thread-header">          <span className="thread-author">Grace Hopper</span>          <time className="thread-meta" dateTime="2026-11-12T09:12">2h</time>        </p>        <p className="thread-text">          The contracts ship on Tuesday, the framework components the week after.        </p>        <div className="reaction-group" role="group" aria-label="Reactions to Grace Hopper's comment">          <label className="reaction" style={{ '--count': '5' } as React.CSSProperties}>            <input type="checkbox" className="reaction-input" name="reaction-thread" value="👍" aria-label="Thumbs up, 5 others" />            <span className="reaction-emoji" aria-hidden="true">👍</span>            <span className="reaction-count" aria-hidden="true"></span>          </label>          <label className="reaction" style={{ '--count': '2' } as React.CSSProperties}>            <input type="checkbox" className="reaction-input" name="reaction-thread" value="🚀" aria-label="Rocket, 2 others" defaultChecked />            <span className="reaction-emoji" aria-hidden="true">🚀</span>            <span className="reaction-count" aria-hidden="true"></span>          </label>        </div>      </div>      <ol className="thread-replies">        <li className="thread-item">          <span className="thread-avatar"><span className="avatar avatar-sm">AL</span></span>          <div className="thread-body">            <p className="thread-header">              <span className="thread-author">Ada Lovelace</span>              <time className="thread-meta" dateTime="2026-11-12T10:05">1h</time>            </p>            <p className="thread-text">Then the release notes go out on Monday.</p>          </div>        </li>      </ol>    </li>  </ol></div>
<div class="card max-w(480) mx-auto">  <ol class="thread">    <li class="thread-item">      <span class="thread-avatar"><span class="avatar">GH</span></span>      <div class="thread-body">        <p class="thread-header">          <span class="thread-author">Grace Hopper</span>          <time class="thread-meta" datetime="2026-11-12T09:12">2h</time>        </p>        <p class="thread-text">          The contracts ship on Tuesday, the framework components the week after.        </p>        <div class="reaction-group" role="group" aria-label="Reactions to Grace Hopper's comment">          <label class="reaction" style="--count: 5">            <input type="checkbox" class="reaction-input" name="reaction-thread" value="👍" aria-label="Thumbs up, 5 others">            <span class="reaction-emoji" aria-hidden="true">👍</span>            <span class="reaction-count" aria-hidden="true"></span>          </label>          <label class="reaction" style="--count: 2">            <input type="checkbox" class="reaction-input" name="reaction-thread" value="🚀" aria-label="Rocket, 2 others" checked>            <span class="reaction-emoji" aria-hidden="true">🚀</span>            <span class="reaction-count" aria-hidden="true"></span>          </label>        </div>      </div>      <ol class="thread-replies">        <li class="thread-item">          <span class="thread-avatar"><span class="avatar avatar-sm">AL</span></span>          <div class="thread-body">            <p class="thread-header">              <span class="thread-author">Ada Lovelace</span>              <time class="thread-meta" datetime="2026-11-12T10:05">1h</time>            </p>            <p class="thread-text">Then the release notes go out on Monday.</p>          </div>        </li>      </ol>    </li>  </ol></div>
<template>  <div class="card max-w(480) mx-auto">    <ol class="thread">      <li class="thread-item">        <span class="thread-avatar"><span class="avatar">GH</span></span>        <div class="thread-body">          <p class="thread-header">            <span class="thread-author">Grace Hopper</span>            <time class="thread-meta" datetime="2026-11-12T09:12">2h</time>          </p>          <p class="thread-text">            The contracts ship on Tuesday, the framework components the week after.          </p>          <div class="reaction-group" role="group" aria-label="Reactions to Grace Hopper's comment">            <label class="reaction" style="--count: 5">              <input type="checkbox" class="reaction-input" name="reaction-thread" value="👍" aria-label="Thumbs up, 5 others">              <span class="reaction-emoji" aria-hidden="true">👍</span>              <span class="reaction-count" aria-hidden="true"></span>            </label>            <label class="reaction" style="--count: 2">              <input type="checkbox" class="reaction-input" name="reaction-thread" value="🚀" aria-label="Rocket, 2 others" checked>              <span class="reaction-emoji" aria-hidden="true">🚀</span>              <span class="reaction-count" aria-hidden="true"></span>            </label>          </div>        </div>        <ol class="thread-replies">          <li class="thread-item">            <span class="thread-avatar"><span class="avatar avatar-sm">AL</span></span>            <div class="thread-body">              <p class="thread-header">                <span class="thread-author">Ada Lovelace</span>                <time class="thread-meta" datetime="2026-11-12T10:05">1h</time>              </p>              <p class="thread-text">Then the release notes go out on Monday.</p>            </div>          </li>        </ol>      </li>    </ol>  </div></template>

#Accessibility

  • Name each checkbox with the emoji and the others' count in words, such as aria-label="Thumbs up, 3 others", and hide the emoji and the count with aria-hidden="true". The checked state then says whether the reader is one of them, and the name stays true after every press.
  • Do not rely on the drawn count being read. Engines leave text written by a CSS counter out of an accessible name and description: in Chromium the box is named by its label's words without the number.
  • Name the group, and name reaction-add ("Add a reaction"). Each button of the picker is named with its emoji's name, and its emoji is hidden.
  • The pill is the target: 28px, and on a touch screen the target reaches 44px around a pill that keeps its size. In forced colors it keeps an outline, and a given reaction a thicker one in the highlight color.

#Platform notes

The count's figures are trimmed to their cap height with text-box: trim-both cap alphabetic, so the pill centers the figures rather than the line around them, level with the middle of the emoji. Without it they stand within half a pixel of the middle. text-box is in Chromium and Safari.

#Classes

ClassDescription
reaction-groupThe row of reactions, on an element with role="group" and a name. It wraps; under a message it stands where the bubble does, and in a thread under the words
reactionOne reaction: a 28px pill around a reaction-input, an emoji and a count. Set --count to the reactions of everyone but the reader
reaction-inputThe checkbox that holds the reader's own reaction. It covers the pill invisibly; name it with the emoji and the others' count, such as "Thumbs up, 3 others"
reaction-emojiThe emoji: a character in a span, or a picture with the class on the img. Hide it from assistive technology when the input is named. Also the emoji of a picker's button
reaction-countThe count, written by the counter when the element is empty: --count, and one more while the reader's reaction is given. Text inside it, such as 1.2k, is shown instead
reaction-addA round button at the end of the row, with a face and a plus, that opens the page's emoji picker; it stays sunk while a popover right after it is open

#Custom properties

PropertyDefaultDescription
--count0How many others gave this reaction; the reader's own is added while the box is checkedSet on reaction

#Source

@master/ui/components/reaction.css
/* * Reaction: an emoji answer to a message, with how many gave it. * Each reaction is a <label> around a native checkbox, so a press, Space and the form all work as they do for a * checkbox. The count is a CSS counter: the pill starts it at --count, the reactions of everyone else, and a * checked box adds one, so the number is right after every press with no script. Engines leave a counter out of * an accessible name, so the box is named in words (the emoji and the others' count) and the pill's drawing is * hidden from assistive technology; the checked state says whether the reader is one of them. * At rest a reaction is a flat pill of the chip tone on one contour; under a press it sinks into a well and the * emoji is pushed in with it; given, it takes the selected language of the library: an ink hairline, a faint * tint of ink and the count in strong ink. * Geometry: a 28px pill with true half circles at its ends; on a touch screen its target reaches 44px above and below it. The emoji is 16px and stands * as far from the start as from the top and bottom, so it is concentric with the round end; the count's figures * are tabular, and trimmed to their cap height where text-box is supported, so flex centres the figures rather * than the line around them (elsewhere they stand within half a pixel of the middle). * A count written in the markup (1.2k) replaces the counter, for numbers too large to count by one. * Under a message the row stands under the bubble, and in a thread under the words. */@layer components.ui {  /* The row of reactions, with the button that adds one at its end. */  .reaction-group {    display: flex;    flex-wrap: wrap;    align-items: center;    gap: .375rem;    min-width: 0;    margin: 0;    padding: 0;    border: 0;    /*     * A finger's target reaches 8px over and under a pill. Rows that wrap stand that far apart twice over, so     * a target of the second row does not lie on the foot of the pill above it; one row is drawn as it was.     */    @media (pointer: coarse) {      row-gap: 1rem;    }  }  /* Under a message the row stands where the bubble does: at the start of a received row, at the end of a sent one. */  .message .reaction-group {    grid-column: 2;    margin-block-start: .125rem;  }  .message-sent .reaction-group {    grid-column: 1;    justify-content: flex-end;  }  .message:not(.message-sent, :has(.message-avatar)) .reaction-group {    grid-column: 1 / -1;  }  /* In a thread it follows the words, a little further from them than one paragraph from the next. */  .thread-body .reaction-group {    margin-block-start: .375rem;  }  .reaction {    --reaction-height: 1.75rem;    --reaction-emoji-size: 1rem;    --count: 0;    position: relative;    display: inline-flex;    flex: none;    align-items: center;    gap: .25rem;    height: var(--reaction-height);    margin: 0;    padding-block: 0;    padding-inline: calc((var(--reaction-height) - var(--reaction-emoji-size)) / 2) .5rem;    border-radius: 999px;    corner-shape: round;    background: var(--color-surface-chip);    color: var(--color-text-muted);    box-shadow: inset 0 0 0 .5px var(--color-line-contour);    font: var(--font-weight-control) .78125rem/1 var(--font-family-sans);    font-feature-settings: inherit;    font-variant-numeric: tabular-nums;    white-space: nowrap;    vertical-align: middle;    counter-reset: reaction var(--count);    user-select: none;    -webkit-user-select: none;    -webkit-tap-highlight-color: transparent;    cursor: pointer;    touch-action: manipulation;    transition-property: background-color, box-shadow, color;    transition-duration: var(--duration-quick);    transition-timing-function: var(--easing-glide);    @media (hover: hover) {      &:hover:not(:has(.reaction-input:disabled)) {        color: var(--color-text-body);        box-shadow: inset 0 0 0 .5px var(--color-line-mark);      }    }    /* Given: the reader's own reaction is counted, and the pill takes an ink hairline over a faint tint of ink. */    &:has(.reaction-input:checked) {      counter-increment: reaction;      background: color-mix(in oklab, var(--color-text-strong) 10%, transparent);      color: var(--color-text-strong);      box-shadow: inset 0 0 0 .5px var(--color-text-strong), 0 0 0 .5px color-mix(in oklab, var(--color-text-strong) 22%, transparent);      @media (hover: hover) {        &:hover:not(:has(.reaction-input:disabled)) {          background: color-mix(in oklab, var(--color-text-strong) 13%, transparent);          color: var(--color-text-strong);          box-shadow: inset 0 0 0 .5px var(--color-text-strong), 0 0 0 .5px color-mix(in oklab, var(--color-text-strong) 22%, transparent);        }      }    }    /*     * Pressed: the pill sinks into a well and the emoji is pushed in with it, given or not, so a tap is     * answered before the state changes.     */    &:active:not(:has(.reaction-input:disabled)) {      background: var(--color-surface-inset);      box-shadow: var(--shadow-pressed);      transition-duration: var(--duration-press);      .reaction-emoji {        scale: .88;        transition-duration: var(--duration-press);      }    }    &:has(.reaction-input:focus-visible) {      @apply --focus-ring;    }    &:has(.reaction-input:disabled) {      background: var(--color-surface-inset);      color: var(--color-text-disabled);      box-shadow: var(--shadow-flat);      cursor: not-allowed;      .reaction-emoji {        opacity: .6;      }    }    /* Given and disabled: the hairline stays, in the disabled ink, so the reader still sees the reaction is theirs. */    &:has(.reaction-input:checked:disabled) {      box-shadow: inset 0 0 0 .5px var(--color-text-disabled);    }    /* As specific as the press above, so it is not overruled by it. */    @media (prefers-reduced-motion: reduce) {      &:active:not(:has(.reaction-input:disabled)) .reaction-emoji {        scale: none;      }    }    /*     * Reactions stand 6px apart, closer than the 8px a 44px target would reach to the side: on touch a pill's     * target grows above and below only, so it never takes a tap meant for its neighbor. The pill keeps its size.     */    @media (pointer: coarse) {      &::after {        @apply --touch-target-block;      }    }    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;      &:has(.reaction-input:checked):not(:has(.reaction-input:focus-visible)) {        outline: 2px solid Highlight;        outline-offset: -2px;      }      &:has(.reaction-input:focus-visible) {        outline: 2px solid Highlight;        outline-offset: 2px;      }      &:has(.reaction-input:disabled) {        outline-color: GrayText;        color: GrayText;      }    }  }  /* The checkbox covers the pill invisibly: the label is the target, the input keeps the state. */  .reaction-input {    position: absolute;    inset: 0;    width: 100%;    height: 100%;    margin: 0;    padding: 0;    border: 0;    border-radius: inherit;    corner-shape: inherit;    opacity: 0;    appearance: none;    cursor: inherit;  }  /* The emoji, a character or a picture, in a square as tall as its font; also an option of the picker. */  .reaction-emoji {    display: inline-grid;    flex: none;    place-items: center;    width: var(--reaction-emoji-size, 1rem);    height: var(--reaction-emoji-size, 1rem);    font-size: var(--reaction-emoji-size, 1rem);    line-height: 1;    transition: scale var(--duration-quick) var(--easing-glide);  }  /* The count, from the counter; text written inside it is shown instead. */  .reaction-count {    min-width: 1ch;    text-align: center;    /* Trimmed to its figures, so flex centres the figures and not the line around them. */    text-box: trim-both cap alphabetic;    &:empty::before {      content: counter(reaction);    }  }  /*   * Add a reaction: a round button of the same pill, with a face and a plus. It opens the page's emoji picker,   * a popover, which adds the chosen reaction.   */  .reaction-add {    --reaction-height: 1.75rem;    position: relative;    display: inline-grid;    flex: none;    place-items: center;    width: var(--reaction-height);    height: var(--reaction-height);    margin: 0;    padding: 0;    border: 0;    border-radius: 999px;    corner-shape: round;    background: var(--color-surface-chip);    color: var(--color-text-muted);    box-shadow: inset 0 0 0 .5px var(--color-line-contour);    appearance: none;    -webkit-tap-highlight-color: transparent;    cursor: pointer;    touch-action: manipulation;    transition-property: background-color, box-shadow, color;    transition-duration: var(--duration-quick);    transition-timing-function: var(--easing-glide);    &::before {      content: '';      width: 1rem;      height: 1rem;      background: currentColor;      mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M13.07 5.27A8 8 0 1 0 18.73 10.93M19.5 2v5M17 4.5h5M8 15.5q3 2.5 6 0'/%3E%3Ccircle cx='8.5' cy='11' r='1' fill='black' stroke='none'/%3E%3Ccircle cx='13.5' cy='11' r='1' fill='black' stroke='none'/%3E%3C/svg%3E") center / contain no-repeat;    }    @media (hover: hover) {      &:hover:not(:disabled) {        color: var(--color-text-strong);        box-shadow: inset 0 0 0 .5px var(--color-line-mark);      }    }    &:active:not(:disabled), &:has(+ .popover:popover-open) {      background: var(--color-surface-inset);      color: var(--color-text-strong);      box-shadow: var(--shadow-pressed);    }    &:active:not(:disabled) {      transition-duration: var(--duration-press);    }    &:focus-visible {      @apply --focus-ring;    }    /* Disabled: the flat well of a reaction that cannot be given. */    &:disabled {      background: var(--color-surface-inset);      color: var(--color-text-disabled);      box-shadow: var(--shadow-flat);      cursor: not-allowed;    }    /*     * It stands 6px after the last reaction, closer than the 8px a 44px target would reach to the side: on touch     * its target grows above and below only, and keeps its 28px width, so it never takes a tap meant for the pill.     */    @media (pointer: coarse) {      &::after {        @apply --touch-target-block;      }    }    @media (forced-colors: active) {      outline: 1px solid ButtonText;      outline-offset: -1px;      &::before {        background: ButtonText;      }      /* The well it sinks into while the picker is open is gone with its shadow: a firmer outline keeps it. */      &:has(+ .popover:popover-open):not(:focus-visible) {        outline: 2px solid Highlight;        outline-offset: -2px;      }      &:disabled {        outline-color: GrayText;        &::before {          background: GrayText;        }      }    }  }}