DEV Community

Kristian Hviid Nielsen
Kristian Hviid Nielsen

Posted on

How to structure your html?

I've been learning web dev for a few months now, and getting comfortable with the basics. But I find it hard to keep track of my html files when it becomes too nested, so I've been looking at ways to structure it and create modules.

  1. Have a div with an onload link to an external html file. It can end up being a lot of files for a single page of a site, but other than that, it seems to work okay.

  2. To use vanilla JS to createElement() with loops and appendChild() to divs on window.onload. This makes it easy to create, add, remove and reuse elements as needed.

I'm wondering if there's a best practice for structuring your html in a modular way that I'm not aware of?

Top comments (1)

Collapse
 
ben profile image
Ben Halpern

Ultimately the opinions here are going to likely be that of the framework/environment you wind up working in. As long as there is consistency and an understandable pattern, there is likely no universally correct answer.

In general these things wind up being a give and take, so pay attention to what's working and learn by observing where you can, but if you're not sure, don't sweat it too much.