Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it bad to use many div's in a single page?

Tags:

html

css

This is the first time i am properly coding in HTML,CSS. in my code i have used whole lot of div's to position and also to put the content in place. i am not sure if i am coding the right way. i have loads of contents too in a single page. here is the link to my code i have used.

http://jsfiddle.net/32ShZ/

can you please suggest. is it really bad in structure and shape?

like image 709
Ibrahim Azhar Armar Avatar asked Sep 25 '10 18:09

Ibrahim Azhar Armar


People also ask

Is it bad to use too many divs?

A <div> by definition is a meaningless element, so it doesn't matter how many of them you have. However, you need to have <div> s on your page as long as they make sense, and to not use them if there are elements better suited for the job (semantically). And such. That makes sense.

Are nested divs bad practice?

There is nothing wrong with nesting div elements, but it is possible to overuse or misuse the div element. When we first made the move to CSS-based layouts from tables, it was common to see pages marked up with div elements replacing every table, table row, and table cell that would have been used otherwise.

Why should you avoid using the div element when possible?

Use of more appropriate elements instead of the div element leads to better accessibility for readers and easier maintainability for authors.

Is it good to use div?

The Div is the most usable tag in web development because it helps us to separate out data in the web page and we can create a particular section for particular data or function in the web pages. It is used to the group of various tags of HTML so that sections can be created and style can be applied to them.


2 Answers

Absolutely not. You don't want to go overboard though (it's called "div soup" when you do). If you find that a div has no purpose but to hold a background image, or to clear a float, etc that means you've done something wrong. By using wrappers (e.g. 3 levels deep of div tags for a content area that has some backgrounds, etc is OK), you can properly achieve any layout that you need without resorting to "div soup". Take a look at http://www.digitalperfections.net/ for an example of good (x)HTML with a lot of div tags.

To further expand, and answer the question about your code specifically, I noticed one thing right off the bat: <div id="divider"></div> - this is bad because you're using this div purely for non-semantic purposes (for decoration only).

like image 143
orokusaki Avatar answered Sep 25 '22 17:09

orokusaki


The general principle is use as less HTML for layout as possible. And try to give Style to your page with the help of CSS. So if a minimum number of divs can achieve your task, you should go for it. This helps to make page lighter and maintainable. But yes how small structure (HTML) you can have in your page depends on your experience and design.

like image 25
sushil bharwani Avatar answered Sep 22 '22 17:09

sushil bharwani