返回模板

Accessible FAQ accordion

A native <details>/<summary> FAQ accordion requiring zero JavaScript and supporting keyboard navigation.

用这个模板

完整源码

1 行 · 1.1 KB
<style>*{box-sizing:border-box}body{margin:0;font-family:Inter,system-ui,sans-serif;background:#f6f7fb;color:#172033}button,a{font:inherit}.wrap{width:min(960px,calc(100% - 32px));margin:auto}</style><style>main{padding:56px 16px}.faq{max-width:680px;margin:auto}details{background:#fff;border:1px solid #e2e8f0;border-radius:12px;padding:16px 20px;margin:12px 0}summary{font-weight:700;cursor:pointer;list-style:none}details p{margin:12px 0 0;color:#475569;line-height:1.65}</style><main><section class="faq"><h1 style="text-align:center;margin-bottom:28px">Frequently Asked Questions</h1><details open><summary>Do native details elements work without JavaScript?</summary><p>Yes. Browsers handle keyboard toggling, focus, and expanded semantics natively.</p></details><details><summary>Can multiple sections stay open at once?</summary><p>Yes, unless you add a matching name attribute to group them into a mutually exclusive accordion.</p></details><details><summary>How should answers be written?</summary><p>Keep each answer direct and concrete so readers find the rule in one scan.</p></details></section></main>

适用场景

纯原生 HTML `<details>` 与 `<summary>` 实现的常见问题手风琴页面,无需一行 JavaScript。

布局原理

浏览器原生支持焦点切换、回车/空格展开以及无障碍状态播报,结构极简稳健。

如何定制

问题较多时可按主题分组展示,每个回答尽量在前两句给出明确结论。

发布前检查

测试键盘开关体验及 200% 放大时的排版稳定性。

带着上下文继续制作

在编辑器中改编示例之前,可以先比较相关模式或阅读实用指南。