FAQ: Learn HTML - Intro to HTML - Divs

I would do the following:

<div>
  <p>nested paragraph element</p>
</div>

given the paragraph is nested within the div element, so the spaces are before the opening element

this of course applies to multiple levels of nesting:

<div>
  <div>
    <p>lala</p>
  </div>
</div>

this really improves readability and ensuring all tags are properly closed

Okey thanks for answering! Just so I got it correct, why is the reason you did two

like this:

<div>
  <div>

Was it just to make it extra readable?

So it’s okey to write:

<div>
  <p>nested paragraph element</p>
</div>

But to really make sure it’s readable and ensure all tags are closed you recomend to type:

<div>
  <div>
    <p>nested paragraph element</p>
  </div>
</div>

Did I understand that right? :smile:

The extra div’s where just to demonstrate indention when you are dealing with multiple nested elements.

sometimes you need nested divs to get the layout of your website right :wink:

1 Like

Okey, got it! Thanks! :slight_smile:

1 Like

I understood the previews lesson so whenever encounter problem which i don’t know how to solve it, I’ll ask you
Insha’Allah.

What is the the different of div tags and section tags?
What is the use of section tags in html document if div tags is representing the same task as section?

  • The primary difference is in semantic meaning. <div> is a generic container with no specific meaning, while <section> is a semantic element indicating a thematic grouping of content.
  • <div> is often used for layout and styling purposes, providing a way to group elements for styling with CSS or targeting with JavaScript.
  • <section> is used when there is a need to convey the thematic grouping or segmentation of content, providing a more meaningful structure to the document.

Worth noting that:

  • Use <div> when you need a generic container for grouping and styling content.
  • Use <section> when you want to convey a specific thematic grouping or section of content within the document, helping to create a more semantically meaningful HTML structure.

I used the “inspect” feature to see HTML and JavaScript code to create this HTML lesson. I noticed that the code contained div tags with different classes to them, for example, div class, div style, etc. I guess a coder is able to do different features with the div tag as far as I know.