Posts Tagged ‘Web Design’

HTML 5, Microdata, and You

Howdy, everybody. I have finally returned to convey some more information regarding the technical side of web design. Today’s topic is HTML5 and microdata.

I have recently begun using HTML 5 instead of XHMTL 1.0. The spec for HTML 5 is still a long way off from being a W3 “recommendation,” but I decided to switch to it because of “microdata”. Microdata, or Rich Snippets as Google calls them, are a way to mark up the information on your web site to be more machine readable, such as products or addresses. For example, you can use it to tell search engines that a portion of your page pertains to a specific product, pointing out exactly what makes up the name of the product, the price, its image, and so on. The following code example is pretty typical for an individual product’s info (obviously simplified for this example):

<div class="product">
	<div class="name">The Web Site Maker</div>
	<div class="price">$99.99</div>
	<div class="description">This is the incredible Web Site Maker. No longer
		do you have to get your hands dirty. This software contains a single
		button. Push to receive web site.</div>
	<img src="web-site-maker.png" alt="The Web Site Maker" />

However, a search engine doesn’t necessarily know what all that means. Google’s pretty scary and can probably decipher all that, but, with microdata, we can help by marking exactly what each bit of info means. As follows:

<div class="product" itemscope="itemscope" itemtype="">
	<div class="name" itemprop="name">The Web Site Maker</div>
	<div class="price" itemprop="offers" itemscope="itemscope"
		itemtype=""><span itemprop="price">
	<div class="description" itemprop="description">This is the incredible Web Site
		Maker. No longer do you have to get your hands dirty. This software
		contains a single button. Push to receive web site.</div>
	<img itemprop="image" src="web-site-maker.png" alt="The Web Site Maker" />

What is this itemscope and itemtype stuff, you may be wondering. These are attributes new to HTML 5, and thus the reason for switching to it. These attributes are legal on nearly any element and are used to mark up our data. The itemscope attribute is used to mark an element as the container for a particular item—in this case, a product. In the example, it means everything inside the element with the itemscope attribute is information about this particular product. It’s within the “scope” of this product. As an aside, you may notice that itemscope “equals” itemscope in the example. This is only because I am using the XHTML flavor of HTML 5. If you were using the HTML variant, you could just use itemscope on its own without the ="itemscope" portion.

After itemscope comes itemtype="". As the name implies, it specifies the type of item for the machine reader to expect. “Product” is one of a plethora of types you can use, a list of which can be found at

Moving on, itemprop="name" obviously specifies the name of the product. “Name” is a property of the “Product” type. The web site shows in detail the properties of each type, usually with examples, under their schemas section. Some properties, however, are more than a simple text value. Some are actually an itemtype of their own, such as the price of the product. It is not merely an itemprop="price" with a number inside, but an “Offer” type. So it is necessary to again add the itemscope and itemtype attributes. I also had to add an extra element—the span—inside the price div so I could apply the “price” property, a property of “Offer”.

The rest of the example is just made up of some additional itemprop attributes. After you’ve marked up your information, you can use Google’s Rich Snippets Testing Tool to make sure it’s marked up correctly.

If you’re already using some form of XHTML, it should be a pretty simple matter of changing the doctype and replacing your <meta http-equiv="content-type" content="mime-type; charset=utf-8" /> (or whatever you may be using) with a simple <meta charset="UTF-8" /> to convert to valid HTML 5. It’s not necessary to use the new elements such as header or section. Your old div elements will work fine. It’s probably not even desirable at this point to utilize the new elements thanks to the inability of Internet Explorer 8 and lower to display them without a hack.

Welcome to the future. I hope you can start using microdata (AKA Rich Snippets) to make the web a more semantic place. Don’t forget to check out for all the supported types and their properties. Have fun, web wizards!

—Kyle Blizzard

More Random Web Design Tips

Body Element Classes

One thing I’ve started doing somewhat recently is adding a unique class name to the body element of each page. This allows me to write page-specific CSS as necessary without creating an extra stylesheet. Ideally, there should be styles for common elements that make up the site, rather than style for each page, but this can’t always be avoided. One case could be that a particular page needs to have a slightly different layout than the rest of the site. Body element class to the rescue!

Internet Explorer 6

We all know Internet Explorer 6 is a regular pain in the neck, right? Fortunately, it’s easy to add IE6-specific style with this selector:
* html [additional selectors...]

For example, the style * html p { font-weight: bold; } makes all paragraphs bold only in Internet Explorer 6.  It’s valid, but no other major browser will apply it. This is useful because sometimes the style needed to make things in IE6 look one way is drastically different than what is needed to make it look the same in all the other browsers. A simpler solution, though, is to tell your client to upgrade his 8-year-old browser. 🙂


A site typically has a “bar” of navigational links. Vertically laid out navigation is easy to create and append additional links later. Horizontal navigation is sometimes desired instead, but it’s not always as trivial to append and can be a little trickier to achieve.

This tip will be focused on horizontal navigation. First, you should most definitely use unordered lists (the ul element) to organize your navigation links whether you’re using vertical, horizontal, upside-down, or anything-else-you-can-think of navigation. (See the W3’s excellent webmaster tips for more on unordered lists and their uses.) Once you’ve marked up your navigational links, jump over to the stylesheet and add a display: inline; line to your navigation’s li elements. Now take a step back and behold your now-horizontal navigational links!

If you find you need to set the width and height of your links, just set the display type of the a elements to inline-block, which I was surprised to find out was actually supported in Internet Explorer 6! Once you’ve set that, your links will behave like block-level elements as far as styling goes, but they will remain positioned inline. Sweet!

Well, that’s all for now. Make sure to check back occasionally for more random web tips from your Uncle Kyle!

—Kyle Blizzard

The img Element Vs the CSS background-image Property

Don’t know when to use the img element or when to use the CSS background-image property? Don’t fret; there is hope. Read further and all shall be revealed.

The img element is best used for pictures that are completely unrelated to the stylesheet. That is, pictures that would need to display no matter how much the look of the site changes. These would be pictures related to a news article or photos in a gallery.

The CSS background-image property is for images that make up the appearance of the stylesheet. These pictures on one stylesheet would be different or just completely absent on another stylesheet. They don’t add to the content of the page in any way and are only there to give the page its “look”. These image files would be stored in the stylesheet’s images folder. (See my last post for more on this.)

Just another tip from your uncle Kyle!

—Kyle Blizzard

Organizing Your CSS Files

When I create a web site, I like to organize my stylesheets and images into a specific folder structure. It keeps things tidy and separates presentation files (stylesheets and images) from content files (pages and images related to the content). It also leaves room for additional stylesheet “themes” for your site.

Here is an example of this folder structure:


Default in this example would be the name of the “theme”. The sites I develop typically do not have multiple themes for the user to pick, so I don’t usually take the time to give them fancy names. However, if your site utilizes multiple stylesheets that the user could choose from (such as at the CSS Zen Garden), creative names would be helpful.

All stylesheets for the Default theme would be placed in the /styles/default/ folder. Likewise, images used by those stylesheets would go in the /styles/default/images/ folder.

This method keeps your styles consolidated and makes it easy to use them across multiple sites. All you need to do is copy the folder to the other site; you don’t need to pick through the images folder and figure out which ones are used by the stylesheet and which ones aren’t.

Technically, you wouldn’t even need to copy anything to another site. You could just specify the full URL in the link element or @import rule on the page, but I urge you not to do this. Your visitors may be using security software that sees cross-site references as malicious, thus blocking the stylesheet from downloading or, worse, blocking the entire page.

—Kyle Blizzard

The Target Attribute and Strict XHTML

So, you’ve decided to start creating your web sites with valid strict XHTML 1.0 and CSS. Your client wants a “links” page containing none other than links to other web sites. So you oblige and, to keep your client’s visitors on his site, you make the links open in a new window. So you throw in target="blank" and you’re done. Just run it through the W3 validator…

There is no attribute “target”? What gives?!

Yes, indeed, target is not a valid attribute in XHTML 1.0 Strict. There’s really only one way around it of which I’m aware, and that’s by using Javascript. My preferred method is as follows:

<a href="" onclick=", 'OffSite').focus(); return false;">

This opens the URL in a new window and brings it into focus if the user had previously opened an “OffSite” window and didn’t close it.

You would still put the desired URL in the href attribute just like with any hyperlink. That way, if the visitor for some reason has Javascript disabled, the link still functions correctly. It just wouldn’t open in a new window.

One caveat though—in Firefox 2 and later with default settings, this code causes the linked site to open in a new tab, not a new window. If you find this to be a problem, there is a way around it, and that’s by adding the window options parameter such as:

<a href="" onclick=", 'OffSite', 'directories=yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes').focus(); return false;">

Those are all the options required to make the window appear normally with default tool and menu bars—kind of a pain. At this point, you may want to move the code into an external Javascript file. The function I use typically looks like the following:

function OpenOffSite(a)
{, "OffSite", "directories=yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes").focus();
return false;

Then the onclick attribute of your anchor would look like so:

<a href="" onclick="return OpenOffSite(this);">

Your links now open in a new window! Welcome to the world of XHTML conformity. 🙂

—Kyle Blizzard