Micro Interactions: UI Examples With Code and Timing Rules | HorizonX
← The Journal

Micro Interactions

Micro Interactions: UI Examples With Code and Timing Rules

Micro interactions are trigger and feedback pairs. UI examples with code, timing rules from NN/g and web.dev, reduced motion and a checklist to judge each one.

HorizonX

HorizonX

November 26, 2026 · 8 min read

Micro Interactions: UI Examples With Code and Timing Rules

Micro interactions are the small pieces of feedback that answer a single action: a save button that confirms the save, a heart that fills when tapped, a field that flags a typo once you leave it. Nielsen Norman Group calls them "trigger-feedback pairs". Good ones respond at once, report a real change of state, and never make the user wait for an animation.

Below are worked examples with code, timing rules taken from published research, and a checklist for deciding whether a micro interaction earns its place. Ready-made versions live in the HorizonX micro-interactions collection.

What counts as a micro interaction

The clearest definition comes from NN/g's article on microinteractions: the trigger "can be a user action or an alteration in the system's state", and the feedback is "a narrowly targeted response to the trigger and is communicated through small, highly contextual (usually visual) changes in the user interface". The same article summarizes their job in one line: they "convey system status, support error prevention, and communicate brand".

That definition gives you a test. NN/g's own table says a button is a micro interaction only sometimes: "If there is no feedback when a user clicks the button, there is no microinteraction." A looping decorative animation is not one either, because nothing triggers it. So the question is never "where can we add motion?" but "which actions currently get no answer?"

The term was popularized by Dan Saffer's 2014 book Microinteractions, which NN/g credits for defining the concept.

How fast the feedback has to be

Two primary sources set the budget:

  • Jakob Nielsen's response time limits: "0.1 second is about the limit for having the user feel that the system is reacting instantaneously". At 1 second the user notices the delay but keeps their train of thought.
  • Google's Interaction to Next Paint metric measures how long a page takes to paint after an interaction. web.dev puts it plainly: "When a page responds to an interaction, the browser presents visual feedback in the next frame that it paints." A good INP is 200 milliseconds or less.

The practical rule follows from both: change the state in the same frame as the click, then let the animation decorate a change that has already happened. Never hold the real result back until an animation ends. The examples below use durations between 120 and 300 ms; that range is this guide's starting point, not a standard, so tune it by watching the interaction repeat.

A trigger, a state change and a short feedback signal drawn as three connected steps

Example 1: a toggle that remembers its state

A save, like or follow button is a toggle. Store the state in aria-pressed and style from that attribute, so what the user sees and what a screen reader announces can never disagree. MDN's aria-pressed reference explains that it "indicates the current 'pressed' state of a toggle button".

<button type="button" class="toggle" aria-pressed="false">
  <svg aria-hidden="true" viewBox="0 0 24 24" width="20" height="20">
    <path d="M12 21 3.5 12.5a5 5 0 0 1 7-7L12 7l1.5-1.5a5 5 0 0 1 7 7Z"/>
  </svg>
  <span>Save</span>
</button>
.toggle svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.toggle[aria-pressed="true"] svg {
  fill: currentColor;
  animation: toggle-pop 260ms ease-out;
}

@keyframes toggle-pop {
  50% {
    transform: scale(1.25);
  }
}

@media (prefers-reduced-motion: reduce) {
  .toggle[aria-pressed="true"] svg {
    animation: none;
  }
}
document.querySelectorAll('.toggle').forEach((button) => {
  button.addEventListener('click', () => {
    const pressed = button.getAttribute('aria-pressed') === 'true';
    button.setAttribute('aria-pressed', String(!pressed));
  });
});

The label stays "Save" in both states; the pressed state carries the meaning. Under reduced motion the icon still fills, it just does not pop.

Example 2: copy to clipboard with a status message

Copy buttons are the classic case of an action with no visible result. The feedback has to be both visual and announced, without moving focus. WCAG 4.1.3 Status Messages asks that status messages "can be programmatically determined through role or properties" so assistive technology can present them "without receiving focus". An element with role="status" does exactly that.

<button type="button" data-copy="npm install example-package">Copy command</button>
<p class="copy-status" role="status"></p>
const status = document.querySelector('.copy-status');
let clearTimer;

document.querySelectorAll('[data-copy]').forEach((button) => {
  button.addEventListener('click', async () => {
    try {
      await navigator.clipboard.writeText(button.dataset.copy);
      status.textContent = 'Copied to clipboard';
    } catch {
      status.textContent = 'Copy failed. Select the text and copy it manually.';
    }
    clearTimeout(clearTimer);
    clearTimer = setTimeout(() => {
      status.textContent = '';
    }, 4000);
  });
});

Two details make this robust. Clipboard.writeText() only works in secure contexts (HTTPS), so the failure message is not hypothetical. And the status text says what happened, so the check mark or color change you add on top is decoration, not the only signal.

Example 3: inline validation that waits for the user

An error that appears while someone is still typing their email is feedback at the wrong moment. The :user-invalid pseudo-class matches a field whose value is invalid "after the user has interacted with it", which is the right trigger, and it needs no script.

<div class="field">
  <label for="email">Email</label>
  <input id="email" type="email" required aria-describedby="email-hint">
  <p id="email-hint" class="hint">Use the address you sign in with, like name@example.com</p>
</div>
.field input {
  border: 2px solid #5b6b80;
  border-radius: 0.375rem;
  transition: border-color 150ms ease-out;
}

.field input:user-invalid {
  border-color: #b3261e;
}

.field:has(input:user-invalid) .hint {
  color: #b3261e;
  font-weight: 600;
}

.field:has(input:user-invalid) .hint::before {
  content: "Check this field: ";
}

The hint is always visible and connected with aria-describedby, and the invalid state changes its weight and adds a short prefix, so the error is not signaled by color alone. Both colors reach more than 4.5:1 on white. :user-invalid has been Baseline since November 2023, and :has() since December 2023 (both checked on MDN on 2026-10-09).

Example 4: a press that answers before the network does

For a button that starts slow work, the first feedback is the press itself: a slight shrink on :active, applied to every input type, including touch. If the result takes longer than about a second, switch the label to a progress state and, when it finishes, announce the outcome through the same role="status" pattern from example 2. The CSS buttons guide covers hover, focus, pressed and disabled states in detail.

Reduced motion: keep the feedback, drop the travel

WCAG 2.3.3 Animation from Interactions says "Motion animation triggered by interaction can be disabled, unless the animation is essential". It is a AAA criterion, but prefers-reduced-motion makes it cheap to meet. The mistake to avoid is removing the micro interaction entirely. The user who asked for less motion still needs to know that the item was saved. Replace scaling, sliding and bouncing with an instant change of color, fill or text:

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}

This global version keeps every end state and removes the travel between them. The !important is deliberate: the universal selector has no specificity, so without it any component rule with a class would override the safety net. Still write targeted rules like the one in example 1 for effects that should not run at all.

The same save control shown twice: once with a bouncing bookmark icon and once as an instant solid fill without movement

Checklist: does this micro interaction earn its place?

  1. There is a trigger. A user action or a real change of system state starts it.
  2. It reports something new. Saved, copied, invalid, done. If it reports nothing, it is decoration.
  3. The state changes in the next frame. The animation follows the change instead of delaying it.
  4. The state is exposed. Native state, aria-pressed, or a role="status" message carries the meaning for assistive technology.
  5. It works without hover. Touch and keyboard users trigger it too.
  6. It survives reduced motion. The movement goes, the feedback stays.
  7. It survives repetition. Click it twenty times. If it gets in the way by the fifth, shorten it.
  8. It costs little. Animate transform and opacity where you can, as web.dev's animation guide recommends.

Micro interaction examples on HorizonX

These components are small enough to drop into a real interface. You can adjust each one in the browser and export it as HTML, Svelte or React:

  • Save Slide Button: the label fades in place while the icon travels into the space it leaves, so the button never changes width. The accessible name lives on the button, and reduced motion removes the transitions.
  • Firework Todo Checkbox: checking a task draws the check, strikes through the label and fires a small burst. Under reduced motion it shows the final state directly.
  • Expanding Search: a search field that widens on hover and again on focus, with a real focus ring and a screen reader label. It animates width, a layout property, which is an acceptable exception for a single field but not a pattern to copy into a list.

See the rest in the micro-interactions collection, and run each one through the checklist before it ships.

FAQ

What are micro-interactions?

They are small, single-purpose responses to one trigger: a user action or a change in the system's state. Examples include a toggle that fills when pressed, a copy button that confirms the copy, and a form field that flags an error after you leave it.

Can you give me an example of a micro-interaction?

A "Copy" button that, when clicked, copies the text, shows a check mark and announces "Copied to clipboard" through a status message. The trigger is the click, and the feedback is the visual change plus the announcement. Example 2 above has the full code.