glasscn
ShowcaseDocsComponentsStudioThemingNative
5Get started
Guides
IntroductionInstallationThemingFonts & typeStudioReact Native
Surfaces
AuroraBackdropGlassLiquid glassCardTheme scopeBackground extensionScroll areaAccordionCollapsibleAlertItemEmpty
Typography
TypographyProse
Controls
ButtonBadgeInputTextareaLabelSwitchCheckboxSegmented controlTabsGlass groupGlass clusterGlass morphSliderProgressKbdSeparatorAvatarGlass preferencesComboboxCalendarDate pickerSpinnerSkeletonSelectRadio groupFieldInput groupButton groupToggleToggle groupStepper
Overlays
DialogAlert dialogSheetAction sheetPopoverTooltipDropdown menuToasterCommandDrawerContext menuConfirmation popover
Navigation
DockToolbarScroll edgeNavigation barSidebarSearch fieldGrouped list
Data
Activity ringsProgress ringSparklineStatKPIWidgetRange chartBar listGaugeTrackerCategory barHeatmapChartArea chartBar chartLine chartDonut chartTableData table
Chat
ChatChat markdownChat parts
Blocks
More Apple glass examplesLiquid Glass examplesDashboardAnalyticsSettingsSign inChat
glasscn — a shadcn registry. Copy it, own it, change it.DocsThemingregistry.json
Controlsradix-ui

Label

An accessible label.

Installation

pnpm dlx shadcn@latest add https://glasscn.app/r/label.json

React Native (iOS, Android and web through react-native-web) — same parts and props:

pnpm dlx shadcn@latest add https://glasscn.app/r/native-label.json

Or with the namespace set up: shadcn add @glasscn-app/label

Props

PropTypeDefault
requiredboolean

A marker after the text (hidden from screen readers — mark the control required too).

false
optionalboolean | string

A quiet "(optional)" hint, or your own text.

false

Source

components/glass/label.tsx
"use client"

import * as React from "react"
import { cn } from "@/lib/glass-cn"
import { Label as LabelPrimitive } from "radix-ui"

/**
 * An accessible label. `required` adds a marker (hidden from assistive tech — mark the control
 * `required` too); `optional` adds a quiet "(optional)" hint.
 */
function Label({
  className,
  required,
  optional,
  children,
  ...props
}: React.ComponentProps<typeof LabelPrimitive.Root> & { required?: boolean; optional?: boolean | string }) {
  // markers only when asked: with asChild, Radix needs a single child
  const content =
    required || optional ? (
      <>
        {children}
        {required ? (
          <span aria-hidden data-slot="label-required" className="-ms-1.5 text-destructive-ink">
            *
          </span>
        ) : null}
        {optional ? (
          <span data-slot="label-optional" className="font-normal text-muted-foreground">
            {typeof optional === "string" ? optional : "(optional)"}
          </span>
        ) : null}
      </>
    ) : (
      children
    )
  return (
    <LabelPrimitive.Root
      data-slot="label"
      className={cn(
        "flex items-center gap-2 text-sm leading-snug font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:text-glass-label-tertiary peer-disabled:cursor-not-allowed peer-disabled:text-glass-label-tertiary",
        className
      )}
      {...props}
    >
      {content}
    </LabelPrimitive.Root>
  )
}

export { Label }
TextareaSwitch