---
title: "Password Input · Ark UI — StyleX Blocks"
description: "Password fields with a show/hide toggle, built on the input styles in every variant and size."
url: "https://stylexblocks.com/components/ark-ui/password-input/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Password Input

Password fields with a show/hide toggle, built on the input styles in every variant and size.

- Behavior engine: Ark UI
- Also available for: [Base UI](https://stylexblocks.com/components/base-ui/password-input.md), [UI SDK](https://stylexblocks.com/components/ui-sdk/password-input.md)
- Category: Form
- Variants: outline, subtle, flushed
- Sizes: xs, sm, md, lg, xl
- HTML page: https://stylexblocks.com/components/ark-ui/password-input/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init
```

Then add the item as source you own:

```sh
npx stylexblocks add password-input
```

Equivalent: `npx shadcn add @stylexblocks/password-input`. Registry item JSON: https://stylexblocks.com/r/ark-ui/password-input.json

## Usage

```tsx
import { PasswordInput } from "#components/ui/ark-ui/password-input.tsx";

export function Example() {
  return (
    // Ark's password-input machine wearing the input recipe: it wires the
    // label, swaps the input type and labels the toggle "Show password" /
    // "Hide password"; VisibilityTrigger ships the eye icons
    <PasswordInput.Root variant="outline" size="md" autoComplete="current-password">
      <PasswordInput.Label>Password</PasswordInput.Label>
      <PasswordInput.Control>
        <PasswordInput.Input placeholder="Enter your password" />
        <PasswordInput.VisibilityTrigger />
      </PasswordInput.Control>
    </PasswordInput.Root>
  );
}

// controlled: <PasswordInput.Root visible={visible} onVisibilityChange={(d) => setVisible(d.visible)}>
// custom icons: <PasswordInput.VisibilityTrigger><PasswordInput.Indicator fallback={<Eye />}><EyeOff /></PasswordInput.Indicator></PasswordInput.VisibilityTrigger>
```

## Examples

### Strength meter

Pair the field with a Meter that scores the password and switches palette by level.

```tsx
import { useState } from "react";
import { PasswordInput } from "#components/ui/ark-ui/password-input.tsx";
import { Meter } from "#components/ui/ark-ui/meter.tsx";
import { amberPalette, greenPalette, redPalette } from "@stylexblocks/ui/themes/palettes.ts";

const levels = [
  { label: "Too short", palette: redPalette },
  { label: "Weak", palette: redPalette },
  { label: "Weak", palette: redPalette },
  { label: "Fair", palette: amberPalette },
  { label: "Good", palette: amberPalette },
  { label: "Strong", palette: greenPalette },
  { label: "Very strong", palette: greenPalette },
];

export function Example({ score }: { score: (password: string) => number /* 0–6 */ }) {
  const [password, setPassword] = useState("");
  const points = score(password);
  const level = levels[points];
  return (
    <>
      <PasswordInput.Root autoComplete="new-password">
        <PasswordInput.Label>New password</PasswordInput.Label>
        <PasswordInput.Control>
          <PasswordInput.Input value={password} onChange={(e) => setPassword(e.currentTarget.value)} />
          <PasswordInput.VisibilityTrigger />
        </PasswordInput.Control>
      </PasswordInput.Root>
      <Meter.Root
        value={points}
        max={6}
        variant="subtle"
        size="xs"
        shape="full"
        palette={level.palette}
        aria-label="Password strength"
        aria-valuetext={level.label}
      >
        <Meter.Track>
          <Meter.Range />
        </Meter.Track>
      </Meter.Root>
    </>
  );
}
```

### Invalid and disabled

Root flags reach every part: the input turns the error colour, the toggle disables with the field.

```tsx
import { PasswordInput } from "#components/ui/ark-ui/password-input.tsx";

export function Example() {
  return (
    <>
      <PasswordInput.Root invalid>
        <PasswordInput.Label>Invalid</PasswordInput.Label>
        <PasswordInput.Control>
          <PasswordInput.Input />
          <PasswordInput.VisibilityTrigger />
        </PasswordInput.Control>
      </PasswordInput.Root>
      <PasswordInput.Root disabled>
        <PasswordInput.Label>Disabled</PasswordInput.Label>
        <PasswordInput.Control>
          <PasswordInput.Input />
          <PasswordInput.VisibilityTrigger />
        </PasswordInput.Control>
      </PasswordInput.Root>
    </>
  );
}
```

## Source

`components/ui/ark-ui/password-input.tsx`

```tsx
import * as stylex from "@stylexjs/stylex";
import { PasswordInput as ArkPasswordInput } from "@ark-ui/react/password-input";
import { createSlotRecipeContext } from "#lib/ark-ui/create-slot-recipe-context.tsx";
import {
  defineSlotRecipe,
  resolveSlotStyles,
  type SlotRecipeVariants,
  type WithStyleOverrides,
} from "#lib/recipe-props.ts";
import { fontWeights } from "@stylexblocks/ui/tokens/font-weights.stylex.ts";
import { accentPalette } from "@stylexblocks/ui/themes/palettes.ts";
import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'
import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'
import { semanticRadii } from '@stylexblocks/ui/semantic-tokens/radii.stylex.ts'
import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
import { spacing } from '@stylexblocks/ui/tokens/spacing.stylex.ts'
import { textStyles } from '@stylexblocks/ui/text-styles.ts'

const inputStyles = stylex.create({
  base: {
    width: '100%',
    minWidth: 'var(--input-height)',
    outline: 'none',
    position: 'relative',
    appearance: 'none',
    textAlign: 'start',
    opacity: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 0.5,
    },
    cursor: {
      default: null,
      ':is(:disabled, [disabled], [data-disabled])': 'not-allowed',
    },
    height: 'var(--input-height)',
    '--focus-color': colorPalette.focusRing,
    '--error-color': semanticColors.borderError,
    '--focus-ring-color': {
      default: null,
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
    },
    borderColor: {
      default: null,
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
    },
  },
})

const inputSizes = stylex.create({
  xs: {
    borderRadius: semanticRadii.control,
    paddingInline: spacing._2,
    '--input-height': sizes.controlXs,
  },
  sm: {
    borderRadius: semanticRadii.control,
    paddingInline: spacing._2_5,
    '--input-height': sizes.controlSm,
  },
  md: {
    borderRadius: semanticRadii.control,
    paddingInline: spacing._3,
    '--input-height': sizes.controlMd,
  },
  lg: {
    borderRadius: semanticRadii.control,
    paddingInline: spacing._4_5,
    '--input-height': sizes.controlLg,
  },
  xl: {
    borderRadius: semanticRadii.control,
    paddingInline: spacing._6,
    '--input-height': sizes.controlXl,
  },
})

const inputVariants = stylex.create({
  outline: {
    backgroundColor: semanticColors.bg,
    borderWidth: '1px',
    borderColor: {
      default: semanticColors.border,
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
      ':hover': semanticColors.borderEmphasized,
    },
    outlineWidth: {
      default: null,
      ':focus-visible': 'var(--focus-ring-width, 0)',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
    focusRingWidth: 0,
  },
  subtle: {
    borderWidth: '1px',
    borderColor: {
      default: 'transparent',
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
    },
    backgroundColor: semanticColors.bgMuted,
    outlineWidth: {
      default: null,
      ':focus-visible': 'var(--focus-ring-width, 0)',
    },
    outlineOffset: {
      default: null,
      ':focus-visible': '0px',
    },
    outlineStyle: {
      default: null,
      ':focus-visible': 'solid',
    },
    outlineColor: {
      default: null,
      ':focus-visible': colorPalette.focusRing,
    },
  },
  flushed: {
    backgroundColor: 'transparent',
    borderBottomWidth: '1px',
    borderBottomColor: semanticColors.border,
    borderRadius: 0,
    paddingInline: 0,
    borderColor: {
      default: null,
      ':is([data-invalid], [aria-invalid="true"])': 'var(--error-color)',
      ':focus-visible': 'var(--focus-color)',
    },
    boxShadow: {
      default: null,
      ':focus-visible': '0px 1px 0px 0px var(--focus-color)',
    },
  },
})

const inputTextStyles = {
  xs: textStyles.xs,
  sm: textStyles.sm,
  md: textStyles.sm,
  lg: textStyles.md,
  xl: textStyles.md,
} as const

export type InputSize = keyof typeof inputSizes

export type InputVariant = keyof typeof inputVariants

// The field reuses the input recipe as-is; this layer only adds the group
// around it: a stacked root, the label, a relative control that sizes the
// end slot, and the ghost visibility toggle pinned inside the input's end.
const group = stylex.create({
  root: {
    display: "flex",
    flexDirection: "column",
    gap: spacing._1_5,
    width: "100%",
  },
  label: {
    fontWeight: fontWeights.medium,
    userSelect: "none",
    opacity: {
      default: null,
      ":is([data-disabled])": 0.5,
    },
  },
  control: {
    position: "relative",
    display: "flex",
    alignItems: "center",
    width: "100%",
  },
  input: {
    // room for the toggle, which is as wide as the input is tall
    paddingInlineEnd: "var(--input-height)",
  },
  trigger: {
    position: "absolute",
    insetBlockStart: 0,
    insetInlineEnd: 0,
    zIndex: 1,
    display: "inline-flex",
    alignItems: "center",
    justifyContent: "center",
    width: "var(--input-height)",
    height: "var(--input-height)",
    padding: 0,
    margin: 0,
    borderWidth: 0,
    borderStyle: "none",
    borderRadius: semanticRadii.control,
    backgroundColor: "transparent",
    appearance: "none",
    color: {
      default: semanticColors.fgMuted,
      ":hover": semanticColors.fg,
    },
    cursor: {
      default: "pointer",
      ":is(:disabled, [data-disabled])": "not-allowed",
    },
    opacity: {
      default: null,
      ":is(:disabled, [data-disabled])": 0.5,
    },
    outlineStyle: {
      default: null,
      ":focus-visible": "solid",
    },
    outlineWidth: {
      default: null,
      ":focus-visible": "2px",
    },
    outlineOffset: {
      default: null,
      ":focus-visible": "-2px",
    },
    outlineColor: {
      default: null,
      ":focus-visible": colorPalette.focusRing,
    },
  },
  indicator: {
    display: "inline-flex",
    alignItems: "center",
    justifyContent: "center",
  },
  icon: {
    width: "var(--password-input-icon-size)",
    height: "var(--password-input-icon-size)",
    flexShrink: 0,
  },
});

const groupSizes = stylex.create({
  xs: { "--input-height": sizes.controlXs, "--password-input-icon-size": sizes._3_5 },
  sm: { "--input-height": sizes.controlSm, "--password-input-icon-size": sizes._4 },
  md: { "--input-height": sizes.controlMd, "--password-input-icon-size": sizes._4 },
  lg: { "--input-height": sizes.controlLg, "--password-input-icon-size": sizes._5 },
  xl: { "--input-height": sizes.controlXl, "--password-input-icon-size": sizes._5 },
});

const passwordInputRecipe = defineSlotRecipe({
  slots: {
    root: { styles: { base: group.root } },
    label: { styles: { base: group.label }, sizes: inputTextStyles },
    control: { styles: { base: group.control }, sizes: groupSizes },
    input: { styles: inputStyles, variants: inputVariants, sizes: inputSizes },
    visibilityTrigger: { styles: { base: group.trigger } },
    indicator: { styles: { base: group.indicator } },
  },
  defaultVariants: { variant: "outline", size: "md" },
});

const { withProvider, withContext } = createSlotRecipeContext(passwordInputRecipe);

type PasswordInputVariants = SlotRecipeVariants<typeof passwordInputRecipe>;

function EyeIcon() {
  return (
    <svg viewBox="0 0 16 16" fill="none" aria-hidden="true" {...stylex.props(group.icon)}>
      <path
        d="M1.5 8S3.8 3.5 8 3.5 14.5 8 14.5 8 12.2 12.5 8 12.5 1.5 8 1.5 8Z"
        stroke="currentColor"
        strokeWidth="1.25"
        strokeLinejoin="round"
      />
      <circle cx="8" cy="8" r="2" stroke="currentColor" strokeWidth="1.25" />
    </svg>
  );
}

function EyeOffIcon() {
  return (
    <svg viewBox="0 0 16 16" fill="none" aria-hidden="true" {...stylex.props(group.icon)}>
      <path
        d="M6.6 3.65A6.9 6.9 0 0 1 8 3.5c4.2 0 6.5 4.5 6.5 4.5a11 11 0 0 1-1.7 2.3M4.3 4.9C2.5 6.1 1.5 8 1.5 8s2.3 4.5 6.5 4.5c1.4 0 2.6-.5 3.6-1.2M6.6 6.6a2 2 0 0 0 2.8 2.8M2 2l12 12"
        stroke="currentColor"
        strokeWidth="1.25"
        strokeLinecap="round"
        strokeLinejoin="round"
      />
    </svg>
  );
}

/**
 * PasswordInput — Ark UI's password-input machine wearing the input recipe.
 * `<PasswordInput.Root variant size>` resolves the recipe once and every
 * part inherits it via context; the machine owns visibility (`visible`,
 * `defaultVisible`, `onVisibilityChange`), wires the Label to the Input,
 * swaps the input `type`, and labels the toggle "Show password" / "Hide
 * password". VisibilityTrigger ships the eye icons through Indicator.
 * Every part composes via `asChild`.
 */
export type PasswordInputRootProps = WithStyleOverrides<
  React.ComponentProps<typeof ArkPasswordInput.Root>
> &
  Partial<PasswordInputVariants>;

const PasswordInputRoot = withProvider(ArkPasswordInput.Root, "root", "PasswordInputRoot");

function Root({ palette = accentPalette, ...props }: PasswordInputRootProps) {
  return (
    <PasswordInputRoot
      palette={palette}
      {...(props as React.ComponentProps<typeof PasswordInputRoot>)}
    />
  );
}
Root.displayName = "PasswordInputRoot";

const StyledIndicator = withContext(
  ArkPasswordInput.Indicator,
  "indicator",
  "PasswordInputIndicator",
);

/**
 * Indicator — renders `children` while the password is visible and
 * `fallback` while it is masked. Defaults: eye-off / eye.
 */
function Indicator(props: React.ComponentProps<typeof StyledIndicator>) {
  const { children, fallback, ...rest } = props;
  return (
    <StyledIndicator fallback={fallback ?? <EyeIcon />} {...rest}>
      {children ?? <EyeOffIcon />}
    </StyledIndicator>
  );
}
Indicator.displayName = "PasswordInputIndicator";

const StyledVisibilityTrigger = withContext(
  ArkPasswordInput.VisibilityTrigger,
  "visibilityTrigger",
  "PasswordInputVisibilityTrigger",
);

function VisibilityTrigger(props: React.ComponentProps<typeof StyledVisibilityTrigger>) {
  const { children, ...rest } = props;
  return <StyledVisibilityTrigger {...rest}>{children ?? <Indicator />}</StyledVisibilityTrigger>;
}
VisibilityTrigger.displayName = "PasswordInputVisibilityTrigger";

export const PasswordInput = {
  Root,
  Label: withContext(ArkPasswordInput.Label, "label", "PasswordInputLabel"),
  Control: withContext(ArkPasswordInput.Control, "control", "PasswordInputControl"),
  Input: withContext(
    ArkPasswordInput.Input,
    (v) => [
      ...resolveSlotStyles(passwordInputRecipe.slots.input, v),
      inputTextStyles[v.size],
      group.input,
    ],
    "PasswordInputInput",
  ),
  VisibilityTrigger,
  Indicator,
  Context: ArkPasswordInput.Context,
};
```
