Difference Between ≪Section≫ and ≪Div≫

Could Section and div be used interchangeably in html?

The <section> tag defines sections in a document, such as chapters, headers, footers, or any other sections of the document.

Whereas: The <div> tag defines a division or a section in an HTML document. The tag is used to group block-elements to format them with CSS.

HTML Section vs Div tag

I think you can apply the logic of 'common usage make right' which was raised in a slightly different but relatable question on the use of the i tag for icons. Though it is in a slightly different context, the principle is the same. Meaning the section tag, whilst may not be technically approved by W3C, it is very widely used. Many WordPress themes and templates use it, and WordPress takes up quite a large percentage of the internet these days.

Before I get stick for saying that, I am not saying use bad practice or use tags when ever for what ever just because every one else does. I mean, if its used semantically, in the right context for the right uses as per the W3C specification then thats ok.

A div tag sometimes doesn't make sense, when you are clearly sectioning an area that has a title and a body of text then use section. If you're creating a box in order to put other elements in to section off a part of your page for a menu or comments or something then thats not really the right kind of section and so use a div or other tags more appropriate.

After all, the SO blog uses them: SO use of section tag

So does the w3c website
W3C example of section use

Are section, div, and span all basically the same thing?

<section> (also <article>, <aside>, and other HTML 5 additions) and <div> (been around forever), are very similar (except for SEO / semantic differences) -- but <span> is quite different.

All - even <html> and <body> - are just containers inside which you can put other containers/tags.

As an inline element, <span> has several limitations that the other two do not, a couple of which are:

  • Cannot style/change height or width

  • Cannot use margin to raise/lower it above baseline

So what is span for? Usually used to enclose a string of text for any of the following purposes:

  • Assign an ID or class to a bit of text in order to style it

  • Assign an ID or class to a bit of text in order to target it for javascript manipulation

  • With an ID or class, javascript can inject or remove text

References (for further reading) :

What is the difference between <section> and <div>?

https://www.smashingmagazine.com/2013/01/the-importance-of-sections/

CSS width of a <span> tag

Does height and width not apply to span?

Note that:

<p> and <h1> etc are exactly the same - containers inside which you can put other containers/tags/text - but these are like <span> in that they come with some automatic formatting that you may (or may not) desire. The primary reason for the different tags (except for a little bit of auto-formatting/css) is for SEO (semantics).



Related Topics



Leave a reply



Submit