Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are these DIVs really necessary?

Tags:

html

css

I sometimes find myself creating a div which serves no other purpose than to hold another element.

For example when creating a menu, I would create a div and assign it a background colour, position etc. Then within it I would create an unordered list.

I could surely assign all the properties I assigned to the DIV to the UL and not use a div at all.

Any ideas of what is best practice and reasons for it.

Thanks

Zenna

like image 857
zenna Avatar asked Jul 22 '26 19:07

zenna


1 Answers

DIVs can be useful for grouping semantically related elements. If you are simply wrapping a single element that is also a block element, then you are simply adding bytes to the file.

like image 163
geowa4 Avatar answered Jul 24 '26 12:07

geowa4



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!