Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Age Verification

ProNew

A full-screen age gate that asks yes or no, a date of birth or a birth year, in four layouts, with a denied screen and a remembered answer for returning visitors.

Installation

pnpm dlx shadcn@latest add @viewport/age-verification

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
mode"confirm" | "birthdate" | "year"

`confirm` asks yes or no, `birthdate` asks for the full date, `year` only for the year of birth.

"confirm"
minAgenumber

The age a visitor must have reached.

18
layout"card" | "split" | "panel" | "bare"

`card` is a centred card, `split` a form beside a photo, `panel` a dark glass panel and `bare` text straight on the backdrop.

"card"
titlestring"Are you of legal age?"
messageReact.ReactNode—
logoReact.ReactNode

Your logo, above the title.

—
imagestring

Photo URL: the backdrop, or the side picture in the `split` layout.

—
confirmLabelstring

Label of the yes button. Defaults to "I am 18 or older" with your `minAge`.

—
denyLabelstring

Label of the no button.

—
submitLabelstring

Label of the button under the date fields.

"Enter"
dateOrder"mdy" | "dmy" | "ymd"

Order of the date fields in `birthdate` mode.

"mdy"
footerReact.ReactNode

Small print under the buttons, e.g. a link to your terms.

—
colorstring

Color of the main button.

—
buttonTextColorstring

Text color on the main button.

—
rememberboolean

Keeps a yes for `rememberDays`, so returning visitors are not asked again.

true
rememberToggleboolean

Shows a "Remember me" checkbox so the visitor decides.

false
rememberDaysnumber

How long a yes is kept. A no is kept for one day at most.

30
storageKeystring | null

localStorage key the answer is kept under. Pass `null` to keep nothing.

"age-verification"
deniedTitlestring"Sorry, you can’t come in"
deniedMessageReact.ReactNode—
allowRetryboolean

Lets a visitor who was turned away go back and answer again.

true
exitHrefstring

Adds a "Leave site" link to the denied screen.

—
onVerify() => void

Called when the visitor passes.

—
onDeny() => void

Called when the visitor is too young or says no.

—
openboolean

Shows or hides the gate yourself. Overrides the stored answer.

—
containedboolean

Covers the nearest `relative` parent instead of the window, and does not trap focus. For previews.

false
classNamestring—

Accessibility

  • The gate is a modal dialog: focus is trapped inside, Escape and outside clicks do nothing, and focus goes back to the page once the visitor passes.
  • Date fields are a labelled group of numeric inputs with autocomplete hints; they advance as they fill and Backspace steps back.
  • A date that is not real is announced as an alert, the fields are marked invalid and focus returns to the one to fix.
  • The denied screen takes focus when it replaces the form, so it is read at once. Under reduced motion nothing scales or shakes.