How many containers do i need to contain an element?

Hi, i am trying to write my own code on my computer to make a website. I am just wondering how many containing/parent elements (or levels of nested elements) i should be making? i mean is there a good rule of thumb that i dont know about? any help is appreciated.

Hi there!

The amount of containers you use is down to personal preference. If you inspect some websites, some of them have containers, in containers, in containers, in containers. However, some others use one or two.

When designing the website/project, it’s good to think of what’s needed when creating certain elements. Do you want one container to control spacing and placement? Or do you want two to cover them separately?

But I would also add that at the end of the day, you should use a system that you’re comfortable with. If you find it easier to maintain more containers, use more containers. Less? Then use less.

I hope this helps. :slight_smile:

Happy coding!


And don’t be afraid to add and delete containers! Especially when adding CSS and JS to a project, simply adding a <div> container can help with a ton of headaches!