What exactly is the difference between div and section tags?

section class=“cooked”
label for=“doneness” How do you want your patty cooked? /label
/section

I’ve come across section tag in my html lesson but can’t div tag be used instead? I know div element can envelop h1, p etc tags…

div
h1 A section of grouped elements /h1
p Here’s some text for the section/p
/div

From what I understood, section’s opening tag has class attribute which will probably be used by CSS, but div doesn’t have such options? Is that it?

Hello @prathyush6460409269!! Welcome to the forums!!

The section tag is used to create a ‘new’ section of the webpage, were as the div tag has no effect on the HTML and is only used to group items together for styling.

Check these out


And actually div does have class and id attributes.
For the most part these two tags are interchangable, but in advanced situations you may have to use one or the other.
Hopefully this helps.
Happy coding :grinning:

1 Like

Thanks for the help. Will read up… :smile: :+1:

1 Like