What are HTML tags?

Tags form the basis of HTML coding. A tag is simply a way of defining sections of code so that we can assign properties and styling to those sections. For example, you might use a heading tag for your page title, and you can then assign styling such as a large font or a different color to the heading.

HTML tags are very simple to use - they consist of the tag title surrounded by angled brackets < and >. For example, the tag which defines a web page's main body text is simply <body>.

Tags are arranged in pairs - one to mark the start of a defined section and one to mark the end. These are known as the opening and closing HTML tags. They look very similar, the only difference being that the closing tag has a forward slash /. For example, in order to define some text as a paragraph we have to put the opening and closing paragraph tags at the beginning and end like this:

<p>Paragraph text goes in here</p>

Some HTML tags do not actually surround any content, so they do not have separate opening and closing tags. Instead they just have one tag which acts as the opening and closing tags in one. A good example is the line break tag, which looks like this: <br />. Notice that it has the tag name, br, as well as the closing forward slash, all in one tag. The space between the br and the slash is optional, however some web browsers require it, so it is best to always include it for maximum compatibility.

It used to be the case that tags could be written using lower or upper case letters, or even a combination of the two. However, the latest HTML specification, XHTML 1.0, states that all tags must be written in lower case, so make sure you do.

Finally, you can assign attributes to many HTML tags. These are used to give the browser a bit more information about how to interpret the tag. For example, whenever we use the <img> tag to insert an image into our web page, we must also use the "src=" attribute to tell the browser which image it should load.