Reputation: 93
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?
Upvotes: 1
Views: 877
Reputation: 13623
There are a few reasons not to use "naked" content in your markup:
<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).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!
Upvotes: 1
Reputation: 943142
A text node is just a piece of text.
A p element is an element (with all the usual features of an element such as being able to apply CSS to it and select it with JavaScript) with sensible default CSS for paragraphs (such as creating new lines before and after it) and the particular semantics that define it as being a paragraph (which are used by a variety of tools like search engines and screen readers).
If you were to type:
<p>Hello, world</p>
You would create a paragraph containing a text node.
Upvotes: 3