What’s the difference between <div> and <section>?

I’ve seen both <div> and <section> used in HTML, and I’m a little confused. I know <section> is supposed to be more semantic, but when exactly should I use it instead of a <div>?
For example, should I wrap each block of content inside a <section>, or is <div> fine for layout too?
Also, does it affect SEO or screen readers in any way? Would love some clarity or examples.I’ve seen both

and used in HTML, and I’m a little confused. I know <section> is supposed to be more semantic, but when exactly should I use it instead of a <div>?
For example, should I wrap each block of content inside a <section>, or is <div> fine for layout too?
Also, does it affect SEO or screen readers in any way? Would love some clarity or examples.

Hi. Welcome to the community.

Can I ask what you mean by “a”? You ask should I wrap each block of content inside a … without saying what.

I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Because almost always sections have headings associated with them, the answer to this is yes on both counts.

You should aim to use a section whenever you want to group related things together but you don’t have a better semantic element to use. The only exception is if you are grouping things to gather for visual appeal (and not because of their relative contents) and in that case use a div.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.