What is the basic difference between HTML elements and tags?
What is the basic difference between HTML elements and tags?
An element in HTML represents some kind of structure or semantics and generally consists of a start tag, content, and an end tag.
Tags are used to mark up the start and end of an HTML element.
A tag is a part of an HTML element, or rather, an element is the sum of a start-tag, optional content and optional end-tag.
e.g. The 'header' element is made up of the following:
<header> <-- Start tag of the 'header' element.
Text content, and other elements
</header> <-- Closing tag of the 'header' element.
Some elements like <br> don't need a closing tag (if the document is not intended to be XML-compliant) or text content.
Elements and their corresponding start tags can have attributes.
e.g. <img src="/opengraph.png" alt="">
In the above example, the 'img' element has two attributes in its start-tag: src and alt. The 'img' element doesn't have any contents and a closing-tag is not required in HTML5.
A tag is a subset of element in HTML. An element is the basic building block of HTML and is typically made up of two tags: an opening tag and a closing tag.
For example, the paragraph element <p></p> is made up of the opening tag <p> and the closing tag </p>. The element is the collection of both the starting tag and the ending tag.
|
Bookmarks