Big Mistakes to Avoid in CSS

CSS SphereCSS – on the surface – is a very simple web-based language that uses common syntax and phrases that make it simple to customize elements in a variety of aspects.  Digging deeper into the language, however, can reveal lots of formatting issues, redundancies and code errors that can cause your CSS to not perform as well as it should and this is what will separate the CSS professionals from the novices.  Here is a list of several of the most common big mistakes that can appear in CSS code along with some solutions for replacing the errors and making sure your end result checks out.

Use Hexadecimal, Not Names

Being lazy is not an admirable trait in CSS and can lead to code incompatibilities and inconsistencies.  For example, each browser may read your color codes differently when using “red” or “blue” than when using “FF0000” or “G5Y7F3”.  In order to guarantee the colors displayed through your CSS scripts are being displayed exactly how you wish, use a color sheet or hexadecimal generator that gives each color a specific, uniform definition.  Using traditional color names can add extra code that increases the overall file size of the script, which is another reason to avoid its use.

Avoid Redundant Properties

To give an example, let’s say we have the following two elements: #element-1 and #element-2.  Both elements have the same attributes (font-style, color, margin, padding) but in a poorly written example of CSS, we may still see these elements separately.  By combining the elements into something like this: #element-1, #element-2, followed by the common code, you can give both elements the same attributes with roughly half of the code, which simplifies the code’s readability and decreases overall file size.  This comes in handy when having to make changes and will save you tons of time in the long run.

Eliminate White Space

For clarity and ease of use to the human eye, many coders will leave chunks of white space separating important elements so that quick changes can be made and errors can be spotted easily.  After the code has been finalized, however, you will want to eliminate these white spaces in order to have successfully reduced the file size to the smallest amount possible.  Yes, even these spaces take up valuable file space and when speed is everything, you want to have your CSS code as compacted and minimized as possible.

Use Validation Tools

Finally, once you have made all of the optimizations and corrections you can see and think of, locate a CSS validation tool to confirm whether or not your code is properly written and executed prior to deployment.  One of the ways you can check this is by using Pingler’s CSS Validator Tool, which will let you know whether or not your code meets the validation standards set forth by the W3C.  Simply upload the code to the web, direct the CSS Validator tool to the URL of the code and it will inform you whether or not said code is up to par.  It doesn’t get much easier than that.

Leave a reply translated

