Skip to main content

CloseButton

A small dismissal button displaying an × icon. Use to close or dismiss modals, alerts, drawers, or tags. Don't use for destructive or irreversible actions — use a labelled Button with Destructive intent instead.

Figma Storybook Docs

Description

What it does

Provides a compact, icon-only button that dismisses or closes a containing UI element such as a modal, drawer, alert, or tag.

Where it appears

Top-right corner of modals and drawers; inline within dismissible alert banners; attached to removable tags in stakeholder filters and consultation audience selectors.

Why it exists

Government interfaces frequently surface time-sensitive notifications and contextual panels. A consistent, accessible dismiss affordance reduces cognitive load and prevents users from becoming trapped in layered UI states.

Dependencies

Button, Alert, Modal, Drawer, Tag

Anatomy

PartRequired?Notes
Button root Required Native
Icon (×) Required A wa-icon or inline SVG rendering a close/times glyph at 16px. Must not carry standalone meaning — the accessible label is on the button root.
Accessible label Required aria-label or visually hidden text (e.g. 'Close modal', 'Dismiss alert', 'Remove tag: Stakeholder name') read by screen readers. Never left empty.
Focus ring Required 3px solid ring using --op-color-interactive-focus, always visible on keyboard focus. Not suppressed on mouse interaction.
Touch target overlay Recommended Minimum 44x44px interactive area regardless of visual icon size, achieved via padding or an invisible pseudo-element.

Variants

Default

Neutral dismiss action on a light background

Use on white or --op-color-bg-primary surfaces such as modal headers and card corners.

On-colour

Dismiss action placed on a tinted or dark background

Use inside coloured alert banners (info, success, warning, error) where the default icon colour would lack sufficient contrast against the status background token.

Ghost

Reduced-prominence dismiss with no visible background until hover

Use inside tag components or dense list rows where a visible button background would be visually noisy.

States

State Behaviour
Default (rest) Icon renders at --op-color-text-secondary. No background fill.
Hover Background fills to --op-color-interactive-hover at low opacity (8-12%). Icon shifts to --op-color-text-primary. Cursor becomes pointer.
Focus 3px focus ring using --op-color-interactive-focus appears around the button. Background fill matches hover state. Must be visible for both keyboard and programmatic focus.
Active (pressed) Background deepens slightly (--op-color-interactive-default at 16% opacity). Icon scales to 95% if motion is not reduced.
Disabled Icon renders at --op-color-text-disabled. Pointer events removed. aria-disabled='true' set. Do not use disabled state when the parent element is already not dismissible — simply omit the button.

Usage guidelines

When to use

  • Closing a modal or drawer that can safely be abandoned without data loss.
  • Dismissing an informational, success, warning, or error alert banner.
  • Removing a selected tag or filter chip (e.g. removing a stakeholder segment from a consultation audience).
  • Closing a tooltip or popover triggered by user action.

When not to use

  • Destructive or irreversible actions (e.g. deleting a consultation, removing a stakeholder record permanently) — use a labelled Button with Destructive intent and a confirmation step instead.
  • Navigation — use a Back link or breadcrumb.
  • Cancelling a multi-step form — use a labelled 'Cancel' Button so the action is unambiguous to assistive technology users.
  • Primary or secondary calls to action — the icon-only format provides no affordance for unfamiliar users.

Do / Don't

Do

Always provide a descriptive aria-label that includes the name of what is being closed (e.g. 'Close Add Stakeholder modal').

Don't

Don't use a bare aria-label of 'Close' when multiple CloseButtons are present on the same page — screen reader users will hear duplicate, ambiguous button names.

Do

Position the CloseButton consistently in the top-right corner of modals and drawers to match user expectations established by common OS and browser patterns.

Don't

Don't place CloseButton at the bottom of a modal where it competes visually with primary action buttons.

Do

Return focus to the element that triggered the parent overlay when the CloseButton is activated.

Don't

Don't drop focus to the top of the document or to a generic container after dismissal.

Do

Use the Ghost variant inside Tag components so the button does not dominate the tag's visual weight.

Don't

Don't apply the Default variant inside small Tag components — the background fill will visually overpower the tag label.

Was this page helpful?

Updated 9 September 2026