New eBookNew eBook - Guide to Semantic HTML

Ben Hunt adds another great eBook to the collection with his "Guide to Semantic HTML". The book gives you advice and tips on how, and why to use semantic HTML.

Included is a comprehensive list of HTML tags, each with their semantically appropriate uses, along with a worked example taking you through the process of how to build a website using semantic HTML.

Get “Guide to Semantic HTML” now for £5.00

New eBookNew eBook - Web page production with xHTML and CSS #1

Experience the thought process of a professional web producer as he guides you through the web page production process, from photoshop design to working HTML template.

The book tells you how to approach web production, beginning with semantic HTML, guiding you through how to slice up a photoshop document, and finally how to use CSS for presentation.

Buy Now for £9.00 GBP

Tags and Attributes

As we covered in Introduction to HTML, HTML tags are defined by angle brackets <tag>. Sometimes they are stand-alone, like the Image tag <img> or Line-break <br>.

All HTML tags can include one or more attributes. These give the browser more information about the tag.

Let's jump in and look at some of the most common attributes for everyday HTML tags.

HTML Style Property

You can apply the style attribute to any visible tag. It assigns CSS styles inline. (This is not always a good idea, see: Introduction to CSS.)

<p style="color:red; background:#ffc; padding:1em;">Hello mum</p>
Looks like:

Hello mum

HTML Name Property

The name attribute is used by more than one type of tag.

Form elements

Form elements should have a name attribute in order for server-side scripts to work out what was entered into each field.

e.g.

<form action="yourscript.php" method="get">
   <input type="text" name="username" />
   <input type="password" name="password" />
   <input type="submit" />
</form>

On-page anchors

The anchor (<a>) tag isn't only for creating links. You can also use them to create places on a page that you can jump to directly from a link.

e.g. You can create an on-page anchor with...

<a name="mainbody"></a>

Which you can then link to with...

<a href="#mainbody">Skip navigation</a>

Which brings us on to...

HTML Href Property

href stands for "hypertext reference", and simply means the target of a link.

e.g. A link to another site...

<a href="http://www.scratchmedia.co.uk/about-us.html">About us</a>

A link to an anchor on this page...

<a href="#product1">Product One</a>

Or a link to an anchor on a different page...

<a href="people.html#geoff">About Geoff</a>

HTML Title Property

The title attribute is different to the <title></title> tag (which goes in the page head and sets the title of your page).

The title attribute provides a bit of extra information for a visible element, like a link, image or button. In most browsers, it causes a tooltip to appear when the mouse pointer hovers over the element.

e.g.

<input type="button" title="Don't click this, it doesn't do anything." value=" Useless " />

Looks like...

HTML Class Property

<div class="comment code">

Almost any tag that you put in the HTML body can have one or more classnames. The example div above has two classnames: "comment" and "code".

At the highest level, a tag's classes provide additional description about what kind of element the tag is. For example, the example above is described as a "comment" container and also as "code" container.

These definitions don't really mean much on their own, but it's good practice to make sure they make sense (i.e. semantically useful). (For example, my code snippets get the "code" classname, instead of being called class="greybox" or class="typewriterstyle")

What you can do with Class

You mainly use an element's classname(s) to assign styles through Cascading Style Sheets, but it's also possible to read them and do stuff in DHTML.

Example of applying styles in CSS using elements' class. The classname is prefixed with a dot/period to specify that it applies to elements with class="comment".

<style type="text/css">
   .comment {
      border:1px solid white;
      background-color:#f6f6ff;
      padding:1em;
      margin:.5em;
      border-left:6px solid #eee;
   }
</style>

HTML ID Property

<div id="introblock">

Anything can have an ID attribute. An element's ID is its unique identifier.

Note: There should only be one element on each page with a particular ID attribute.

What you can do with ID

Like class, id is frequently used to assign properties through CSS. Here, note how the id is prefixed with a hash/pound sign, to show that it applies to elements with id="nav".

#nav {
   height:76px;
   float:right;
   display:block;
   text-indent:-3000px;
}

(CSS styles assigned to an element's ID override any of the same style properties assigned through class.)

The ID attribute is particularly useful in DHTML. It's very often used to identify a particular element in JavaScript.

e.g. This code finds an element with the ID "nav", and hides it.

<script type="text/javascript">
<!--
   if (document.getElementById('nav')) {
      document.getElementById('nav').style.display = 'none' ;
   }
// -->
</script>

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.