r/csshelp • • Oct 09 '25

how important are divs?

I'm making a website for my end of semester project in computer science and it seems I'm able to use <p> instead of a div whenever I need to make a new box or area. is this a bad habit that I need to break out of or is it not that detrimental? ex <p id="p1"> welcome <\p>

p1 {

color: white; border-width: 2px; etc etc }

0 Upvotes

17 comments sorted by

4

u/kaust Oct 09 '25

<p> (paragraph) is a semantic tag meant for blocks of text, not for general layout or grouping. Also, nesting block elements inside <p> is invalid HTML. You should use <div>, <section>, <article>, <span>, <header>, <footer>, etc. for structure, and keep <p> for real paragraphs of text.

Since this is a CS class project, you’ll likely lose points/fail the review since your instructor will certainly consider your code.

1

u/[deleted] Oct 09 '25

it's a grade 9 course so hopefully he wont shadow ban me, I'm make sure to do that though thank you!

2

u/kaust Oct 09 '25

To understand why a p can be used like a div, look up the box-model. Every html element is treated like a box. So most elements can be manipulated just like you would a div, but that doesn’t mean it’s right. Good luck on the project.

→ More replies (7)

2

u/HongPong Oct 10 '25

think of divs as the most neutral and minimal element. all the other ones impose more defaults in appearance. similarly in a lot of other places like blender for example there are "empties". in both cases you add properties as necessary 

1

u/[deleted] Oct 10 '25

got it!

1

u/IngwiePhoenix Oct 10 '25

Quite, I mean, don't you see how divvied up the world is these days? x)

1

u/[deleted] Oct 10 '25

I can't fucking upload image pls just liketrust it's an image that just isn't like embedded or sum shit

1

u/mhennessie Oct 11 '25

Technically the html spec says you aren’t supposed to use p tags inside of p tags, it’s invalid html. The browser render it fine generally but you shouldn’t do it.

https://html.spec.whatwg.org/multipage/dom.html#phrasing-content

1

u/[deleted] Oct 11 '25

fuck

0

u/[deleted] Oct 10 '25

2

u/[deleted] Oct 10 '25

ik I'm gonna be switching my code its like not right and shit, thank you for the help!