Web Development

What are the Elements, Tags, and Attributes in HTML?

If you have used HTML in your web design tasks or you have just started learning it, then terms such as HTML elements, HTML tags, and HTML attributes are not new to your ears.

Html Elements Tags Attributes - Dynamic Web Training

However, there are high chances that the trio often confuses you. That’s because it is hard to tell the difference between two or more items if you don’t understand their meanings. If that is the case, this is the place to be. We have prepared an article that will define and differentiate elements, tags, and attributes in HTML. Continue reading for the details as we dive into the meaning of the various terms.

What is an HTML Element?

When it comes to HTML elements, these are the building blocks of this language. Each element is an individual component on a particular web page or document. They are in every part of the page, including the header, footer, body, and text.

The format of a tag is a start tag followed by the content and an end tag, eventually. For instance, if you need to use a paragraph element, here is the way to go.

<b>some written texts here</b>

However, not all the HTML elements have closing words. They go by the names void, singleton, or empty elements.

Examples include:

This text contains<br>a line break.

<img src="images/logo.png">

Types of HTML Elements

here are two broad categories of HTML elements. They are the inline-level as well as the block-level HTML elements. The block-level elements make up the structure of the document. It takes up the entire width of the page.

There is always a line before and after a block HTML element. Examples include <div>, <p>, <h1>, <h6>, <form>, <ol>, <ul> and <li>, e.t.c.

On the other hand, the inline-level elements are mainly in the contents of a block. In addition to that, their width is based on how much space that individual element needs. They include <img>, <a>, <span>, <strong>, <b>, <em>, <i>, <code>, <input> and <button> among others.

What is an HTML Tag?

HTML tags are what defines where an HTML element starts and where it ends. There is usually an opening bracket followed by the element’s name and, finally, a closing bracket.

In most cases, there is always a start tag and an end tag enclosing an element. Nevertheless, that is not the case for all elements.

As far as HTML is concerned, there are several types of a tag. The first one is the start tag. It contains two opposite angle brackets. Examples include:

  • <title>
  • <p>
  • <b>

The other one is the end tag. The similarity to the start tag, it has angle brackets. However, there is a forward slash after the first angle bracket. Examples of the end tags corresponding to the start tags above are as follows.

  • </title>
  • </p>
  • </b>

In other cases, the tags may contain other aspects. That usually happens when it comes to the opening tags. They may contain an extra attribute, including the likes of height, width, or CSS class name, among others. Check out this example:

<p class='info'> 

img src="smiley.gif" alt="Smiley face" height="42" width="42"> 

<INPUT TYPE = "checkbox"> 

What is an HTML Attribute?

In simple words, an HTML attribute is what modifies an HTML element. It is usually in the form of unique words that one inserts inside the opening tag. They control the behavior of the element that follows.

Every tag has two sections. The first one is usually the name of the attribute, while the other one is its value. The two are usually separated by an equals sign (=). Attributes are inside the start tag of that particular element that needs modification.

One can enclose the value of the attribute using either double or single quotes. In some cases where there is the usage of certain characters, quoting may not be necessary. It is good to note that the rules may be different when it comes to other languages, including the sister one, XHTML.

However, experts have rules unquoted attribute values to be unsafe. Equally important, not all attributes need values. A good example is an ismap attribute, which modifies the img element. The general structure of an attribute is as follows:

<element attribute="value">element content</element>

Let us look at the various types of HTML attributes. 

The first ones are the required attributes. As the name suggests, they are needed by particular element types for them to function as expected.

The next type is the optional attributes. Their role is to change the default functionality of an element.

On the other hand, standard attributes can support several element types.

Last but not least, there are event attributes that allow element types to declare scripts that will run under certain circumstances. 

Under the required and optional attributes, there are some that are used by one, two or multiple elements. For those used by two or more elements, there are high chances that they will modify the various elements differently despite having the same name.

A good example is attribute name

Examples of various HTML attributes

<input type = "text" name="email" size=15 value="type name here">

<td align=right>

<a href=""> cnn </a>

<button onclick="document.getElementById('demo').innerHTML = Date()">The time is?</button>

Standard attributes include class, contextmenu, data, hidden, id, lang, style and title among others.

Final Words:

From the above discussion, a parallel line has been drawn among HTML elements, HTML tags, and HTML attributes. It is important to note that both the tags and attributes are within an element. While the elements tell the browser what to display, the attributes define how they will behave.

The tags mark the beginning and the end of an element. They may not be necessary for some elements, especially the closing tags. Equally important, the attributes are only within the opening tags. With such information at your disposal, we hope that you will have an easy time using HTML.

By Dynamic Web Training

Dynamic Web Training is Australia's leading provider of instructor led software training.

We offer training courses in Adobe, Web Design, Graphic Design, Photoshop, InDesign, Dreamweaver and many more.