robertlib

Required Mark

Forms

About

A small asterisk badge placed after a form field's label to visually flag it as required, hidden from screen readers since the control itself announces required state.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Required Mark to your project and fits it to your theme.

Code

How Required Mark is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

import RequiredMark from "@/components/ui/required-mark";

export default function RequiredMarkDemo() {
  return (
    <div className="grid gap-8 sm:grid-cols-2">
      {/* Labels laid out by hand - the star is the eye's cue, the control's
          own `required`/`aria-required` is what a screen reader announces */}
      <div className="grid gap-3">
        <span className="text-sm font-medium text-foreground">
          Full name <RequiredMark />
        </span>
        <span className="text-sm font-medium text-foreground">
          Email address <RequiredMark />
        </span>
        <span className="text-sm font-medium text-foreground">
          Terms and conditions <RequiredMark />
        </span>
      </div>

      {/* A form that marks its optional fields instead - this hides the
          stars inside it */}
      <div className="grid gap-3" data-required-mark="hidden">
        <span className="text-sm font-medium text-foreground">
          Full name <RequiredMark />
        </span>
        <span className="text-sm font-medium text-foreground">
          Note (optional)
        </span>
      </div>
    </div>
  );
}

More by robertlib

View all
  • Timeline

    Timeline

    17
  • Switch

    Switch

    9
  • Chip

    Chip

    7
  • Spinner

    Spinner

    5
  • Empty State

    Empty State

    5
  • Progress Indicator

    Progress Indicator

    5
  • Collapsible Content

    Collapsible Content

    4
  • Checkbox

    Checkbox

    3

More in Forms

View all
  • Premium Auth

    Premium Auth

    593
  • Contact Form

    Contact Form

    28
  • Form

    Form

    4
  • Login 1

    Login 1

    70
  • Book A Demo 1

    Book A Demo 1

    94
  • Contact Card

    Contact Card

    1.1K
  • HeroUI Field Error

    HeroUI Field Error

    13
  • Form [react-aria-components]

    Form [react-aria-components]

    19