Indentation


#1

What is indentation?


#2
<body>
  <div>
    <h1>Indentation</h1>
    <div>
      <h2>sub-heading indentation</h2>
      <p>nested content</p>
    </div>
  </div>
</body>

Nesting is when elements contain other elements. Nests within nests give us additional levels.

By counting the number of indentations, we can pinpoint the level of an element. The nested content paragraph is three levels below the body.

The above document is formatted for reading, not for the user agent. Whitespace is ignored when the DOM is constructed. The significant elements of the document are parsed into nodes in the document tree. Nodes are objects that share common attrbutes inherited from their parent class, as well their own attributes including styles.

If the above is a blur, don’t worry. There will be more discussion of this later. For now it is merit enough to understand the structure we see in the above view declaration, which is what a markup document is.

Note the OPENTAG and ENDTAG that each element has. With exception to a few self-closing tags (known as void elements) all HTML elements have closing tags. It is this markup that describes the structure of the document to the user agent, and thereby, informs the DOM. It is fundamental and much more important than indentation.

Bottom line, indentation is for the reader (mostly us, but also others, naturally). It helps us to make sure we keep with the above written rule and have a way to quickly spot omissions or errors in our structure.


#3

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