Navigation

v2.1.0
Content

Presence

Another person's pointer, caret or selection, in the color that names them.

On this page

Presence shows where the other people working on the same thing are: their pointers on a canvas or a board, their carets and selections in text. Each person is drawn in one identity color, with their name beside it, so a reader can tell who is where at a glance. Add presence and the person's identity, presence-1 to presence-8, to an element that holds a presence-name, inside the positioned element the pointers move over, and set where it stands with --presence-x and --presence-y.

Presence

<div class="sheet relative overflow-hidden w-full max-w(520) h(264)" id="board">  <div class="texture texture-grid absolute inset(0)"></div>  <div class="sheet sheet-raised absolute p-md text-sm w(168)" style="top: 32px; left: 28px">    <p class="m(0) fg-text-strong">Launch checklist</p>    <p class="m(0) mt-xs fg-text-muted">Docs, changelog and the post</p>  </div>  <div class="sheet sheet-raised absolute p-md text-sm w(168)" style="top: 128px; left: 260px">    <p class="m(0) fg-text-strong">Open questions</p>    <p class="m(0) mt-xs fg-text-muted">Who writes the release notes?</p>  </div>  <div class="presence presence-6" style="--presence-x: 150px; --presence-y: 78px" aria-hidden="true">    <span class="presence-name">Ada Lovelace</span>  </div>  <div class="presence presence-4" id="moving" style="--presence-x: 340px; --presence-y: 40px" aria-hidden="true">    <span class="presence-name">Alan Turing</span>  </div>  <div class="presence presence-8" style="--presence-x: 96px; --presence-y: 176px" aria-hidden="true">    <span class="presence-name">Grace Hopper</span>    <span class="presence-message">I can take the release notes</span>  </div></div><script>const pointer = document.getElementById('moving')const path = [[340, 40], [372, 64], [398, 108], [360, 150], [318, 132], [300, 84]]let at = 0setInterval(() => {  at = (at + 1) % path.length  pointer.style.setProperty('--presence-x', path[at][0] + 'px')  pointer.style.setProperty('--presence-y', path[at][1] + 'px')}, 700)</script>
Three people on a board. Alan's pointer moves as the application reports it, and glides between the points it is given; with reduced motion it jumps.

#Where a pointer stands

A pointer's tip is the point. --presence-x and --presence-y are its distance, in pixels, from the top-left corner of the nearest positioned element, usually the canvas or the board, which takes relative and overflow-hidden so a pointer near its edge is cut there. The application knows where each person is and when they leave: it adds a presence when someone arrives, sets the two properties as their pointer moves, and removes it when they go. The stylesheet does the drawing and the motion; there is no script of its own.

app.js
function move(person, x, y) {  const pointer = board.querySelector(`[data-person="${person.id}"]`)  pointer.style.setProperty('--presence-x', `${x}px`)  pointer.style.setProperty('--presence-y', `${y}px`)}
  • Motion. A pointer glides to each new point in a straight line for 160ms, which turns the few positions a second a connection delivers into steady movement. With prefers-reduced-motion: reduce it jumps.
  • Out of the way. A pointer takes no pointer event, so it never stands between the reader's own pointer and what is under it.
  • Coordinates. Send them in the canvas's own units and convert them to the reader's view before setting the properties, so two people with different window sizes and zoom levels point at the same thing.

#A message

A presence-message under the name holds a few words the person is writing, as cursor chat does: a question about the thing they are pointing at. It wraps at 15rem. Remove it a few seconds after they stop writing.

#Identity colors

Hue in Master UI says a status, and here, a person. The theme has eight identity colors, --color-identity-1 to --color-identity-8, all at one lightness: a person keeps one of them for the session, and their name always stands beside it, so the color is never the only way to tell people apart. --color-identity-ink is the text on every one of them, at a contrast of at least 4.8:1 in the light scheme and 9:1 in the dark one.

Choose one with a modifier, presence-1 to presence-8, on a pointer, a caret, a selection or a name that stands alone. A product with colors of its own for people sets --presence-color instead; give it one of a lightness that --color-identity-ink reads on, or set that token too.

Identity colors

<span class="presence-name presence-1">Ada</span><span class="presence-name presence-2">Alan</span><span class="presence-name presence-3">Grace</span><span class="presence-name presence-4">Edsger</span><span class="presence-name presence-5">Barbara</span><span class="presence-name presence-6">Donald</span><span class="presence-name presence-7">Margaret</span><span class="presence-name presence-8">Ken</span>
<>  <span className="presence-name presence-1">Ada</span>  <span className="presence-name presence-2">Alan</span>  <span className="presence-name presence-3">Grace</span>  <span className="presence-name presence-4">Edsger</span>  <span className="presence-name presence-5">Barbara</span>  <span className="presence-name presence-6">Donald</span>  <span className="presence-name presence-7">Margaret</span>  <span className="presence-name presence-8">Ken</span></>
<span class="presence-name presence-1">Ada</span><span class="presence-name presence-2">Alan</span><span class="presence-name presence-3">Grace</span><span class="presence-name presence-4">Edsger</span><span class="presence-name presence-5">Barbara</span><span class="presence-name presence-6">Donald</span><span class="presence-name presence-7">Margaret</span><span class="presence-name presence-8">Ken</span>
<template>  <span class="presence-name presence-1">Ada</span>  <span class="presence-name presence-2">Alan</span>  <span class="presence-name presence-3">Grace</span>  <span class="presence-name presence-4">Edsger</span>  <span class="presence-name presence-5">Barbara</span>  <span class="presence-name presence-6">Donald</span>  <span class="presence-name presence-7">Margaret</span>  <span class="presence-name presence-8">Ken</span></template>
The eight identities, in the order a session hands them out.

Hand the colors out in this order as people arrive, and give the color of someone who left to the next to come. Choose from a stable number, such as a hash of the person's id, when every reader must see the same person in the same color. With more than eight people, colors repeat; the names still tell them apart.

#In text

In a document edited together, another person's caret is a presence-caret between two letters: a 2px bar in their color, as tall as the line, with their name in a flag that stands on it. It takes no room, so the words around it do not move as it does. Their selection is a presence-selection around the words they selected: a tint of their color behind the words, carried across lines.

A caret and a selection

<div class="sheet p-lg max-w(440)">  <p class="m(0) text-sm fg-text-body leading-md">    The release ships <span class="presence-selection presence-4">on Thursday, after the docs build</span><span class="presence-caret presence-4" aria-hidden="true">      <span class="presence-name">Alan</span>    </span> passes, and the post goes out the same afternoon. Ada writes the changelog<span class="presence-caret presence-6" aria-hidden="true">      <span class="presence-name">Ada</span>    </span> while Grace checks the links.  </p></div>
<div className="sheet p-lg max-w(440)">  <p className="m(0) text-sm fg-text-body leading-md">    The release ships <span className="presence-selection presence-4">on Thursday, after the docs build</span><span className="presence-caret presence-4" aria-hidden="true">      <span className="presence-name">Alan</span>    </span> passes, and the post goes out the same afternoon. Ada writes the changelog<span className="presence-caret presence-6" aria-hidden="true">      <span className="presence-name">Ada</span>    </span> while Grace checks the links.  </p></div>
<div class="sheet p-lg max-w(440)">  <p class="m(0) text-sm fg-text-body leading-md">    The release ships <span class="presence-selection presence-4">on Thursday, after the docs build</span><span class="presence-caret presence-4" aria-hidden="true">      <span class="presence-name">Alan</span>    </span> passes, and the post goes out the same afternoon. Ada writes the changelog<span class="presence-caret presence-6" aria-hidden="true">      <span class="presence-name">Ada</span>    </span> while Grace checks the links.  </p></div>
<template>  <div class="sheet p-lg max-w(440)">    <p class="m(0) text-sm fg-text-body leading-md">      The release ships <span class="presence-selection presence-4">on Thursday, after the docs build</span><span class="presence-caret presence-4" aria-hidden="true">        <span class="presence-name">Alan</span>      </span> passes, and the post goes out the same afternoon. Ada writes the changelog<span class="presence-caret presence-6" aria-hidden="true">        <span class="presence-name">Ada</span>      </span> while Grace checks the links.    </p>  </div></template>
Alan has selected a phrase and his caret stands at its end; Ada's caret stands where she is typing.

The editor puts these marks where its collaboration layer says the other people are, as decorations it renders and removes; they are not part of the document. Leave room above the first line for a name flag, or let the flag of a caret on the first line run into the padding of what holds the text.

#When to use something else

  • Who is here, rather than where, is a pile of avatars in the header.
  • The mark at the end of text the application is still writing is a caret.
  • Words highlighted for the reader, such as a search match, are a mark.

#Accessibility

  • Pointers and carets are decoration: give each aria-hidden="true", so their names are not read in the middle of a canvas or a sentence. Say who is here in words elsewhere, such as the avatars in the header with their names, and announce arrivals and departures in a polite live region if they matter to the task.
  • A selection is not hidden: the words in it are the document's. The tint does not change the words' color, so they keep their contrast.
  • A color is never the only clue: the name stands beside every pointer and caret.
  • In forced colors the arrows and the caret are drawn in system colors, and the flags and bubbles get an outline.

#Classes

ClassDescription
presenceA pointer: an arrow whose tip stands at --presence-x and --presence-y in the positioned element that holds it, in the person's identity color. It glides to each new point and takes no pointer event
presence-nameThe person's name, in a flag of their color with the identity ink: beside the arrow's tip, standing on a caret, or on its own in a list of who is here
presence-messageA short message the person is writing, in a bubble of their color under the name
presence-caretAnother person's caret in text: an inline bar as tall as the line, in their identity color, that takes no room. A presence-name inside it stands on top of it
presence-selectionAnother person's selection: a tint of their identity color behind the words it holds, carried across lines
presence-1Identity 1, --color-identity-1: red in hue. Without a modifier or --presence-color, a presence takes this oneApply with presence or presence-caret or presence-selection or presence-name
presence-2Identity 2, --color-identity-2: orange in hueApply with presence or presence-caret or presence-selection or presence-name
presence-3Identity 3, --color-identity-3: amber in hueApply with presence or presence-caret or presence-selection or presence-name
presence-4Identity 4, --color-identity-4: green in hueApply with presence or presence-caret or presence-selection or presence-name
presence-5Identity 5, --color-identity-5: teal in hueApply with presence or presence-caret or presence-selection or presence-name
presence-6Identity 6, --color-identity-6: blue in hueApply with presence or presence-caret or presence-selection or presence-name
presence-7Identity 7, --color-identity-7: violet in hueApply with presence or presence-caret or presence-selection or presence-name
presence-8Identity 8, --color-identity-8: pink in hueApply with presence or presence-caret or presence-selection or presence-name

#Custom properties

PropertyDefaultDescription
--presence-colorvar(--color-identity-1)The person's color. A presence-1 to presence-8 modifier sets it to an identity; set it for a color of the product's own. Read by a presence, a presence-caret, a presence-selection and a presence-name
--presence-x0pxWhere the arrow's tip stands, from the left edge of the positioned element that holds it. The application sets it
--presence-y0pxWhere the arrow's tip stands, from the top edge of that element. The application sets it
--presence-arrow1.25remThe size of the arrow; the name stands beside its point

#Source

@master/ui/components/presence.css
/* * Presence: where another person is, drawn in the color that names them. * A pointer is an arrow standing at the point the page gives it, with the person's name in a flag down and to * the side of its tip and, when they write one, a short message in a bubble under the name. In text, another * person's caret is a 2px bar in the line with their name above it, and their selection is a tint of their color * behind the words. * The color is the person's identity: one of --color-identity-1 to 8, chosen with presence-1 to presence-8, * or any color set as --presence-color. Every identity takes --color-identity-ink as its text. Hue means a * person here and nothing else. * Geometry: a 20px arrow whose tip is the point, cut out of the page by a ring of the identity ink so it reads * on any content; a 12px name in a flag with the chip's corner; a 13px message in a bubble with the control's * corner, at most 15rem wide. The flag and the bubble stand on the page with the raised shadow. * Coordinates and presence are the application's: it sets --presence-x and --presence-y, in pixels from the * top-left corner of the positioned element that holds the pointers, and adds and removes the elements. A * pointer glides to each new point and jumps under reduced motion. Nothing here takes a pointer event, so a * pointer never stands in the way of the reader's own. */@layer components.ui {  .presence {    --presence-color: var(--color-identity-1);    --presence-x: 0px;    --presence-y: 0px;    --presence-arrow: 1.25rem;    position: absolute;    top: 0;    left: 0;    z-index: 1;    display: flex;    flex-direction: column;    align-items: flex-start;    gap: .25rem;    width: max-content;    max-width: 15rem;    /* The flag starts under the arrow's tail, beside its point. */    padding: calc(var(--presence-arrow) * .85) 0 0 calc(var(--presence-arrow) * .6);    translate: var(--presence-x) var(--presence-y);    pointer-events: none;    transition-property: translate;    transition-duration: var(--duration-quick);    transition-timing-function: linear;    /* The point is placed from the left whatever the direction, so right to left the flag still starts beside it. */    &:dir(rtl) {      align-items: flex-end;    }    /*     * The arrow: a ring of the identity ink under a face of the identity color. Its tip, 2 of its 20 units in     * from the corner, is the point.     */    &::before, &::after {      content: '';      position: absolute;      top: calc(var(--presence-arrow) * -.1);      left: calc(var(--presence-arrow) * -.1);      width: var(--presence-arrow);      height: var(--presence-arrow);    }    &::before {      background: var(--color-identity-ink);      mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M2 2 18 8.6 10.6 10.6 8.6 18Z' fill='black' stroke='black' stroke-width='3.5' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;    }    &::after {      background: var(--presence-color, var(--color-identity-1));      mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M2 2 18 8.6 10.6 10.6 8.6 18Z' fill='black' stroke='black' stroke-width='1' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;    }    @media (prefers-reduced-motion: reduce) {      transition-duration: 0s;    }    @media (forced-colors: active) {      &::before, &::after {        forced-color-adjust: none;      }      &::before {        background: Canvas;      }      &::after {        background: CanvasText;      }    }  }  /* The person's name, in a flag of their color. */  .presence-name {    max-width: 100%;    margin: 0;    padding: .125rem .375rem;    overflow: hidden;    border-radius: calc(var(--radius-chip) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: var(--presence-color, var(--color-identity-1));    color: var(--color-identity-ink);    box-shadow: 0 0 0 .5px var(--color-line-on-color), 0 1px 2px -1px var(--color-shade-1), 0 2px 4px -2px var(--color-shade-2), 0 4px 8px -4px var(--color-shade-3);    font: var(--font-weight-control) .75rem/1.35 var(--font-family-sans);    font-feature-settings: inherit;    letter-spacing: 0;    text-overflow: ellipsis;    white-space: nowrap;    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;    }  }  /* What the person is saying, in a bubble under the name: a few words, as cursor chat has them. */  .presence-message {    max-width: 100%;    margin: 0;    padding: .375rem .625rem;    border-radius: calc(var(--radius-control) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: var(--presence-color, var(--color-identity-1));    color: var(--color-identity-ink);    box-shadow: 0 0 0 .5px var(--color-line-on-color), 0 1px 2px -1px var(--color-shade-1), 0 2px 4px -2px var(--color-shade-2), 0 4px 8px -4px var(--color-shade-3);    font: 400 .8125rem/1.4 var(--font-family-sans);    font-feature-settings: inherit;    text-wrap: pretty;    overflow-wrap: anywhere;    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;    }  }  /*   * Another person's caret in text: an inline mark between two letters, a bar as tall as the line of letters,   * with the name in a flag that stands on it. It takes no room in the line.   */  .presence-caret {    --presence-color: var(--color-identity-1);    position: relative;    display: inline-block;    width: 2px;    height: 1.2em;    margin-inline: -1px;    border-radius: 999px;    corner-shape: round;    background: var(--presence-color, var(--color-identity-1));    vertical-align: -.2em;    pointer-events: none;    .presence-name {      position: absolute;      bottom: 100%;      inset-inline-start: 0;      max-width: 12rem;      padding: 0 .3125rem;      border-end-start-radius: 0;      font-size: .6875rem;      line-height: 1.45;    }    /*     * The bar keeps the system's highlight. forced-color-adjust is inherited, so the name on it is handed back     * to forced colors and drawn as a name standing alone is.     */    @media (forced-colors: active) {      forced-color-adjust: none;      background: Highlight;      .presence-name {        forced-color-adjust: auto;      }    }  }  /*   * The eight identities, by class: presence-1 to presence-8 on a pointer, a caret, a selection or a name   * that stands alone. Naming each token here also keeps it in a stylesheet compiled for the classes a page   * uses. --presence-color takes any other color a product gives a person.   */  :is(.presence, .presence-caret, .presence-selection, .presence-name) {    &.presence-1 {      --presence-color: var(--color-identity-1);    }    &.presence-2 {      --presence-color: var(--color-identity-2);    }    &.presence-3 {      --presence-color: var(--color-identity-3);    }    &.presence-4 {      --presence-color: var(--color-identity-4);    }    &.presence-5 {      --presence-color: var(--color-identity-5);    }    &.presence-6 {      --presence-color: var(--color-identity-6);    }    &.presence-7 {      --presence-color: var(--color-identity-7);    }    &.presence-8 {      --presence-color: var(--color-identity-8);    }  }  /* Another person's selection: a tint of their color behind the words, carried across lines. */  .presence-selection {    --presence-color: var(--color-identity-1);    padding-block: .1em;    border-radius: calc(2px * var(--corner-scale));    corner-shape: var(--corner-shape);    background: color-mix(in oklab, var(--presence-color) 24%, transparent);    color: inherit;    box-decoration-break: clone;    -webkit-box-decoration-break: clone;    @media (forced-colors: active) {      outline: 1px dotted CanvasText;    }  }}