CSS Pitfalls for Web Designers to Avoid

CSS Pitfalls for Web Designers to Avoid

The stylistic language of CSS has been among us for many years, yet while it possesses the ability to engage and entrance our visitors with increasingly complex feats of layout and design engineering, poor decision making can affect the final outcome. While often due to a lack of awareness of the implications or from personal choice, a number of potentially problematic issues exist that can result from innocent decisions. This article aims to correct these common practices.

CSS Pitfalls for Web Designers to Avoid

Proprietary Code Isn’t Demonic

The first pitfall that needs to be addressed is the common misconception regarding proprietary code such as webkit transitions and animations. One of the major reasons why vendor prefixed code is frowned upon by many in the industry is simply because it doesn’t validate. Because the code was not set or sanctioned by the W3C, those who rely on the validators see it as a mistake rather than a helpful feature which can boost a site’s beauty which is rather a shame when you think about it.

Solar System

Figure 1: Even with the proprietary label, Webkit’s animation transitions remain pretty awesome!

Cgalvin

Figure 2: Until CSS3 is widely adopted, vendor prefixes will remain a solid route to gaining opacity.

As designers, we regularly find ourselves trapped within code. With CSS having a specified limit on what properties are valid, custom properties are given an opportunity to push the boundaries, test new features like CSS3 before it goes final and not intrude on the general layout. Yes of course, if you make your code depend on them, it’s likely to break, but surely you make your CSS progressively enhance to such code and update your site anyway, so there’s not really anything to worry about! Using proprietary CSS isn’t a bad thing – it just requires an extra bit of attention and maintenance.

Ignoring Browsers or Mobile Devices

The next pitfall we can address is one which seems to be trickling into the mainstream, but not at a proportionate pace in relation to its visible growth. Like them or not, many cellphones and handheld devices now have Internet access, and not just that clunky WAP system which existed in the 90’s. Many smartphones and featurephones actually have a fully fledged browser within them. With this in mind, why do so many people still remain loyal to testing in desktop rendering engines?

iPhone

Figure 3: The iPhone really changed the way the Internet was consumed in a proper browser.

WML Website

Figure 4: Back in the days of old, a WML website was the only method of getting web content.

People are using the web in all sorts of ways they didn’t in the past. Televisions are being enabled, phones are already enabled and there have even been refrigerators with Internet access in the past though it’s fair to say that it didn’t take off. Some people don’t test outside of the desktop because of perceived costs this is less of an issue with the range of good emulators. It’s also not fair to say that the usage numbers don’t justify the testing after all, usability should be paramount. If your site doesn’t already work on handheld devices, it’s now time to consider making the experience better.

Inline Style When External Will Do

Many standards advocates have been promoting the importance of separating structure, behaviour and style for the reasons of ease of maintainability and the advantages of caching, yet still to this day there are many individuals who make use of either the style attribute, style tags within the header or even resort to using deprecated stylistic elements within their code. While the more perceptive and up-to-date amongst you will already avoid this at all costs, the bad trend just seems to continue!

Inline Code

Figure 5: Inline code is still quite persistent, even on websites which should know better.

HTML Elements

Figure 6: Plenty of stylistic HTML elements were deprecated, and can still be found on the web.

In this case the resolution of such problematic coding is education and while we all know that taking that CSS, stripping it from the page and breaking it into a separate file will give you the amazing and cool bandwidth savings that browser caching provides possibly more if you have GZIP enabled on the server, the necessity of many CMS products, prebuilt apps and WYSIWYG editors to continue applying style in such a manner requires immediate attention. There is rarely a case where internal style is of more use than external, and as such, learning to avoid repetitive coding is worth the effort.

Keep it Together (Less Files are Good)

Following on from the previous pitfall, something which plenty of active designers who code beyond the novice level will encounter is the separation of stylesheets into smaller files. While the breaking down of style into separate files may serve a purpose if you update your CSS files regularly and wish to maximize caching, the argument that separate files are easier to navigate seems to showcase the IDE or editor’s lack of code tracking methods than a real need to invoke added HTTP requests.

Keep it Together

Figure 7: Each requested resource adds to the overall loading time as it waits for a response.

Mobile Stylesheet

Figure 8: Having your screen, print and mobile stylesheet in one single file is entirely possible.

Putting it simply, editors like Notepad++ have the ability to cleverly collapse code, which removes any potential issue which may result from lengthy CSS files. If your current editor doesn’t have such a function, it may be worth changing to a tool that does as unless you update your CSS regularly, the extra HTTP requests to the server are waste produce. While this may seem rather picky, it’s easier from the browser to navigate “view source” in a single file, and as media selectors can target specific conditions like print styles or certain widths, you can still have the separation within a single file.

Typeface Dependence and Unit Values

Finally it’s worth mentioning the pitfalls of typeface and unit value dependence. Back when the web was young, the need for selecting relatively Websafe typefaces was critical, yet while the lures of @font-face may give another impression, this still hasn’t changed. So many sites assume that a font has been installed or font-face will be available that many simply ignore the traces of usable fallback mechanisms. In addition, tonnes of sites still use PX units on text which is crazy for IE users.

Custom Fonts

Figure 9: Everyone is getting used to custom fonts, just be careful not to depend on them!

PX Unit

Figure 10: Resizing text using a PX unit of measurement in IE is impossible without using zoom.

With Websafe fonts, it’s easy to say that there’s no such thing as most typefaces can be uninstalled along with font-face downloads disabled, and with CSS3 not being available everywhere, it’s still very important that we acknowledge those devices. When you make use of the font-family property in CSS, always ensure that you have a proper stack formed with fallback options, it’s that simple. As for measuring text unit’s in PX, while the Zoom function in every browser will handle the task of resizing it with ease, IE’s Text Size accessibility option (even in IE9) can’t resize PX measured text!

Think Before You Style

There are plenty of mistakes we can end up with while coding, from forgetting the hash character in color hex values to spelling the properties incorrectly or even forgetting about case sensitivity in CSS selector names. While the journey of getting to grips with CSS may be long and slightly daunting for the less experienced coder, the need to think about what you’re doing, exploring the risks of using both standardised and proprietary code in browsers and staying in control of your site is critical.

For the more advanced CSS developers out there, the terrors of hasLayout and the new frontiers of mobile design will remain heavily in our focus as will browser compatibility. For beginners, the way in which you build, structure, organise and maintain your code (and getting past those simple yet somewhat annoying validation issues) will be paramount. In either case, it’s acceptable that we will all suffer at the hands of our own mistakes (or those of browsers) in the future, so the best thing any of us can do is stay vigilant, read the specifications, keep learning and stay on top of what’s new!

More Resources

Questions

Do you agree with my observations that vendor prefixed codes can be helpful? Are you a fan of font-face and non-Websafe typography? Do you test or build for mobile devices? Or are you the person who still uses inline styles or tonnes of separate CSS files? Let us know in the comments!

Deals

Iconfinder Coupon Code and Review

Iconfinder offers over 1.5 million beautiful icons for creative professionals to use in websites, apps, and printed publications. Whatever your project, you’re sure to find an icon or icon…

WP Engine Coupon

Considered by many to be the best managed hosting for WordPress out there, WP Engine offers superior technology and customer support in order to keep your WordPress sites secure…

InMotion Hosting Coupon Code

InMotion Hosting has been a top rated CNET hosting company for over 14 years so you know you’ll be getting good service and won’t be risking your hosting company…

SiteGround Coupon: 60% OFF

SiteGround offers a number of hosting solutions and services for including shared hosting, cloud hosting, dedicated servers, reseller hosting, enterprise hosting, and WordPress and Joomla specific hosting.