A tree view (collapsible list) can be created using only HTML and CSS, without the need for JavaScript. Accessibility software will see the tree view as lists nested inside disclosure widgets, and the standard keyboard interaction is supported automatically.

  • Giant planets

  • Gas giants

  • Jupiter

  • Saturn

  • Ice giants

  • Uranus

  • Neptune

The HTML

We begin with the HTML for simple nested lists:

```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

|

  • Giant planets
    • Gas giants
      • Jupiter
      • Saturn
    • Ice giants
      • Uranus
      • Neptune
``` |

We then add a class to the outermost <ul> element, and for each list item that contains a nested list, we put …

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help