Introduction to HTML tags

HTML uses tags, which are written in pairs of angle brackets, like this <tag>.

Paired tags

Most tags are paired, i.e. they begin with an opening tag and end with a matching closing tag. The pair of tags then defines the structure of the content between them.

Simple HTML Example

<p>This is a paragraph. Everything between these two tags is part of this paragraph.</p>

Standalone HTML tags

A few tags don't have end tags. These are tags that are stand-alone structure, and don't need to contain content to be meaningful.

The main basic standalone HTML are:

<br>
Line-break. Starts a new line. (<br /> in xHTML)
<hr>
A horizontal rule. Puts a line across the page. (<hr /> in xHTML)
<img>
An image. See below for more information about this.
<meta>
Don't worry about this one for now. It's also hidden in the document's <head>, and is a place for putting content about the document that doesn't need to be displayed on-screen.

What's xHTML then?

HTML comes in various versions, which dictate the sets of allowable tags. xHTML is the latest version of HTML, and is simply HTML written in a strict XML syntax, so that xHTML documents are valid XML documents. There isn't much difference. The only important thing you will need to know is that, if your web page says it's HTML, you ought to use proper HTML tags. If your web page says it's xHTML, then it ought to contain only valid xHTML tags.

The main things you'll notice about xHTML are:

The following would be permissible in HTML 4, but invalid in xHTML:

<IMG SRC=background.gif WIDTH=40 HEIGHT=20 ALT="Hello">

For valid xHTML, you'd have to put:

<img src="background.gif" width="40" height="20" alt="Hello" />

Basic formatting in HTML

Your basic, everyday HTML tags.

<h1> ... </h1>, <h2> ... </h2>, <h3> ... </h3>
Headings (heading 1, 2 3, etc.) Used for marking section headings in your web pages.
<p> ... </p>
We saw this one above. It's a paired tag that says "Here's where the paragraph starts" and "Here's the end of the paragraph"
<br>
Another familar tag. Inserts a new line.
<hr>
Horizontal rule
<div> ... </div>
This is one of the most common tags. Basically, a div is a general-purpose box that takes up the full width of the space it's in.
<span> .. </span>
This is another general-purpose container. Whereas a div is a blocky full-width box, this quietly wraps round anything it contains. See below for details.
<strong> .. </strong>
A section of text that you want to be stressed. Normally rendered as bold in web browsers (although you can control this)
<em> .. </em>
Emphasised text - normally rendered in italics in web browsers.
<title>
This tag goes in the document's head section, and isn't displayed on the web page itself. It says what the title of the web page is, and is displayed in the browser's title bar (very top).

Paragraph tag: <p> ... </p>

Code

<p>
    Here's a paragraph.
</p>
<p>
    And here's a different one.
    It's as simple as that.
</p>

Looks like

Here's a paragraph.

And here's a different one. It's as simple as that.

Line-break tag: <br>

Code

I'd like to write some text<br>and then have the next bit on the line below.

Looks like

I'd like to write some text
and then have the next bit on the line below.

Horizontal rule tag: <hr>

Code

<p>Here's part of my page.</p>
<hr>
<p>And here's another bit, distinguished by the line above.</p>

Looks like

Here's part of my page


And here's another bit, distinguished by the line above.

Div tag: <div> ... </div>

Code

Here's some content...
<div>This is a div.</div>
<div>And this is another one. Works pretty much like a new paragraph for now.</div>
Here's some more content...

Looks like

Here's some content...
This is a div.
And this is another one. Works pretty much like a new paragraph for now.
Here's some more content...

Basically, that's it about <div>s. They're boxes, and (unless you tell them otherwise), they occupy the full width of the space available to them.

It's only when we get on to CSS that we can make divs do all kinds of interesting things.

Span tag: <span> ... </span>

Code

<p>Here's a paragraph of text. What I want to happen is to make <span style="font-weight:bold;">some of the text bold</span>, and then make <span style="color:red;">some of it red</span>, and <span style="background:yellow;">yet another bit on a yellow background</span>. <span>Now, some of this text may wrap round onto new lines, but that's OK.</span></p>

How it looks

Here's a paragraph of text. What I want to happen is to make some of the text bold, and then make some of it red, and yet another bit on a yellow background. Now, some of this text may wrap round onto new lines, but that's OK.

If you look carefully at the code above, you may notice that spans don't actually do anything on their own. The last sentence is contained in a blank <span>, which has no effect on anything. The only ones you notice in any way are the ones I've styled (using inline CSS - not the only or best way to apply styling, but we'll come to that later).

Spans are useful when you want to apply some styles to a portion of content without affecting the layout in any way.

Here's what would happen if I replaced all the spans with divs.

Here's a paragraph of text. What I want to happen is to make

some of the text bold
, and then make
some of it red
, and
yet another bit on a yellow background
.
Now, some of this text may wrap round onto new lines, but that's OK.

The divs are messing up my nice neat paragraph, because every div has to start on a new line, and have a new line after it, so that it can take up the full width available.

Next read...

Do you love our approach to crafting simple & effective web sites that just work for people?

We'd love to hear about your web strategy. Contact one of our team today!

Search this site
Pro Tips
Learn how to make fantastic web site designs..
Buy "Save the Pixel" now!
On “Save the Pixel”
Clicss templates, great robust useful CSS templates from £40
Share this Article
Send to a friend now&hellip
Follow Ben Hunt on Twitter
Floor 3
111 Buckingham Palace Road
London
SW1W 0WQ
UK
Phone
+44 (0)207 1600 989

Articles + tutorials in HTML & CSS Production

Overview
Menu of all our articles on HTML, CSS and web page production
CSS
List of our CSS articles
Introduction to CSS
Beginner's introduction to Cascading Style Sheets (CSS)
HTML
List of HTML articles
Introduction to HTML
Introduction to basic HTML tags and the structure of HTML documents.
How HTML, CSS and JavaScript work together in making web pages
Best practice for using HTML, Cascading Style Sheets, and JavaScript together to make web pages.
Building a web page with HTML + CSS for complete beginners
Learn what HTML is and how to build a website from scratch. A guide to creating a web page using HTML and CSS for people with no prior knowledge
Block vs Inline display style in CSS
HTML elements can be displayed either in block or inline style. The difference between these is one of the most basic things you need to know in order to use CSS effectively.
Inheritance and Cascading Styles in CSS
Introduction to how styles apply in CSS through inheritance and cascading.
HTML Lists
The basics of lists: unordered, ordered and definition lists covered.
HTML Tables
The basics of tables. When to use tables, and how to do it. Includes tips on colspan and rowspan properties, and the col and colgroup tags.
Anatomy of HTML tags
Describes the common attributes that can feature in your HTML tags.
Introduction to Semantic HTML
Explains what semantic HTML, or semantically-correct HTML, is and how it benefits web development.
Semantic HTML Handbook - Benefits of Writing Semantic HTML (Nov 15 2009)
Free article on Semantic HTML. Why you should learn Semantic HTML. Benefits for SEO and code reuse explained.
Complete List of HTML/xHTML Tags, With Guide to Proper Semantic Use (Nov 15 2009)
My Complete List of HTML/xHTML Tags, With Guide to their Proper Semantic Use
A Few Tips and Tricks to Write Better Semantic HTML (Nov 15 2009)
Tips and tricks for writing better semantic HTML or xHTML from a professional web producer
Web Page Production using xHTML and CSS (ebook)
This new 61-page ebook provides a worked example of web production, taking you through the entire process from a Photoshop page design, to a working HTML page template.
Datasheet-style form using HTML, CSS and JavaScript
Make a datasheet-style web form using HTML, CSS and JavaScript
Tabular list-style form using HTML, CSS and JavaScript
Create an appealing tabular list using HTML, CSS and JavaScript
Complete HTML tag reference
Our complete guide to HTML and xHTML tags, and their proper usage.
Keeping your content in order of priority with flexible CSS layouts
This article shows you how to use CSS floats to achieve any column layout, while keeping your most important content highest on the page.