Web design

My thoughts on web design and development

6 common CSS errorsMarch 6th, 2009

Since writing the article about HTML errors I thought, why not list those common CSS errors too?

Using colour keywords

Ok, ok, this isn’t strictly an ‘error’ (it’s in the CSS spec), but in my book it’s wrong. Each browser supports colour keywords differently, so to be safe you might as well use another method. I personally prefer the hex notation, which can be very easily gathered from Photoshop or Paint Shop Pro, but the RGB decimal notation is also a useable notation.

Using inline styling

The ability to add style to a tag by using the style=”" attribute can be handy, but it also sort of defeats the whole purpose of using CSS. One of the major benefits of CSS is the ability to easily change a visual aspect of a website without having to change page after page. Sure, use inline styling for testing purposes, but keep your styles to an external file. And remember, if you’re using styles that are only for one or two pages, there really is nothing from stopping you using multiple external files!

Not using semantic class names

Again going back to being able to easily change the style of a site using CSS, keep in mind that your site will likely change when naming your tag classes. Using the class name “bigyellowbox” might seem like a good idea now, but in a couple of years will it still make sense when you change the colour to blue?

Using px for font size

Many people will disagree with me here, but I’m of the opinion that fonts on the web should be the same as fonts in any other medium. Fonts have always been measured in point since the early days of the paper press right up to the day of Microsoft Word. People say that using pixels makes it easier to line up text to images, but in my opinion the web is a fluid medium and shouldn’t be strictly controlled like that.

Using height

Again, I think that the web is a fluid medium, and setting a height of an element using CSS contradicts this. Anyway, it never quite works as you expect once implemented. There are many cases where the height of an element will be different to as you’d like such as the text being resized by the user, the font not existing on the user’s computer, site copy being changed, and one browser (incorrectly) rendering your CSS differently to another browser.

Using class and id incorrectly

There’s a subtle, but important, difference between the HTML class and id attributes; it might even surprise you to learn that an element can indeed have both.

  • id is a unique identifier for that particular element. Effectively, it’s a name so that you can reference just that element (for example, the footer div) in your CSS and javascript
  • class is less unique, and is a way of identifying the element as part of a group of elements. For example, a website might have restricted pages whose links you want to look different to those page links that aren’t restricted. This can be achieved by giving the link tag an attribute of class=”restricted-link”

External links

Tech Usability #3: Making mistakesFebruary 6th, 2009

One of an ongoing series of articles discussing usability issues in technology and how to improve the overall experience for the user

It’s perfectly human to make mistakes: everybody’s done it. That’s why computers make it easy for you to undo your last action, and that’s why applications should do too.

Some applications ask if you’re sure if you want to do this action, with a confirmation box. This is bad!

The confirm box appears so often now, people ignore it. It becomes part of the process to do that action. Want to delete a file? Hit delete and enter. Even if you really really didn’t want to delete that file, it’s too late: the file’s gone. Because you automatically hit ‘yes’ when it asks you if you are sure.

It’s like asking a colleague to make you a cup of coffee when it’s their turn to do the office tea-round. They wouldn’t respond saying “Are you sure you want a coffee?”, because it’s just silly. And if they did, as with confirmation boxes, you’d just end up saying “Can I have a coffee please? … Yes”.

Undo is the only way to confidently ensure that no problems occur from making a mistake. Whether it’s accidentally deleting that file and being able to retrieve it from the recycle bin, or hitting the wrong option in a form and having the ability to go back. Give the user security in the knowledge that if they do something wrong, it doesn’t matter.

Let’s stop making people too scared to use computers.

Introducing CSS3January 30th, 2009

As you’ve noticed, a few weeks ago I launched a redesign of my website and blog. Although I’ve used some elements of CSS3 in the past, this design uses the most. Not all browsers display all CSS3 styles, but most modern browsers implement at least some.

The CSS3 styles that I used on this site are rounded corners and drop shadows, but other elements include alpha transparency control, web fonts, text shadows, and attribute selectors.

Rounded corners

The classic way of creating rounded corners involves creating background images, which is difficult and messy to do. Although it only works in Firefox and Safari/Chrome, the CSS3 method is much simpler and requires two lines of CSS on the element:

-moz-border-radius: 10px;
-webkit-border-radius: 10px;

The top line is read by Firefox, and the second line by Webkit browsers (Safari and Chrome)

Drop shadows

Although it only currently works in Safari, drop shadows now (or will soon) no longer require the use of graphics:

-webkit-box-shadow: 1px 1px 5px #ccc;

The first two values contain the horizontal and vertical (respectively) distance between element and shadow, the third value (5px) the size of the drop shadow, and the last element defines the colour.

Alpha transparency

CSS3 lets you define exactly how opaque a colour is by using the RGBA format (red-green-blue-alpha). This can be used in place of a hex code anywhere you define colour in your CSS. For example, if you want a semi-transparent black background for a div you might use

background-color: rgba(0, 0, 0, 0.8);
Where the red, green and blue values are 0 and alpha is at 80%.

Web fonts

With CSS2, the only choice you had regarding fonts were using a web-safe font such as Arial or Gill Sans, or using an image replacement tool such as sIFR or FLIR. CSS3 includes web fonts, which allows the browser to import a font file stored on the web server. This is achieved using the @font-face rule.

Text shadows

Text shadows allow you to give normal text a small drop shadow, which is especially useful if you have a background image that may make the text harder to read. This can be achieved very easily, with a format similar to drop shadows:

text-shadow: 1px 1px 2px #ccc

Attribute selectors

CSS3 allows you to style a tag depending on any attributes. So for example you can include an icon after an external link, or apply a style to a password input box.

a[href^='http://']:after{
content: url(images/externallink.png);
}

href^=’http://’ means to match <a> tags with the attribute ‘href’ beginning with ‘http://’
^ can be replaced with $ to match those ending with a string, or replaced with * to match those attributes which contain a string.

Conclusion

So even though not all browsers support all parts of CSS3 yet, I believe it’s worth using those that are supported now, as part of progressive enhancement.

External Links

6 common HTML errorsJanuary 9th, 2009

A recent study by Opera has found that only 4.13% of websites are valid. Although admittedly sometimes writing invalid HTML can’t be helped, there are many errors that can be easily avoided. These are:

Using outdated tags and attributes

Over the years, W3C have depreciated a number of HTML tags (such as <center> and <u>) and tag attributes; stuff that can be better done with CSS. However, many people forget to update their HTML (or a WYSIWYG editor uses these depreciated tags), and so they end up in websites anyway. Sometimes using CSS doesn’t quite cut it, and the author has no choice but to use depreciated tags and attributes.

Using the incorrect tag

This won’t throw up an error in the validator, but is certainly incorrect HTML. It seems loads of people don’t realise how much HTML and CSS is actually out there: there’s definition lists (for question/answer type lists), css for better form and page layout (rather than tables), more table tags than the usual column/cell tags, and six different header tags (which shouldn’t be used for their typography!). If you use the correct semantic HTML, it will vastly improve site accessibility and SEO.

Not using HTML entities

Certain characters, such as &, <, >, and £ need to be converted to their entities. Again, this is usually down to poor WYSIWYG editors, or people who are unaware of this requirement editing sites. Not using entities isn’t usually the end of the world, especially if it’s a common character (such as the ampersand), but it may cause problems with foreign characters.

Using invalid HTML/XHTML syntax

In XHTML all tags need to be closed, even if it’s a self closing tag such as <br />. In HTML, not all tags need to be closed but a good number still do. There are other changes such as only allowing lowercase tags and requiring quotes in attributes. Often when converting from HTML to XHTML, these are missed, and sometimes can cause problems with the website not displaying as intended.

Also, sometimes you may forget to close your tag pairs. A good HTML editor will warn you about this!

Putting tags in the wrong place

Sometimes if you put a tag somewhere where the validator isn’t expecting it, an error will show. This includes not surrounding inline elements (such as <span> or <a>) with block elements, or putting other tags inside lists.

Not using the ‘alt’ attribute

I cannot stress how important the alt attribute is! It’s important not only for accessibility but also for SEO. If your image is purely decorative, still use the alt attribute but leave it empty (alt=”"), or better yet use CSS.

And there we have it, six HTML errors that I see a lot, although there are many more. It’s always good practice to run your site through the validator to catch any mistakes you make, to make everybody’s life easier!

Tech Usability #2: Hitting your targetJanuary 2nd, 2009

When making targets for your user to click or point on, the bigger you can make it, the better. This is shown by Fitts’ law, which states:
Time = a + b log2(distance/size + 1)

Where a is the start/stop time of the device, bthe speed of the device, distance is how far is is from the starting point to the target, and size is how big the target is (or rather, how wide it is on the axis of the direction you are moving).

How does this affect me?

There’s two ways which Fitts’ law can be used to your advantage to make your websites more accessible: putting your targets near the “starting point” and making them nice and big.

Put your targets nearby

It goes without saying that the further away something is, the longer it will take to get there. Of course, if you are designing a website then you won’t know where the user’s mouse pointer is, but you can make a guess. For example, if they’ve just filled in a form, then it’s probably likely that their mouse pointer is over the last field that was filled in, so put the submit button near the last field.

Popup menus can be useful for proximity, since the target is pretty much right next to the pointer. The most common usage of this is the popup menu you get in Windows when you right-click, but this could also be done on the left-click or even when a user presses and holds on a touch-screen device (such as in Windows 7).

However, you need to beware that popup menus don’t get in the way of the intended target. The Marks and Spencer website does this by covering up a large amount of the page (including the search box) when you go over the menu item (see below). This could be solved by either having a short delay before showing the menu, or having it show when the user clicks on the menu bar.

Screenshot of M&S website

Another noteworthy method is having the targets at the edge of the screen, for example having the Windows Start menu at the bottom left, and the Dock at the bottom of the screen in Mac OS. Mac OS also make extensive use of hot spots, where the corner of a screen is the target.

Make your targets big

Screenshot of BBC News sidebar menuWhen making links, make them nice and big. Don’t use small 5px high buttons, make them nice and clunky!

A common mistake designers make is to ignore the whitespace around links in menu bars. So even though the link itself is small, if you make the whitespace active then the target is made bigger! For example, the BBC News website (see right) has wide menu items in the sidebar, where the whole width of the sidebar is active rather than just the link text. This can be seen in the image where the whole ‘politics’ menu item has been highlighted.

It’s also helpful for accessibility!

Your older visitors will thank you for having large link targets: those with poor motor skills will struggle to move the mouse with fine detail, so will be able to browse quicker. To see this for yourself, try using your mouse with the tip of only one finger: you’ll notice yourself slowing down to try and hit the small targets.

The Accessible Web #2: All about colourDecember 19th, 2008

Picking the right colours for your site can be a tricky thing, and the accessibility considerations only makes things a bit trickier. But if you ask me, the limits imposed will make your website easier to see and read by everybody: somebody doesn’t have to be colour-blind to struggle to read green text on a red background.

Help the colour-blind

A large chunk of people are colour-blind: about 1 in 10 males have red-green colour-blindness, this is when the person cannot easily discriminate between red and green hues. A less common form of colour-blindness is blue-yellow colour-blindness, where the individual struggles to discriminate between blue and yellow.

The quick and simple solution to make life easier for those who are colour-blind is to not use the red/green and blue/yellow colour combinations where discrimination is important (for example having green text on a red background, or having red and green as the two colours on a graph). To check how a site looks to somebody who is colour-blind, take a screenshot and convert the image to greyscale.

Give the colours sufficient contrast (WCAG2 1.4.3/1.4.6)

Giving the background and foreground colours enough contrast makes it easier for those with visual difficulties to read the text, and makes the site easier to read in general by everybody (I’m sure we’ve all squinted at some yellow text, struggling to read it).

A formula (based on ISO-9241-3) is used to gauge a ratio of the contrast between two colours. To meet WCAG2 Level AA this should be at least 4.5:1 (3:1 for text larger than 18pt), which is increased to 7:1 (4.5:1 for large text) if you want to meet Level AAA. Some websites prefer to have an option to change the colour scheme to a high contrast one, which is perfectly acceptable.

Don’t use too much contrast!

Having said that, try not to have too much contrast. People who have dyslexia sometimes struggle to read text (particularly small text) which has a high amount of contrast (black on white is a classic example).

For a quick and simple fix, don’t use black on white. Depending on your site’s colour scheme, you might want to use a dark shade of grey (BBC use the colour value #4d4d4d) or you might want to introduce a light background colour.

Using colour correctly (WCAG2 1.4.1)

When using colour, don’t forget that not everybody can see it. If you were to say “click the red button to continue”, you need to keep in mind that people may not be able to see which is the red button (this isn’t to say that using colour-coding is bad, just make sure you don’t rely on the colour to identify objects or an as an action prompt).

Many website owners and developers don’t realise this, but only using colour to identify a link and identifying failed/required fields with colour only may fail WCAG2 guidelines.

Final thoughts

The best way to ensure your site is viewable by everybody is to go out there and test it. You don’t even have to do formal testing to get colour right, since colour blindness and dyslexia are relatively common. Chances are you have a family member, friend or colleague who have one of the two, so run the site past them to see if they struggle at all.

File formatsDecember 12th, 2008

There’s loads of file formats out there nowadays, so there’s no surprising that most of the time people can’t tell the difference between a GIF and a JPG. So here goes, a short list of common file formats on the web and what they are:

GIF

Does anybody even use this format anymore? GIF is really old, and just as bad. You can only use up to 256 colours, two states of opacity (‘transparent’ or ‘on’), and file sizes are large. The only reasons you’d want to use this is if you want to have animation, which no other common format has.

PNG

A better version of GIF. It has millions of colours, better transparency options (such as alpha transparency, where each pixel is given a value — the alpha channel — which states how opaque the pixel is), and better compression (smaller files). Sadly Internet Explorer 6 doesn’t display PNGs with alpha transparency properly, instead a grey background is shown. ‘Normal’ transparency, however, is still displayed fine.

PNG shouldn’t be used for photographic images, since the compression isn’t really meant for them. Instead, JPEG should be used.

It’s worth noting that Adobe Fireworks will store extra meta data into PNG files, such as layer information. PNG isn’t a layered format, this is something that can only be seen by Fireworks. Having said that, Fireworks is excellent at exporting PNG files for the web, and when using the “Save for web & devices” will often provide smaller files than Photoshop.

JPEG/JPG

Showing JPG artefactsShowing JPG artefacts, note the
grey pixels around the text
(brightness of magnification has been
decreased for clarity and demonstration
purposes)

Best for photographs, due to the compression algorithms being best for those kind of images. Not so good for images with text or sharp edges: this is because the nature of the compression means that ‘artefacts’ will appear (see image, right). JPEG is what is known as a ‘lossy’ file format, which means that bits of the image is effectively stripped out during compression (that means every time the file is saved in a graphics editor).

PSD, AI, INDD, FLA

The native file format for Adobe Photoshop, Illustrator, InDesign, and Flash respectively. You won’t see these on the web (browsers can’t read them), but if you’re a website owner you might see them floating around as graphic designers normally keep the original files, so that important data such as layers and filter options are kept.

SVG

A graphics format, but slightly different to the others. Instead of storing information on a pixel-by-pixel basis, information on the actual shapes is saved. For example, “A line this thickness from here to here” or “a circle of this radius starting from here”. This kind of file is known as a vector format, and is particularly useful for logos and icons since they can be blown up or shrunk to pretty much any size.

SWF

A Flash file that has been compiled and can be ran on any browser (assuming the browser has the required plugin installed, of course).

MPG, MOV, FLV

These are all various video formats that can be found on the web. To go into the differences would go beyond the scope of this article, all you need to recognise is that they are for video

Web browsers: a rundownNovember 28th, 2008

With Google entering the web browser market, there’s now more choice for the user than ever before. But most users don’t even realise such a choice exists, and stay with the default choice in their operating system (Internet Explorer). So here’s a rundown of the most popular browsers out there, and what’s so good — and bad — about them.

Internet Explorer 6

This is what you’ll get by default if you have Windows XP. Now eight years old, IE6 is one of the oldest browsers out there. It doesn’t follow standards properly (and doesn’t follow the very latest standards at all) and has many security problems. All IE6 users are urged to upgrade to IE7.

Internet Explorer 7

IE7 comes with Windows Vista, and is the current version of the Microsoft browser. Improvements over IE6 include tab support, better font display, and better security. Although not as good as other browsers, IE7 also supports standards better than IE6.

Internet Explorer 8

Not yet released (it’s in the late stages of public beta), but Internet Explorer 8 is the upcoming version, with a release planned vaguely soon. I’ve been playing around with it this week and I’m very impressed. Improved features include a better address bar, better search bar, and improved crash recovery (so improved, in fact, you barely notice anything’s crashed)

Firefox

The most popular Internet Explorer alternative. Firefox is an open source browser, which means that it’s free to download and use, anyone can contribute to the code, and anybody can create a plugin for the browser.

Safari

Safari is to Mac OS what Internet Explorer is to Windows. That is, it is the default browser for Macs. Built on the very standards-compliant Webkit engine, it’s very quick and very good looking. Safari is now actually available for Windows, but I agree with those who say that it looks slightly out of place: it has the look and feel of a Mac OS application but inside the Windows look and feel operating system, so it does take a little getting used to.

Safari is also the browser included in the iPhone, which means you get the real web, and not a stripped down WAP-enabled where-the-hell-did-all-the-pictures go web.

Opera

Not many people will have heard of Opera, and to be honest, nowadays it’s nothing to phone home about either. Just like Safari, Opera is available for mobile devices, but other than that it’s pretty much “just another browser”.

Google Chrome

The latest entrant to the sardine can known as the web browser market. Chrome uses the same engine as Safari (Webkit) behind the scenes, but with a lot of improvements that many current browsers don’t yet have. These improvements include running tabs as different “processes” which effectively means you have more than one version of chrome running (so it’s better when it crashes), a better address bar which includes suggested search results and previously visited sites, and a default homepage which contains your most visited site.

Chrome is still very new to the market and has little market penetration (current figures range from 1-5%), but some commentators believe that Chrome will eventually do well.

Which one to choose

So, the question to ask now is which one to choose. Well, personally I say nowadays you can’t go very wrong. With the release of IE7, all browsers are at least vaguely standards compliant (which is the main thing) and most browsers are now decent bits of software.

This renewed competition has been a very good thing in recent years, with many developments being made. All of the browsers now have their pros (and, of course, their cons), so my advice to anybody is to try out all the different browsers for a bit and see which one suits you the best. Afterall, there’s no harm in it.

Adobe CS4 (part 1)November 7th, 2008

Part one in a series of articles about Adobe CS4

Earlier this week I attended an Adobe CS4 tour, to check out the cool features of this new release. After picking my jaw off the ground for the fiftieth time, I decided that I really must upgrade, as it’s a fantastic release.

So, the new stuff. Bearing in mind I’m a web developer by trade, I’m only going to be going into those products that affect (and therefore excite) me personally. These are Photoshop, Illustrator, Dreamweaver, Flash, and Fireworks.

Photoshop CS4

There’s three things that excite me about Photoshop: the new smooth zoom which looks simply brilliant, the on-image adjustments, and the canvas rotation.

  • Smooth zoom — It may be little more than eye candy, but there’s something about it that draws me in (pun not intended). I’ve always found the zoom in CS2 to be a lot to be desired, and finally it’s been improved and looks good in non-standard zoom levels. I also really like the new grid that is shown at deep zoom levels
  • On-image adjustments — is probably the feature I’ll make the most use out of. I’ve always been a tad scared by the graphs in some of the adjustments, and now it can all be done on-screen. I’ve yet to actually play with this feature, but going by the demo it looks extremely cool and very easy to make changes

Dreamweaver CS4

What can I say, this is the update that excites me the most. In the past, Dreamweaver has always been a so-so application for me, with my preferred editor being Komodo Edit. However, this new update contains a ton of updates that I really am very excited about: stuff that Komodo can’t do. I think the only thing holding me back from going completely to Dreamweaver is Komodo’s superior auto-complete.

So, what are these cool new features I’m so excited over?

  • Live design view — Webkit (the engine behind Safari and Google Chrome) is now used to show the design view, which means that things such as javascript now appear and the view is standards compliant. Personally I might not find much use behind it because I mostly write webpages in php, but still, it’s nice to have
  • Live code view — How was this never thought of before? How did we ever accept not being able to view the changes to HTML that javascript makes? Amazing stuff
  • Smart Objects — This one made me wow. If you’re importing a graphic into Dreamweaver, you now no longer have to go through the hassle of loading up Photoshop, exporting for web, going back into Dreamweaver, importing the graphic… you can now do it all inside Dreamweaver. What also makes it great is it also exports it to the size you want: if you only need a small thumbnail, then a small thumbnail file you will get
  • Subversion integration — Every web developer knows that we should be using versioning control, but it just never happens. The applications are just too complicated, and it’s such a pain having to check in and out all the time. This wasn’t demo’d on the day, but I’m still very excited by this feature and I really do hope it works intuitively. Maybe this is the kick I need to actually start using subversion

Next time

In the next article I’ll be taking a look at some more of the CS4 suite, including Illustrator, Flash, and maybe even Fireworks.

FLIROctober 17th, 2008

An alternative to sIFR called FLIR (Facelift Image Replacement) was mentioned on Boagworld recently, and I only just got around to checking it out.

I was never a fan of sIFR, mostly because it required using (and owning) Flash. So not only does that mean you need to own a flash player to see the text, you also needed to own a Flash composer to create the font file.

FLIR uses php and javascript only: the javascript calls the php script, which changes text into an image. It’s all controlled in CSS and a couple of config files (which you rarely ever have to touch), and if you have javascript disabled (or your browser doesn’t have javascript) you wouldn’t know the difference. Even if you do have javascript enabled, to the reader the sites looks just like you have an image with the text in.

Personally, I’m rather excited by FLIR. Being a big typography fan I was always disappointed by the small number of web safe fonts out there, so I’m looking forward to using FLIR a lot. It’s a little buggy, but it’s still new, and I’m sure these will be ironed out in time.