HTML tags

Meet the many tags that help us construct HTML documents

Updated

Block- and inline-level tags

HTML tags sit in two camps: block-level and inline-level.

Block elements fill our layout. By this we mean they expand to fit the full width of the available space, pushing other elements (even other block-level elements) onto the next line – without us having to do any styling. There are quite a few basic HTML tags that are defined as block-level, which we'll cover later in this article.

Inline elements don't fill our layout. By default they have no sense of width (unless we use styles to overrule this). They exist quite happily inside block-level elements, just going with the flow.

HTML tags

Block-level

Here's a list of block-level elements with definitions:

<h1>
First header tag. Only one per page.* Take a look at this newspaper's front page to see why the examples below are marked up as demonstrated.
  • <h1>Men walk on moon</h1>
The tags that make a header, number one..
<h2> <h3> <h4> <h5> <h6>
The other available header tags. As many of these per HTML page as you feel you require. However, they must be written sequentially, so don't use, for instance, the <h3> before the <h2>.
  • <h2>Astronauts land on plain; collect rocks, plant flag</h2>
  • <h3>Voice from moon: 'Eagle has landed'</h3>
  • <h3>A powdery surface is closely exposed</h3>
The tags that make a header, number two and three. NASA is still waiting for the flag to grow...
<div>
General-purpose box. Primarily used to hold our layout together.
  • <div>
  • ...
  • </div>
The tags that make a block level container.
<p>
Paragraph tag. Most every piece of copy should be inside them.
  • <p>My fellow citizens of the world: ask not what America will do for you, but what together we can do for the freedom of man.</p>
The tags that make a paragraph.
<ul>
Unordered list tag. By default will display bullet points against each of its list items. Use when you have points to get across (that wouldn't be satisfied by using a <p> tag) and that their order is not necessarily important.
<li>
List tag. Is used inside <ul>s and <ol>s for each list item required. These should not be written without a parent.
  • <ul>
  • <li>Apples</li>
  • <li>Oranges</li>
  • </ul>
  • Apples
  • Oranges
An unordered list in HTML, with its output below.
<ol>
Ordered list tag. Also uses list items within it. but by default will display numbers against each of them.
  • <ol>
  • <li>Whisk 3 eggs</li>
  • <li>Add 500g of flour</li>
  • <li>Mix together</li>
  • </ol>
  1. Whisk 3 eggs
  2. Add 500g of flour
  3. Mix together
An ordered list in HTML, with its output below. If I knew you were comin', I'd've baked a cake...
<dl>
Definition list tag. Its 'list items' are made up of two child tags and is itself invalid without them.
<dt>
Definition list term tag. Required to establish the title of the definition list item.
<dd>
Definition list description tag. Required for writing the description that relates to the definition list title.
  • <dl>
  • <dt>Apples</dt>
  • <dd>Available in many varieties, such as Braeburn and Cox.</dd>
  • <dt>Oranges</dt>
  • <dd>Succulent and healthy, oranges come in many different sizes.</dd>
  • </dl>
Apples
Available in many varieties, such as Braeburn and Cox.
Oranges
Succulent and healthy, oranges come in many different sizes.
A definition list with two items. Output is beneath.

Definition lists, or rather their definition titles, can have multiple definition descriptions. As a concept, it is a little odd, but in comparison to other types of HTML lists it at least allows us to have finer control over what kind of information we show and how we can style it. Essentially, until the next definition title (<dt>) starts in the list, you can have as many definition descriptions (<dd>) as you require. However, they must relate to what the definition title is on about – otherwise we lose semantic meaning to the markup and its content. Here's a quick demonstration using a second definition list with an image inside it:

  • <dl>
  • <dt>Apples</dt>
  • <dd class="desc">Available in many varieties, such as Braeburn and Cox.</dd>
  • <dd class="image"><img src="images/apples.jpg" alt="Apples" /></dd>
  • <dt>Oranges</dt>
  • ...
  • </dl>
A definition title with two definition descriptions.
<table>
Table tag. You can find out more about it, and its associated tags, in understanding HTML tables.
  • <table>
  • <tr>
  • <td> ... </td>
  • </tr>
  • </table>
The tags for a table. No formica required.
<form>
Form tag. Allows us to create forms that can be filled out by visitors. It has quite a few tags that are only allowed inside it, some demonstrated below for context. Read the article about HTML forms for more detail.
  • <form>
  • <fieldset>
  • <legend>Your details</legend>
  • ...
  • </fieldset>
  • </form>
The tags for a form with some of its children present.
<blockquote>
Perfect for writing quotes. Combine it with a <p> tag for maximum effect and control.
  • <blockquote>
  • <p>An economist's guess is liable to be as good as anybody else's.</p>
  • </blockquote>
Use the <p> tag inside to have more things to hang CSS rules on.

Inline-level

Here's a list of inline-level elements with definitions:

<span>
The ultimate, all-purpose inline element.
  • <span>Look at me going with the flow</span>
The tags that make a span.
<a>
The anchor is an extremely useful inline element. Use its href attribute to link to other HTML pages.
  • <a href="http://www.duckduckgo.com/">find something on DuckDuckGo</a>
The tags that make an anchor.

For an email address use the same parts, but just prefix the email address (inside the href) with mailto:. Clicking the link will launch the user's default email program, which may not always be the desired result. Best to write the email out in full, in the page, so users can make their own choice.

Concatenate ?subject= directly after the email address to pre-fill the subject line for them.

  • <a href="mailto:info@mydomain.co.uk?subject=Help me">email us for support</a>
The anchor again, this time with email specific rules.
<strong>
Make text bold – without using CSS.
  • <strong>I will be bold</strong>
The tags for making something bold. Text shown between the tags may not be true.
<img />
This self-closing tag allows you to show images on your HTML page. Use the src attribute to hook it up to the relevant image. Add the alt attribute to describe it briefly, so that those that won't be able to see it can still understand it.
  • <img src="myimage.gif" alt="A family get together at the Red Lion" />
The tag for an image.
<abbr>
If you're writing a word as an abbreviation, wrap it in this tag. Use the title attribute to explain it in full.
  • <abbr title="that is">i.e.</abbr>
The tags for an abbreviation.
<acronym>
If you're writing an acronym, like BBC, wrap it in this tag. Use the title attribute to explain it in full.
  • <acronym title="British Broadcasting Corporation">BBC</acronym>
The tags for an acronym.
<address>
If you're writing an address then wrap it up in this tag, using other markup to help control its parts. It's all about semantics, remember, so if there's a tag for something in particular, use it.
  • <address>
  • <p>22 Acacia Avenue</p>
  • </address>
The tags that define an address as an address.

HTML 5 tags

In the not-quite-fledgling-anymore world of HTML5, there are series of new tags available for use and some old ones that are now deprecated. As it stands (as of 2012-06-13), the National Trust's national website doesn't use any of these. However, newer, stand-alone websites, should start using these.

<section>
Section tag. Not a replacement for the <div> tag, but they can help to give your HTML more implied structure and should contain <header> and <footer> tags.
<header>
Use this tag to define where your header elements sit, generally including visual identity and a main menu of navigation.
<footer>
Use this tag to define where your footer elements sit, sometimes including additional menus and copyright notices.
<article>
The article tag is very useful. Treat its contents as if they were alone, separate from the wider context of the document. Partly why multiple <h1>s can be used, as every <article> tag can accommodate its own <h1>.
<aside>
This tag represents content related to surrounding tags, typically the <article> tag.
<nav>
Keep your menu items in this tag, typically an unordered list of links to other pages. There is no need to use this for individual anchors.

You can find out more about HTML5 tags on External site: HTML5 Doctor, a particularly useful resource for using them in the field.

Back to top