The Difference Between a Tag and an Element

The Difference Between a Tag and an Element

A Tag

A tag is simply a less than sign (<), followed by a forward slash (/) if it’s a closing/ending tag, followed by a string of one or more pre-defined characters (a, li, body, etc), followed by a greater than sign (>). For example, the starting/opening body tag:


Or the closing paragraph tag:


If you make a mistake in the spelling of a tag, that is, if you spell a tag that is not defined by HTML, then browsers will typically ignore it. If your misspelled tags contain content, the tags are ignored, but the content is rendered in a browser. The content “Here’s my misshapen document” in the following example will be rendered in the browser, but the tags will be ignored.

Here’s my misshapen document

An Element

An element consists of the opening/starting tag, all its allowable content, and the closing/ending tag. If it’s an empty element, like, for example, the image tag, then the element consists of only the opening/starting tag. Here’s the image element:

<img src="shihtzu.jpg"
     alt="[A 5-year old Shih Tzu]">

And here’s the paragraph element:

<p>This is a paragraph.</p>

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.