Skip to content

VisuallyHidden

XS, under 350B gzipped

Content for assistive technology only, removed from the visual layout without leaving the accessibility tree.

Category
Accessibility & preferences
Budget
xs, static display primitive
Runtime deps
None

Preview

Preview language
Screen-reader-only text

This is the exact fixture the conformance suite renders in CI. Switch the language to see the component mirror and reformat.

Install

npx shadcn@latest add https://kata-ui-rho.vercel.app/r/visually-hidden.json

Copies the source into your project.

Source

/**
 * Content present for assistive technology and absent from the visual
 * layout — an icon-only button's real label, an SR-only column header.
 *
 * Not `display: none` or `hidden`: both remove a node from the accessibility
 * tree as completely as from the screen, which is the opposite of the point.
 */
export function VisuallyHidden({
  children,
  as: As = "span",
}: {
  children: React.ReactNode;
  as?: React.ElementType;
}) {
  return (
    <As
      style={{
        position: "absolute",
        width: 1,
        height: 1,
        margin: -1,
        padding: 0,
        border: 0,
        overflow: "hidden",
        clip: "rect(0 0 0 0)",
        clipPath: "inset(50%)",
        whiteSpace: "nowrap",
      }}
    >
      {children}
    </As>
  );
}

What CI checks

Used by

← All components