Last year my colleague Christophe suggested that I add a table of contents and anchor links on the FAQ page of tinytex (#94, #95), which were definitely good ideas. This week I took some time to reorganize my miscellaneous JavaScript code, learned a little bit about NPM, and published my scripts as a Node package.1
During this process, I wrote another little script to convert an ordered list on an HTML page into a collapsible FAQ list. Basically, all you need to do is load the script and stylesheet in your HTML or (R) Markdown document:
<link href="https://cdn.jsdelivr.net/npm/@xiee/utils/css/faq.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/@xiee/utils/js/faq.min.js" defer></script>
Demo
Below is a quick demo:
-
What’s the answer to life, the universe, and everything?
-
Who is Frida Gomam?
This clever lady: https://www.reddit.com/r/funny/comments/9u22lb/frida_gomam/
-
How to quit vim?
But why?
You can click on each question to reveal or hide its answer. Or click on the ⊕
button at the top-right to expand/collapse all answers. When you mouse over a
question, its anchor link (denoted by the # symbol) will become visible at the
end. You can use the link to point to a specific FAQ item, e.g.,
https://yihui.org/tinytex/faq/#faq-3.
Selection of ordered lists
This JS program looks for all ordered lists (<ol>) on a page, and turns a list
into an FAQ list if it satisfies the following conditions:
- It either has no
classattribute, or contains anfaq-listclass; - Each of its child element contains at least two child elements (the first one is the question, and the rest is the answer);
- It is a direct child of
<div>,<main>,<section>, or<article>, and the container does not have thefootnotesclass (to avoid accidentally converting footnote items into FAQ lists).
For example, the above ordered list was ignored by this program because its child items only contain one child.
Styling
A class faq-list will be added onto the <ol> element, and you can style the
list using CSS rules if you are not satisfied with the default minimal styling.
For example, since it is Halloween, let’s make the list a little spooky:
<style type="text/css">
.faq-list > li {
border-color: ghostwhite;
}
.faq-list > li > :first-child, .faq-button {
background: darkorange;
color: ghostwhite;
font-family: Papyrus, fantasy;
}
</style>
Then you get an orange theme like this:

Related work
This JS application was inspired by Jiena’s awesome faq package, which is an HTML widget package that allows you to create an FAQ list from a data frame in R. You can use it in either R Markdown or Shiny apps. Thanks Jiena!2
Please feel free to let me know if you have any suggestions or feedback. You can either leave a comment below or file an issue to GitHub.
Donate
As a freelancer (currently working as a contractor) and a dad of three kids, I truly appreciate your donation to support my writing and open-source software development! Your contribution helps me cope with financial uncertainty better, so I can spend more time on producing high-quality content and software. You can make a donation through methods below.
-
Venmo:
@yihui_xie, or Zelle:xie@yihui.name -
Paypal
-
If you have a Paypal account, you can follow the link https://paypal.me/YihuiXie or find me on Paypal via my email
xie@yihui.name. Please choose the payment type as “Family and Friends” (instead of “Goods and Services”) to avoid extra fees. -
If you don’t have Paypal, you may donate through this link via your debit or credit card. Paypal will charge a fee on my side.
-
-
Other ways:
WeChat Pay (微信支付:谢益辉) Alipay (支付宝:谢益辉) 

When sending money, please be sure to add a note “gift” or “donation” if possible, so it won’t be treated as my taxable income but a genuine gift. Needless to say, donation is completely voluntary and I appreciate any amount you can give.
Please feel free to email me if you prefer a different way to give. Thank you very much!
I’ll give back a significant portion of the donations to the open-source community and charities. For the record, I received about $30,000 in total (before tax) in 2024-25, and gave back about $15,000 (after tax).