Search documentation v0.8.1

FAQ

Organize frequently asked questions

Source ↗️ Report Issue ↗️

Use the FAQ component to organize frequently asked questions and answers in a clear, accessible format, enhancing user experience by addressing common inquiries. You can set your FAQ items using the Accordion component, set a heading for the section, and pass any element to display it under the heading:

Preview
Frequently Asked Questions Looking for a specific page? Find them below:
  • We provide 30 days of support.
  • Yes!
  • Hopefully.
How to use the FAQ component in Astro
---
const accordionItems = [{
title: 'Do you offer support?',
content: 'We provide 30 days of support.'
}, {
title: 'Can I request changes?',
content: 'Yes!'
}, {
title: 'Are there any refunds?',
content: 'Hopefully.'
}]
---
<FAQ items={accordionItems}>
<span class="muted">Looking for a specific page? Find them below:</span>
<Tiles items={[
{ icon: 'github', label: 'GitHub', href: '' },
{ icon: 'file', label: 'Documentation', href: '' }
]} columns={1} />
</FAQ>

The FAQ block uses the Accordion component internally. To set the FAQ items, pass an items prop to the FAQ component with the same structure as Accordion items.

See the documentation of the Accordion component to learn more about how to use it with and without this block.

You can pass additional elements as the children to the component to render extra content next to your FAQ items. In the above example, the Tiles block was used as the children. To read more about the Tiles block, visit its documentation page. To set the title of the block, use the title prop:

FAQ Addition text set as the children
  • We provide 30 days of support.
  • Yes!
  • Hopefully.
<FAQ
items={[ ... ]}
title="FAQ"
{/* Accordion-specific props: */}
icon="plus"
reverse={true}
>
<span class="muted">Addition text set as the children</span>
</FAQ>

Customize HTML

By default, the title will be set using an h2 element. To change this, specify the titleTag prop. The entire block is rendered into a section element. This can also be customized using the element prop:

<FAQ
items={[ ... ]}
title="FAQ"
titleTag="h3"
element="article"
/>

API

type FAQProps = {
element?: string
title?: string
titleTag?: string
items: {
title: string
content: string
reverse?: boolean
}[]
icon?: 'plus' | 'none'
reverse?: boolean
className?: string
}
PropDefaultPurpose
element section Sets the HTML tag of the FAQ section.
title Frequently Asked Questions Sets the title of the FAQ section.
titleTag h2 Sets the HTML tag of the FAQ section's header.
items - Sets the FAQ items.
items.title - Sets the heading for the FAQ item.
items.content - Sets the content for the FAQ item.
items.reverse - Changes the order of the FAQ heading and icon.
icon - Changes the style of the icon on the FAQ items.
reverse false Changes the order of all FAQ headings and icons.
className - Pass additional CSS classes for your FAQ component.

Request improvement for this page