General question on <DIV> tags

I have a question on why people use so many div tags and I think I read somewhere, where it said it’s not good practice to have

s everywhere.

Even tho I see them, I was wondering if anyone could help me to learn to use divs a lot and structure my code, so I can properly implement javascript and CSS.

Using a lot of div tags in HTML is a common practice to create structure and layout for web pages. However, using them excessively or improperly can result in bloated and confusing code that is difficult to maintain and style.

One way to structure your HTML code using div tags is to create container elements for different sections of the page, such as header, main content, footer, and sidebar. Within each of these container elements, you can use nested div tags to further structure and organize the content.

It is also important to use semantic HTML elements whenever possible, instead of relying solely on div tags. Semantic elements, such as header, nav, article, section, and footer, provide more meaningful and accessible structure to the content, and can improve the SEO and usability of the website.

When implementing JavaScript and CSS, you can use classes and IDs to target specific elements in your HTML code. By adding classes and IDs to your div tags or other semantic elements, you can apply styles and functionality to them in a more targeted and organized way.

In summary, using div tags is a common practice for creating structure and layout in HTML, but it’s important to use them in a structured and organized way. Consider using semantic HTML elements, and use classes and IDs to target specific elements for styling and functionality.

2 Likes