DEV Community

Cover image for File Tree Structure using CSS
Ambuj sahu
Ambuj sahu

Posted on

19

File Tree Structure using CSS

File tree structure

It is very simple but amazing file structure design in Pure CSS that you can apply to an unordered list, just follow the below steps : -

  • create a simple html file
  • use nested HTML Unordered Lists ```html
  • root
    • folder one
      • file_one.txt
      • file_two.txt
    • folder two
      • file_one.txt
      • file_two.txt

- Add a span inside every li element
```html


<li><span></span>file_one.txt</li>


Enter fullscreen mode Exit fullscreen mode
  • you can add some folder and files icon or svg in the li element to make the file tree structure look more real

    • folder icon

folder icon



    <li><span></span><i class="fa-regular fa-folder-open"></i>root<ul>...rest</li>


Enter fullscreen mode Exit fullscreen mode
  • Now finally add some css magic to complete the file tree structure.

    • create L shape line by adding following css to the empty span. ```css

    border-bottom: 1px solid;
    border-left: 1px solid;
    height: 1.5rem;
    width: 2rem;
    display: inline-block;
    margin-bottom: 0.3rem;
    margin-left: 1rem;

- final output preview

![final preview](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aqmm3d7wqubd9vzcgkyf.jpg)

- you can find live example [here](https://ambujsahu81.github.io/Notes/)
- Also checkout the code pointer for the same [code sample]
(https://github.com/ambujsahu81/Notes/blob/bd519982ed638d2aabff90b1c71f501c89aa0603/docs/main.js#L187)


Enter fullscreen mode Exit fullscreen mode

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay