Nesting

suggest change

It is a common practice to place multiple <div> elements inside another <div>. This is usually referred to as “nesting” elements and allows further dividing of a page into subsections, or helps developers with CSS styling.

The <div class="outer-div"> is used to group together two <div class="inner-div"> elements; each containing a <p> element.

<div class="outer-div">
  <div class="inner-div">
    <p>This is a paragraph</p>
  </div>
  <div class="inner-div">
    <p>This is another paragraph</p>
  </div>
</div>

This will yield the following result (CSS styles applied for clarity):

Nesting inline and block elements. While nesting elements you should keep in mind that there are inline and block elements. Block elements start on a new line and take the available width, so following content is shown on the next line. Inline elements can sit next to each other by default.

Avoid deep <div> nesting

A deeply and often nested container layout is a poor structure.

Rounded corners or similar effects often used to be built with extra elements. Most browsers now have CSS counterparts. Use as few elements as you can: less markup is easier to maintain. A div does not need to be nested many layers deep; the old “no more than 6” rule is only a rule of thumb, not a specification limit.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents