Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Anchor Link FAQ Block for React

A FAQ for a documentation host with a # link on every question that copies its address, and deep links that open and ring the matching answer on load.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

An anchor-link FAQ for React with Base UI. Seven questions sit in a band of hairline rows that run from rail to rail, and each row has a # link at its start. Pressing it copies that answer's address and confirms in a status line beside the title; opening an address that ends in a question's anchor opens that row on load, brings it to the top of the screen and rings it until the next click. The # is always on show, so it works with a finger as well as a pointer. The page's rails and top rule come from the Guides spine, so the block lines up with its neighbours in a stack. It's built from Accordion and Guides, with CSS transitions for the entrance and the ring, and your theme's tokens for every colour. For documentation, help centres and knowledge bases where support sends people to one answer.

FAQ

What does the # copy, and what if the clipboard refuses?

It copies the link's full address: the page's own URL plus the row's anchor. The status line beside the title shows the address without its https://, and the # turns into a check for three seconds. The link also navigates, so the address bar holds it too; if the browser refuses clipboard access (a page that isn't served over HTTPS), the status line says so instead of claiming success.

How do I add or rename a question?

Edit QUESTIONS at the top of the file: each entry is an id, the question and its answer. The id becomes the anchor, so keep it stable once links are out in the world; changing the question's wording is safe. OPEN_QUESTION names the row that's open when the address has no anchor. One answer is open at a time.

Are the closed answers in the page's markup?

Yes. The Accordion takes hiddenUntilFound, so every closed answer stays in the markup as hidden="until-found", and the browser's find in page opens the answer that holds a match.

How does it work with a keyboard and a screen reader?

Each question is a button inside its own h3, and each # is a real link named "Link to" and the question, placed right after its row. Tab goes from a question to its link and on to the next question; Enter on a link copies the address and follows it. The status line is a polite live region, so the copy is announced.

Does it work on a phone?

Yes. The # is never hidden behind a hover: it sits in a 32 pixel square at the start of every row, and the question's text starts after it. The status line moves under the title, the rows run from rail to rail, and nothing scrolls sideways at 320 pixels.

What moves, and what happens with reduced motion?

The header and the rows fade up once when the page loads, the ring fades in, and an answer eases open. With reduced motion the entrance and the ring's fade are off, and the answers open and close at once. Scrolling to a deep link is a jump, never a smooth scroll.

  • Pro

    Share Popover FAQ

    Reading and sharing

    A FAQ for an event ticketing platform whose open answer ends in a Share button: a popover with a copy-link button, an email and a QR code of the answer's link.

  • Pro

    Related Questions FAQ

    Reading and sharing

    A cross-linked FAQ for a password manager: every answer ends in two related questions, and choosing one opens that row, scrolls to it and moves focus to its question.

  • Pro

    Copy Reply FAQ

    Reading and sharing

    A support playbook FAQ for a help desk: each situation opens on the team's advice and a reply to send, with its length in characters and a Copy reply button.

  • Pro

    A FAQ for an object-storage service with a sticky table of contents: three topics and their questions in an outline that follows the reader, beside topic bands that each hold an accordion.

  • Pro

    Accordion FAQ

    Accordion lists

    A side-header FAQ for a web analytics tool: the title, one sentence and a contact prompt beside seven questions in an accordion, behind a split divider.

  • Pro

    Multi-Language FAQ

    Reading and sharing

    An FAQ in English, Spanish and Arabic for a relocation service: a language switcher swaps the title, questions and answers, and sets lang and dir so Arabic lays the block out from its end.