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:

  • Tags must be lowercase
  • All parameters in tags must be in quotes
  • Self-closing (standalone) tags must end with a forward-slash (note: which must be preceded with a space!)

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…


Make Better Web Pages!

How to make your web site sell - use my secrets

Find out How

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!

Leave a comment

Articles + tutorials in HTML / CSS

Complete List of HTML/xHTML Tags, With Guide to Proper Semantic Use
My Complete List of HTML/xHTML Tags, With Guide to their Proper Semantic Use
Semantic HTML Handbook – Benefits of Writing Semantic HTML
Free article on Semantic HTML. Why you should learn Semantic HTML. Benefits for SEO and code reuse explained.
A Few Tips and Tricks to Write Better Semantic HTML
Tips and tricks for writing better semantic HTML or xHTML from a professional web producer
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
Keeping your content in order of priority with flexible CSS layouts.
How to keep your most important content at the top of your page, no matter what kind of column layout you wish to achieve.
Web page production with xHTML and CSS (ebook)
Introduction to Semantic HTML
A Basic Guide to writing semantically correct semantic HTML or xHTML markup
Anatomy of HTML/xHTML tags
HTML basics tutorial: Learn HTML tags, covering the most common attributes
Introduction to Cascading Style Sheets (CSS)
Beginner's introduction to Cascading Style Sheets (CSS), learn CSS.
Making a Tabular list in HTML
Create an appealing tabular list using HTML, CSS and JavaScript
How HTML, CSS and JavaScript work together in web pages
Best practice for using HTML, Cascading Style Sheets, and JavaScript together to make web pages.
HTML Tables – when and how to use tables in HTML
When to use tables in HTML, and how to do it properly
Block vs Inline display style in CSS
An article explaining the differences between block and inline display property in CSS. Gives examples of CSS Block vs Inline CSS and how they are applied in CSS/HTML files and pages.
Datasheet-style form using HTML and CSS
Make a datasheet-style web form using HTML, CSS and JavaScript
Inheritance and Cascading Styles in CSS Explained
Introduction to CSS inheritance and how styles apply in CSS through inheritance and cascading. Read this guide detailed guide on using CSS inheritance.
HTML Lists: unordered, ordered and definition lists
My guide to HTML lists explains the 3 main types of lists web browsers support and how to implement them in HTML / xHTML
HTML, how to code HTML/xHTML markup
Free HTML tutorials: Learn top-quality web page production skills using HTML/xHTML markup
Using CSS (Cascading Style Sheets)
Free tutorial on learning CSS for web design and development
Introduction to HTML – basics of HTML
Introduction to basic HTML tags and the structure of HTML documents.
© Scratchmedia Limited, 2006-2010
Floor 3, 111 Buckingham Palace Road, London, SW1W 0WQ, UK
+44 (0)207 1600 989