# Tree
[component-header:sl-tree]
A tree component allow the user to display a hierarchical list of items, expanding and collapsing the nodes that have nested items.
The user can select one or more items from the list.
```html preview
Getting Started
Overview
Quick Start
New to Web Components?
What Problem Does This Solve?
Browser Support
License
Attribution
Installation
Usage
Frameworks
React
Vue
Angular
Resources
```
```jsx react
import { SlTree, SlTreeItem } from '@shoelace-style/shoelace/dist/react';
const App = () => (
Getting Started
Overview
Installation
Usage
Frameworks
React
Vue
Angular
Resources
);
```
## Examples
### Selection modes
Use the `selection` attribute to specify the selection behavior of the tree
- Set `none` (_default_) to disable the selection.
- Set `single` to allow the selection of a single item.
- Set `leaf` to allow the selection of a single leaf node. Clicking on a parent node will expand/collapse the node.
- Set `multiple` to allow the selection of multiple items.
```html preview
none
single
leaf
multiple
Parent
Parent 1
Child 1
Child 2
Parent 2
Child 1
Child 2
Child 3
```
```jsx react
import { SlTree, SlTreeItem } from '@shoelace-style/shoelace/dist/react';
const App = () => {
const [selection, setSelection] = useState('none');
return (
<>
setSelection(event.target.value)}>
none
single
leaf
multiple
Parent
Parent 1 Child 1
Child 2
Parent 2 Child 1
Child 2
Child 3
>
);
};
```
### Lazy loading
Use the `lazy` attribute on a item to indicate that the content is not yet present and will be loaded later.
When the user tries to expand the node, the `loading` state is set to `true` and a special event named
`sl-lazy-load` is emitted to let the loading of the content. The item will remain in a loading state until its content
is changed.
If you want to disable this behavior, for example after the content has been loaded, it will be sufficient to set
`lazy` to `false`.
```html preview
Getting Started
```
```jsx react
import { SlTree, SlTreeItem } from '@shoelace-style/shoelace/dist/react';
const App = () => {
const [childItems, setChildItems] = useState([]);
const [lazy, setLazy] = useState(true);
const handleLazyLoad = () => {
// Simulate asynchronous loading
setTimeout(() => {
setChildItems(['Overview', 'Installation', 'Usage']);
// Disable lazy mode since the content has been loaded
setLazy(false);
}, 2000);
};
return (
Getting Started
{childItems.map(item => (
{item}
))}
);
};
```
### Styling trees
Using CSS parts is possible to apply custom styles to the tree.
For example, it is possible to change the hover effect and to highlight the selected item.
```html preview
Getting Started
Overview
Quick Start
New to Web Components?
What Problem Does This Solve?
Browser Support
License
Attribution
Installation
Usage
Frameworks
React
Vue
Angular
Resources
```
### With indentation lines
```html preview
Getting Started
Overview
Quick Start
New to Web Components?
What Problem Does This Solve?
Browser Support
License
Attribution
Installation
Usage
Frameworks
React
Vue
Angular
Resources
```
### With icons
```html preview
Root
Folder 1
File 1 - 1
File 1 - 2
File 1 - 3
Folder 2
File 2 - 1
File 2 - 2
File 1
```
[component-metadata:sl-tree]