Small JavaScript helpers. Better everyday interactions.

The little things.
A lot better.

Menus that don’t close too soon. Forms that remember your work. Feedback that arrives at the right time.

Subtly adds thoughtful behavior to the components you already have. Use plain JavaScript or your favorite framework.

npm install subtly
29 focused helpersNo required frameworkNative ES modules
A small detail, in action

Errors when they’re helpful.

Try an incomplete email, then leave the field. Correct it and watch the error clear.

Newsletter signup

A sample form. No email is sent.

Start typing, then leave the field.

fieldValidation() validates after interaction, then again while correcting.

What it does

Better behavior.
Still your interface.

Choose a specific interaction to improve. Subtly handles its timing and state, while your application stays in control of rendering and styling.

Try it yourself

See the difference.
Then use the code.

These examples run the actual library. Requests and saves are simulated locally, so you can experiment freely.

debounce()

Search after a pause

Keep the input immediate. Wait for a pause before doing the work.

Implementation guide
Live example
  • Designing a useful empty state
  • Accessible menus from the start
  • Small details in product design
  • A guide to loading feedback

4 articles · 0 filter runs

<div id="your-component">
<label>Find an article<input type="search" placeholder="Try design or accessibility" autocomplete="off"></label>
        <ul class="result-list"><li>Designing a useful empty state</li><li>Accessible menus from the start</li><li>Small details in product design</li><li>A guide to loading feedback</li></ul>
        <p class="demo-status" role="status">4 articles · 0 filter runs</p>
</div>
import * as kit from 'subtly';

const el = document.querySelector('#your-component');
const listeners = new AbortController();
const { signal } = listeners;
const status = text => {
  el.querySelector('.demo-status').textContent = text;
};
// Local simulation only. Replace with your real data operation.
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));

function setup() {
  const input = el.querySelector('input');
          const articles = [...el.querySelectorAll('li')];
          let runs = 0;
          const filter = kit.debounce(query => {
            runs++;
            for (const article of articles) {
              article.hidden = !article.textContent.toLowerCase().includes(query.toLowerCase());
            }
            const count = articles.filter(article => !article.hidden).length;
            status(`${count} articles · ${runs} filter runs`);
          }, 300);
          input.addEventListener('input', () => filter(input.value), { signal });
          return () => filter.cancel();
}
const stop = setup();

// Call when this component is removed.
function cleanup() {
  listeners.abort();
  stop?.();
}
undoAction()

Give mistakes an undo

Archive a task, then bring it back before the action is confirmed.

Implementation guide
Live example
Review the landing pageDesign · Today
To do

One task in your list.

<div id="your-component">
<div class="task-preview" data-item><span class="task-checkbox" aria-hidden="true"></span><div><strong>Review the landing page</strong><small>Design · Today</small></div><span class="tag">To do</span></div><div class="empty-task" hidden>Task archived.</div><div class="demo-row"><button data-remove>Archive task</button><button data-undo disabled>Undo archive</button><button data-reset hidden>Reset example</button></div><p class="demo-status" role="status">One task in your list.</p>
</div>
import * as kit from 'subtly';

const el = document.querySelector('#your-component');
const listeners = new AbortController();
const { signal } = listeners;
const status = text => {
  el.querySelector('.demo-status').textContent = text;
};
// Local simulation only. Replace with your real data operation.
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));

function setup() {
  let action;
          const item = el.querySelector('[data-item]');
          const empty = el.querySelector('.empty-task');
          const remove = el.querySelector('[data-remove]');
          const undo = el.querySelector('[data-undo]');
          const reset = el.querySelector('[data-reset]');
          function restore() {
            item.hidden = false; empty.hidden = true;
            remove.disabled = false; undo.disabled = true; reset.hidden = true;
            status('Task restored.');
          }
          remove.addEventListener('click', () => {
            action = kit.undoAction({
              duration: 5000,
              apply() {
                item.hidden = true; empty.hidden = false;
                remove.disabled = true; undo.disabled = false;
                status('Task archived. You have 5 seconds to undo.');
              },
              revert: restore,
              commit() {
                undo.disabled = true; reset.hidden = false;
                status('Archive confirmed in this demo.');
              }
            });
            action.start(() => status('Could not archive. Task restored.'));
          }, { signal });
          undo.addEventListener('click', () => action?.undo(), { signal });
          reset.addEventListener('click', restore, { signal });
          return () => action?.destroy();
}
const stop = setup();

// Call when this component is removed.
function cleanup() {
  listeners.abort();
  stop?.();
}
menuAim()

Keep the right submenu open

Move diagonally toward the panel. Click and keyboard work immediately.

Implementation guide
Live example

Products selected

<div id="your-component">
<nav class="menu-demo" data-ix="menu-aim" data-ix-side="right" aria-label="Example navigation"><div class="triggers"><button data-ix-menu-trigger="products" aria-expanded="true" aria-controls="products">Products ›</button><button data-ix-menu-trigger="solutions" aria-expanded="false" aria-controls="solutions">Solutions ›</button><button data-ix-menu-trigger="resources" aria-expanded="false" aria-controls="resources">Resources ›</button></div><div class="menu-panel" id="products" data-ix-menu-panel="products"><b>Products</b><a href="#example">Overview</a><a href="#example">Analytics</a><a href="#example">Integrations</a><a href="#example">Developer tools</a></div><div class="menu-panel" id="solutions" data-ix-menu-panel="solutions" hidden><b>Solutions</b><a href="#example">Business</a><a href="#example">Teams</a><a href="#example">Enterprise</a></div><div class="menu-panel" id="resources" data-ix-menu-panel="resources" hidden><b>Resources</b><a href="#example">Guides</a><a href="#example">Documentation</a></div></nav><p class="demo-status" aria-live="polite">Products selected</p>
</div>
import * as kit from 'subtly';
// Start once at application level.
const interactions = kit.createInteractions();
interactions.start();

const el = document.querySelector('#your-component');
const listeners = new AbortController();
const { signal } = listeners;
const status = text => {
  el.querySelector('.demo-status').textContent = text;
};
// Local simulation only. Replace with your real data operation.
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));

function setup() {
  const nav = el.querySelector('nav');
  // The adapter emits intent. This component controls visibility.
  nav.addEventListener('ix:menu-change', ({ detail }) => {
    for (const panel of nav.querySelectorAll('[data-ix-menu-panel]')) {
      panel.hidden = panel.dataset.ixMenuPanel !== detail.key;
    }
    for (const trigger of nav.querySelectorAll('[data-ix-menu-trigger]')) {
      trigger.setAttribute('aria-expanded', String(trigger.dataset.ixMenuTrigger === detail.key));
    }
    status(detail.key + ' selected');
  }, { signal });
}
const stop = setup();

// Call when this component is removed.
function cleanup() {
  listeners.abort();
  stop?.();
  interactions.stop();
}

Find your starting point

What would you like
to make easier?

Browse by the problem you want to solve. Each helper has a working example, setup code, lifecycle notes and accessibility guidance.

Browse all 29 helpers

From example to implementation

A small addition
to your existing project.

Install

Add the package

Install from npm. The UI library used on this website is a docs dependency and is not included in Subtly.

npm install subtly
Connect

Choose one helper

Import a utility directly or use data attributes for the six built-in HTML behaviors.

import { debounce } from 'subtly';

const search = debounce(findArticles, 300);
input.addEventListener('input', event => {
  search(event.target.value);
});

// When this component is removed:
search.cancel();
Make it yours

Use your component lifecycle

Initialize after the elements exist. Call the helper’s cleanup when the component unmounts. The framework guides show where both belong.

Read the installation guide

Your stack is welcome

Familiar tools.
One small library.

Plain HTML, React, Laravel, Vue and more. Start with the guide for the framework you already use.

HTML, when that is enough

Declare the behavior.
Keep your own styling.

Use data attributes for common behavior and explicit JavaScript when your application needs control.

<div data-ix="hover-intent" data-ix-hover-delay="150">
  <button type="button">Preview</button>
</div>

Start createInteractions() once, then handle the emitted events in your component. Subtly does not render the preview for you.

Explore the HTML API
Ready when you are

Add the behavior. Keep your interface.

Install the package, choose one primitive, and connect it to the component you already have.