A lot of times I see CSS that has been written by other people, usually people who are just starting out, and it’s terrible. That’s not to say it’s invalid, although that sometimes is the case, what I mean is that the way it’s composed makes it very difficult to read and/or understand.
This article is aimed at helping people improve the code they write, whether they're beginners who haven’t had the chance to learn these lessons themselves yet, or elite 12th dan webdev masters who may have missed a trick or two. Of course, that’s not to say I’m such a master, far from it, but I do have knowledge that can help others, and I hope to share it with you now!
How to Format CSS
It was a while before I discovered that spreading the code out wouldn’t be the end of the world. Now I write code more like this:
There are, of course, many more ways to write the code, some of which include indenting the property with a tab instead of two spaces, separating the colon and value with a space, and putting a space or new line between the selector and opening brace. All of these are perfectly valid ways of writing code to increase readability, so if your code is difficult to read, try spreading it out and see if it makes a difference. Don't just do it for yourself, but for other people who may try to read your code as well.
Inaccessible Navigation: The #1 mistake webmasters make is to make their navigation inaccessible to search engines either through flash, javascript, or just plain bad coding. If a search engine cannot utilize your navigation they cannot crawl your site, period. Any pages on your site without an external incoming link will not be crawled. Even if you have 1000 pages on your site, likely only the homepage will be indexed. Your traffic potential will be only a minute fraction of what it could be.
Non-unique Title Tags: The #2 mistake webmasters make is to repeat the same title tag on every page of their site. Some software programs, either content site management systems, or shopping carts, do this out of the box. The title tag is the single most important on-page element for search engine optimization and it needs to be uniquely tailored for each page of content. Failure to do this is a huge hindrance to your efforts. If your software does this you either need to hack the software, or get different software.
Putting Session IDs in the URL: Search engines cannot crawl sites that append session IDs to the URL. The reason is that while the crawl happens there IDs will continually change, thus changing the URL, thus making the search engine crawl every more duplicate pages in a never ending loop. As such, when encountering a session ID or something that looks like it, most search engines stop crawling. Depending on your backend code as well, this can be a problem when a session ID page is actually indexed and someone follows that link from a search engine they can be assigned this old session, which may not be theirs.
Mucking up your Robots.txt File: Having a robots.txt file is a good idea; otherwise your error log will be full of requests for it. However the most common cause of a “ban” or “penalty” from a search engine is really just a person putting the wrong thing in their robots.txt file and accidentally banning the search engine (not the other way around). With Google SiteMaps or Yahoo SiteExplorer a webmaster can verify their site is crawlable and robots.txt is not interfering, among other things. Using these services is so vital and helpful that one could even say not using them could be a major SEO mistake.
Meaningless Identifiers in the Anchor Text of Internal or Incoming Links: Incoming links are extremely important, the anchor text inside of them is doubly so. One major mistake people make is to use meaningless anchor text in their internal or incoming links. For instance “Next Page” or “Click Here” do absolutely nothing to help you. You should never, ever, use such anchor text within your own site unless you really do not care about ranking well with the linked to page. And while you cannot control how others link to you, if they ask your input, always ask for something more descriptive that uses your keywords.
Copyright 1998-2006, WestHost, All rights reserved. No part of this publication may be reproduced in whole, or in part, without the express written consent of the author(s).
To keep you up to date with all the latest in Web Development and Marketing, WestHost has created a newsletter to do just that. WestHost Webmaster Connection contains great tips and ideas to help you and your site be more successful.