Let's learn the difference between HTML elements, tags, and attributes. We'll also take a look at a very basic HTML document.
Elements are the building blocks of HTML. They are the smallest units of content and you use them to build larger elements. Elements can be nested to create more complex content.
Here's an example of an HTML element:
<p>This is a paragraph.</p>
Notice that the element is surrounded by angle brackets (< and >). This element is using a
p tag, and its content is "This is a paragraph."
Tags are the names of the elements. They are used to identify the type of element that you are creating. An opening and closing tags makes a complete element, however, you can also use self-closing tags. Self-closing tags are used to create elements that don't contain content.
Here is an example of a self-closing tag:
Here's a look at the syntax of any generic tag:
<tag>The opening tag is on the left, closing tag on the right.</tag>
Here are some other examples of tags:
In addition to tags, HTML has another way of helping you give meaning to your content, called attributes.
Attributes describe the tags that they are placed inside of. The syntax for attributes is extremely simple. A valid attribute is a name-value pair, separated by an equals sign.
<div class="special">I am a special heading!</div>
In this example,
class is the attribute, and
special is the value. Attributes describe tags because now this
div tag might act or look differently than another
div tag with another class attribute, or no class attribute at all.
The following is a generic example of how an attribute with a value can be applied to a tag.
<tag attribute="value">I am a generic example.</tag>
Hopefully now you know the difference between HTML tags, attributes and elements!