Tree views in CSS
iamkate.com·2d
🎨Modern CSS
Preview
Report Post

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...