# Accordion
An expand/collapse panel list — like a FAQ section or a step-by-step guide where the user reveals each answer one at a time.
---
## Quick example
```csharp
new Accordion(
id: "faq",
items: new[]
{
("What is this?", "A fast HTMX app framework."),
("Is it AOT-safe?", "Yes, fully."),
("Do I need Node?", "Only for the Tailwind build step."),
})
```
That's it. Drop this into a page slot and you have a working FAQ section.
---
## All the options
```csharp
public Accordion(
string id,
IEnumerable<(string Title, string Content)> items,
int openIndex = -1)
```
| Parameter | What it does |
|---|---|
| `id` | A unique identifier for this accordion on the page. If you have two accordions on the same page, they need different ids. |
| `items` | The list of panels. Each item is a pair: the header text (`Title`) and the body content (`Content`). |
| `openIndex` | Which panel should start open. `0` = first panel, `1` = second, `-1` = all closed (default). |
---
## Real-world examples
### FAQ page with the first item pre-opened
```csharp
new Accordion(
id: "faq",
items: new[]
{
("How do I reset my password?", "Go to Settings → Security → Reset Password."),
("How do I cancel my account?", "Contact support from the Help page."),
("Where are my invoices?", "Under Billing in your account dashboard."),
},
openIndex: 0) // first answer visible on load
```
### Step-by-step guide with HTML content inside items
Item `Content` is rendered as raw HTML, so you can use markup inside it:
```csharp
new Accordion(
id: "setup-guide",
items: new[]
{
("Step 1 — Install dependencies",
"Run npm install inside the Htmx.ApiDemo folder."),
("Step 2 — Start MongoDB",
"
Start the MongoDB service, then confirm it is running on localhost:27017.
dotnet run --project Htmx.ApiDemo and open http://localhost:5120."),
},
openIndex: 0)
```
> **Important:** `Title` and `Content` are inserted as raw HTML. If either value comes from user input or a database, HTML-encode it first:
> ```csharp
> System.Web.HttpUtility.HtmlEncode(userTitle)
> ```
### Inside a page
```html
dotnet publish -c Release for a native AOT binary."),
});
}
protected override void RenderFaqAccordion(HtmxRenderContext ctx)
=> _faq.Render(ctx.Next());
}
```
**`Templates/FaqPage.htmx.cs` — GET handler**
```csharp
[Handler]
[MapGet("/faq")]
public static partial class GetFaqHandler
{
public record Query();
private static Task