What is the point of nesting the <p> element in a <div> element?

Let’s put this in reverse. Say we don’t have the DIV element. Now compose your page and see how it looks. The proviso would be that no other sectioning elements are permitted in this, so essentially they don’t exist, either. Looking forward to what that page will look like. Oh, and no tables or lists, either since they, too are sectioning elements but with more purposeful roles.

HTML is less about decision and more about purpose. It’s declarative, after all; the decisions are made by the author. A document is nothing more than a blueprint, or a model from which to fashion a finished product. Truth be told, if the model is written with no obtrusive inline muckery, it will render rather boringly.

Visual presentation is handled by the style sheet. I use the singular here because regardless how many style sheets we plug in to this page, they are cummulatively one style sheet and a single cascade when determining importance of any selector rule against another.

Truth be known, a person is wasting their time if they expect HTML to render anything measuring upon pleasing to the eye. It’s not expected to, and should never be pressed to that end. It’s a document model, not a visual model. That’s why we have a style sheet. All the visual rendering is left in the hands of a resource completely removed from the content.

This is commonly known as, separation of concerns and it is brilliant, if you ask me. When CSS started making headway I was all on it.

13 Likes

Body is supposed to be a child of html, However, That won’t work. A div isn’t reliable on being a parent for body (yet)

That ‘yet’ will never come. DIV is not a child of HTML unless there is no BODY. It cannot be a parent to BODY.

1 Like

Can SECTION be used instead of DIV to group content? Or what is the difference between these two?

2 Likes

They are essentially the same thing by two different names. A ‘section’ denotes being part of something, where a ‘div’ denotes a container that could be anywhere, with no real purpose other than to contain. It’s a semantic difference only and a way to let a reader know the intent of our content.

5 Likes

It’s mainly used for container reasons, You may use it to like container other tags together as well.

the point nesting the


under

my understanding
sorry if wrong

I second the previous reply. Thank you!

1 Like

Hi can you please let me know why we use

n case of the below code :-

Capture%201

The code is basic markup illustrating the BODY, its immediate children (H1, DIV) and descendent element, a P which is a child of DIV.

A typical HTML document will be composed in similar fashion, though perhaps a little more detailed.

1 Like

Thanks. This answer is really clear and helpful.

okay so is it for future use or ?

I don’t understand your question.

Ok I’ve seen the pro has answered you. My bad.

thanks ! i think whatever u just said will help me in the future ! thank u so much and stay safe ;D :smiley: !

In HTML 5, replacements have come for the div (<div>)element (although the div tag is deprecated) like the , <article>(this one is especially useful in inserting main content), <nav> (meant for navigation bars), <header (meant for the top of your webpage), and the <footer> elements. I would recommend you to use them rather as they will help in better SEO optimization.

Hope this helped you on your coding journey!

Huh?

div isn’t deprecated. We should semantic syntax when possible, this doesn’t mean div is no longer supported at all

1 Like

deprecated doesn’t mean you can’t use it; it just means there are better tags or it is discouraged (in the case of <div> there are better tags).

That is correct. What a question!

<div> elements are often used to group related content.
then, what is the difference between <div> and <section> ?

1 Like