#7591·ariakit

Keep Ariakit UI slot badges and avatars visible in forced colors

Author: diegohazCreated Sep 23, 2026Updated Sep 26, 2026
Labelshas workaroundexperimental buga11yp2easyui

Context

The nav slot design work for #7579 and #7584 found that slot badges and avatars lose their surface in forced colors. The same problem exists on main, so #7584 did not cause it.

Problem

Forced colors replace the fill of a slot badge or avatar with the page color (Canvas). The slot has no border, so nothing marks its edge. A count such as "12" or "9" then reads as a stray number beside the label, and initials such as "AL" read as bare letters.

Measured on main at 87749801f with Playwright forcedColors: "active", light scheme:

Element Chromium 153 Firefox 155
11 slot badges and avatars: button "Count badge", "Initial avatar" and "Label and description"; nav "Badges and avatars" (6 slots); tabs "Tab with a badge"; disclosure "Trailing badge" Fill becomes Canvas, no border Fill becomes Canvas, no border
Standalone Badge: badge "Default" and "Brand" 1px border 1px border
Button with a layer fill: button "Label and description" 1px border 1px border
Slot badge with an explicit $border: button "Badge hue" 1px border 1px border

The nav example shows the same result in the dark scheme, in Chromium and Firefox. A painted icon tile (button "Painted icon slot") also loses its fill and has no border, but its icon still shows.

The "Badges and avatars" nav example on main in Chromium without forced colors. The counts 12, 3 and 9 sit in blue pills, and the initials MK, JD and AL sit in gray circles.

The same example with forced colors. The pills and circles are gone. "12", "MK", "3", "JD", "9" and "AL" show as bare text beside the labels.

The "Default" example of the badge sandbox with forced colors. The standalone "Draft" badge keeps a 1px border.

The "Count badge" example of the button sandbox with forced colors. The "12" slot badge after "Inbox" shows as bare text.

Minimal reproduction, with forced colors active:

typescript
<Button>
  <ButtonLabel>Inbox</ButtonLabel>
  <ButtonSlot $kind="badge" $p="md">
    12
  </ButtonSlot>
</Button>
<Button>
  <ButtonSlot $kind="avatar" $layer="brand">
    WW
  </ButtonSlot>
  <ButtonLabel>Will Williams</ButtonLabel>
</Button>

WebKit is not in the table. Playwright's emulation makes the forced-colors: active media query match in WebKit 26.6, but WebKit does not force the colors, so the fills stay. Safari has no forced colors mode. #7500 scoped its forced-colors tests to Chrome and Firefox for the same reason.

Cause

The control recipe adds a real border in forced colors when a control paints a layer and has no $border (control.ts#L86-L90):

typescript
// Forced colors remove a control's fill, which may be its only boundary.
if (variants.$border == null && hasLayerBackground(variants)) {
  addClass("forced-colors:ak-frame-border");
}

controlSlot extends frame, not control (control.ts#L100-L101), so it does not get this rule. Its defaults make a badge and an avatar paint a layer (control.ts#L240-L254), but its own refine adds no forced-colors border (control.ts#L310-L352).

The standalone Badge keeps its edge because it sets $border: true and $borderType: "inset" (badge.ts#L30-L31), and the inset type falls back to a real border in forced colors (frame.ts#L166-L169). #7500, which fixed #7476, added these fallbacks for frames, controls and badges, but not for slots.

Pre-existing on main

Yes. All measurements above are on main at 87749801f, with no change applied.

Why #7584 can finish without it

The cause is in controlSlot, which every slot shares: Button, Tabs, Disclosure, Nav, Combobox, Input, and the checkbox and radio cards. #7584 changes the nav slot API and sizes, not how a slot paints. The fix changes every component with a slot badge or avatar, and it needs its own forced-colors browser tests. So it is a separate change.

Suggested direction

Reuse the rule of control in the refine of controlSlot:

typescript
if (variants.$border == null && hasLayerBackground(variants)) {
  addClass("forced-colors:ak-frame-border");
}

I tested the class that this rule emits. I added forced-colors:ak-frame-border to each of the 12 slot badges and avatars in the examples above, in Chromium 153 and Firefox 155:

  • With forced colors, each slot gets a 1px border. The border takes the text color: black in most controls, and the link color in nav links.
  • The slot sizes do not change: 24x24, and 42x42 for the two-row avatar.
  • Without forced colors, the class adds nothing (a 0px border).

The "Badges and avatars" example with forced colors and the tested class. Each count and each set of initials sits in a thin round border.

With hasLayerBackground, a painted icon tile also gets the border, and a see-through icon slot does not. I did not test a painted icon tile with the class.

Workaround

Add the class to the slot yourself, for example <ButtonSlot $kind="badge" className="forced-colors:ak-frame-border">. This is the class that I tested above. An explicit $border also keeps a boundary in forced colors (button "Badge hue"), but it also draws an edge without forced colors.

Expected outcome

  • Slot badges and avatars keep a visible boundary in forced colors, like the standalone Badge.
  • The slot sizes and the rendering without forced colors do not change.
  • A forced-colors browser test in Chrome and Firefox covers at least one slot badge and one slot avatar, like the tests that #7500 added.
Method
  • Worktree at 87749801f, pnpm dev-app, Playwright 1.63.0 with Chromium 153.0.8010.12, Firefox 155.0 and WebKit 26.6, 1280x900 viewport, device scale factor 2.
  • Each page was loaded in a new context with forcedColors: "active" or "none", and colorScheme: "light". The nav example was also loaded with colorScheme: "dark".
  • For each slot and control: the computed background color, border width, border style and box shadow, and matchMedia("(forced-colors: active)").
  • The tested class was added to the elements in the page. No library file was changed.