htmltextnode

what is the difference between <p> and text nodes?


i'm learning HTML, and it is not clear yet to me what is the difference in using a text node or a <p> element.

more precisely, what are the advantages and disavantages of using a <p> element? what about text nodes?


Solution

  • There are a few reasons not to use "naked" content in your markup:

    1. The primary purpose of HTML is to semantically wrap the content it contains-- paragraph content should be wrapped in a <p>, address information should be wrapped in <address>, etc. When you do this, it is a clue to various technologies that read HTML as to how the information it is reading should be interpreted. Such technologies include search engines (to understand what is on your page) and screen readers (to read content in a manner that makes sense to users who might not be able to see the screen).
    2. When you don't wrap your content in markup, you have no meaningful way to target and style it with CSS
    3. When you don't wrap your content in markup, you have no easy way to access it with JavaScript for manipulation

    Basically, the whole intent of HTML is to semantically wrap content, and doing so also enables other functionality in the browser. There's really no reason not to do so-- so, wrap your content appropriately!