API

css.marker / css.extended

★★★★☆ Stable

Style descendants from a parent state without writing a combinator.

export type marker = (id: string, pseudo: string) => Marker;
export const marker: marker;

export type extended = <I extends string, P extends string>(id: I, pseudo: P) => Extended<I, P>;
export const extended: extended;

marker and extended are a pair: a descendant responds to an ancestor's state without a combinator and without naming the path between them. The styles stay atomic.

Production ready. These APIs compile to CSS container style queries (@container style()), which current versions of Chrome, Edge, Safari and Firefox all support.

  • marker(id, pseudo) - Sets a CSS variable marker on a parent element
  • extended(id, pseudo) - Applies styles to children when the marker is active

Parameters

Both calls take the same two arguments, and a pair is linked when they match.

  • id - A unique identifier linking the marker and extended styles
  • pseudo - The pseudo-class state (e.g., ':hover', ':focus', ':active')

Example

Grand Container (Hover me)
Parent Container (Hover me too)
Child Element
TypeScript
import * as css from '@plumeria/core';

const animation = css.keyframes({
  '0%': {
    scale: 1.2,
  },
  '50%': {
    scale: 1.3,
  },
  '100%': {
    scale: 1.2,
  },
});

const styles = css.create({
  grand: {
    display: 'flex',
    flexDirection: 'column',
    gap: 15,
    alignItems: 'center',
    justifyContent: 'center',
    width: '100%',
    minHeight: 250,
    padding: 20,
    border: '2px dashed #c4c4c466',
    borderRadius: 12,
    transition: 'all 0.3s',
    ...css.marker('grand', ':hover'),
  },
  parent: {
    display: 'flex',
    flexDirection: 'column',
    gap: 10,
    alignItems: 'center',
    justifyContent: 'center',
    width: '80%',
    minHeight: 120,
    padding: 10,
    backgroundColor: '#f5f5f7',
    border: '2px solid #c4c4c444',
    borderRadius: 8,
    transition: 'all 0.3s',
    ...css.marker('parent', ':hover'),
  },
  child: {
    padding: '8px 16px',
    fontWeight: 'bold',
    color: '#86868b',
    background: '#e8e8ed',
    borderRadius: 6,
    transition: 'all 0.3s',
    [css.extended('grand', ':hover')]: {
      color: '#0066cc',
      background: '#e1f0ff',
    },
    [css.extended('parent', ':hover')]: {
      color: '#ffffff',
      background: '#ff9500',
      scale: 1.2,
      ':hover': {
        background: 'skyblue',
        animationName: animation,
        animationDuration: '1.2s',
        animationTimingFunction: 'ease-in-out',
        animationIterationCount: 'infinite',
      },
    },
  },
  description: {
    fontSize: '14px',
    color: '#86868b',
  },
});

const MarkerExtended = () => {
  return (
    <div sx={styles.grand}>
      <span sx={styles.description}>Grand Container (Hover me)</span>
      <div sx={styles.parent}>
        <span sx={styles.description}>Parent Container (Hover me too)</span>
        <div sx={styles.child}>Child Element</div>
      </div>
    </div>
  );
};

How it works

Internal

marker() generates a CSS variable when the pseudo-class is active:

.parent:hover {
  --xyuz5mma-ul-hover: 1;
}

extended() wraps child styles in a container query:

@container style(--xyuz5mma-ul-hover: 1) {
  .child { /* styles */ }
}

The CSS variable is a signal every descendant inherits, wherever it sits in the markup.

ESLint Rule

The no-combinator rule enforces this pattern by disallowing combinator syntax.

Functional pseudo-classes

Any pseudo-class is accepted, including the functional ones.

const styles = css.create({
  wrap: {
    ...css.marker('wrap', ':has(a:hover)'),
  },
  child: {
    [css.extended('wrap', ':has(a:hover)')]: { color: 'red' },
  },
});
.xwpr9f08:has(a:hover) {
  --xg204awn-wrap-has: 1;
}

@container style(--xg204awn-wrap-has: 1) {
  .xof70rr5:not(#\#) {
    color: red;
  }
}

:has() reverses the direction the marker travels: the state belongs to a descendant, the marker lands on the element that contains it, and the styles land on any descendant of that element. CSS spells the same relation as .a:has(.b:hover) .c, naming the path between all three; the marker names none of it.

:defined matches every standard element, so it turns the marker into a permanent signal — the plain descendant relation, with no state involved.

The marker has to be above it

An extended style applies to elements below the marked one, and to nothing else. Render the same component outside that subtree and the style is simply absent — no error, no warning, because the query has nothing to match. With a state like :hover this reads as "the state never fired"; with :defined, which is always on, it reads as the style having disappeared.

Every combinator, expressed

CSSPlumeria
.a .b — descendant, on a statecss.marker(id, ':hover') + css.extended
.a .b — descendant, no statecss.marker(id, ':defined') + css.extended
.a > .b — childcss.marker(id, ':defined') + css.extended on the child
.a + .b, .a ~ .b — siblingcss.marker(id, ':defined') + css.extended on the sibling
.a:hover ~ .b — sibling reacting to a statecss.marker(id, ':has(a:hover)') + css.extended
.a:has(.b) .c — a descendant's state, back up and down againcss.marker(id, ':has(input:focus)') + css.extended

The marker goes on the element both sides share — for a child that is the parent, for a sibling their common parent. What separates a child from a sibling is not a selector but which element you hand extended to.

The CSS column names a path; the Plumeria column does not. marker and extended are linked by an id, so the styles reach every descendant at any depth, and moving an element deeper does not invalidate the pair.

Reach for marker / extended first. The alternative is a selector key — a combinator inside a functional pseudo-class, which no-combinator permits, anchored on something you write yourself:

const styles = css.create({
  cell: { ':is([data-row] > *)': { color: 'red' } },
});

That names the path, so moving the element breaks it, and it repeats the whole selector for every declaration. The marker pair names no path, and every extended sharing an id lands in one @container block.

Targets under one relationSelector keymarker / extended
194 B147 B
5281 B43 B
Bytes each route adds to the stylesheet, measured from a production vite build of the same markup.

The selector key is the escape hatch, for when the target is markup you do not write and therefore cannot attach a style to.

What the container query costs

extended compiles to a style query, which the engine re-evaluates per container when a state changes. Style recalculation, measured over a class toggle in headless Chromium, median of 30 runs:

ElementsPlain CSSSelector keymarker / extended
5000.009 ms0.006 ms0.012 ms
2,0000.008 ms0.007 ms0.012 ms
8,0000.005 ms0.005 ms0.012 ms
One element toggled per run — a hover, a focus. The figure is flat because only the containers on the path are re-evaluated, not the document.

The cost does not grow with the page. Toggling every anchor at once is the case where it does: 8,000 simultaneous toggles cost 26 ms against 7 ms for a selector key. That is not a shape user interfaces take, but it is where the difference lives if you go looking for it.

Edit on GitHub