CSS can be compared to the sculptor’s tool set when crafting a sculpture. We as web designers utilize all the assets CSS brings forth to create structured layouts for our websites. Over the years this design process has become more organized and fitted. Rules have been put in place for best-practice procedures when coding.
We’ll have a look at some ideas you can apply to your stylesheets to help speed up your code in future projects. Efficient CSS is easy to manage and easy to read while also supplying a resource to the web designer. Keeping everything organized is a big step forward, but things get a bit more complicated than that.
Throughout the article keep your personal idiosyncrasies in the back of your mind and try to absorb as much information as possible. The best advice you can get from any developer is to find your own way of working. Try combining a few of these techniques with your own workflow to see how you can benefit the greatest as a CSS developer.
Why Bother to Streamline CSS?
Many web designers get lost in the comparison of frontend to backend languages when talking about parsing code. CSS and HTML are frontend design languages used to format and style elements on your website. Files are downloaded and parsed by the web browser your visitor is using.
This means frontend code still has a quantitative load time. Code developed and parsed by a browser still takes time to be read and computed, just like backend languages such as PHP or Ruby. This is where streamlined CSS can provide a huge benefit to your site in seeing shorter load times and quicker structuring of page elements.
This may not be so obvious with much of today’s high-speed connections and advanced Operating Systems. You may want to try viewing your site through a mobile browser to compare not only load times, but how the website is loaded.
When CSS is coded efficiently you should see elements form and style as they are processed. This can change browser to browser but it’s a common occurrence you’ll see the more you test your website’s code.
You’ll also want to keep your code standardized and simple. When you’re updating your blog or personal website a few months after initial development it’ll be a lot simpler to churn through CSS styles you’re already familiar with. Adapting to a set structure for best industry practices will help in the long run.
How to Work with Efficient Code
To begin coding with ultimate efficiency in your styles you’ll have to adopt some fresh new ideas. These are some basic CSS techniques being used even today by high-tier Internet websites and app developers.
Keep your Code Simple
This seems like an easy one that many will overlook. When mapping out a set of data for how your styles will develop keep it all simple – create data sets in a column stack if you need to.
Start by creating a list of the different sections you will work on in your styles. These can include text, forms, layout boxes, headers, footers, anything you may need. If you’d like to really get organized you can even break things down into a few known styles you will need, such as an ID or class for navigation links.
Afterwards this makes things much simpler when you go sit down to code. Having your resource list in front of you will almost create super-human coding powers to be pouring out code so quickly. This first step helps create a blueprint of your website mockup using “plain words” before going into any style language.
Keep Blocks of Code Delineated and Sparse
There has been an ongoing debate for a while between how CSS code should be written. When I first started I used block notation since it was all I had seen before. However single-line notation is much, much quicker when it comes to parsing and being able to read from a human eye.
This isn’t to say I’m making a case to ignore block-style CSS, far from it. When you are dealing with a key element or ID holding 6 or 7 major properties it will be easier to keep it in blocked form. You’ll be isolating the important pieces and elements out of your style so they’re quicker to find at a glance.
It’s also much simpler to read longer styles in block notation. This is because most text editors will wrap longer lines and reading property:value pairs can get very confusing when you’ve got 10+ to go through. As the web designer it’s your call how you space your CSS code. Just keep the efficiency issue in mind while doing so and always use your best judgement.
Working with Other Developers
This can be an annoyance or a blessing depending on the team. However the fact stands that if you’re currently or aspire to be a professional web designer, chances are you’ll be working with a team at some point.
As designers we can be especially difficult with making major changes to our works. With CSS code it’s a bit different since you’re trying to portray a beautiful layout using only property values. This can get messy when files pass between a few hands so be sure to keep things organized.
Comments can be a major help here. Adding comments to lines or blocks of code which may be confusing or misleading to some will save hours of working time. You want to communicate all of the work you’ve put into a stylesheet in the most elegant way possible.
Ensure while you work there aren’t any duplicate styles or appended styles being overwritten. For example imagine a website’s page headings h1-h4 are styled earlier in a CSS document but some code changes the fonts deeper in. This could be imminently confusing for somebody who didn’t even write the code and now has to go through and fix this bug.
Communication is also very important in web development teams. You can write some of the most efficient code around, but lack of communication is what kills projects. Keep your mental processes focused on the task at hand and work within the boundaries of your team, not just your own creative ideas.
Keep Track of Separate CSS Documents
Another way to keep code clean and organized is to separate the many types of styles you may be applying. This works much better on larger websites which require so many styles that a single document holding them all is an unrealistic sight.
One example of such a site could be Facebook. They would have so many different pages for styles to load on – profile, search, registration, photos. I wouldn’t want to be the guy sorting through all that code to apply a simple bug fix if it were in one consolidated file.
Granted Facebook may be garnering a lot more traffic than you would expect but the principles are the same. If organization is an issue separate stylesheets can go a long way. Commonly today you’ll see web designers keeping code organized based on how it structures the document. For example you may have layout.css, text.css, and forms.css.
The benefit here is not all of these style documents need to be loaded on every page. This allows for greater customization when it comes to building your website. You’ll cut down on parsing time tremendously just by creating separate views and styles for each one.
Testing Support for IE
Internet Explorer has always portrayed the evil bandit for web developers, CSS coding especially. Luckily Conditional Comments can be applied to your HTML which look like regular comments to most browsers. In Internet Explorer they can be used to implement new styles based on the browser your running.
This has always been an issue and with the release of Internet Explorer 9 beta we’re getting just a bit closer to a more solidified Internet experience. Only problem is how many people are still running browsers as old as IE6 or IE7. These have serious processing bugs and sometimes require external styles to fix them, appearing only based on their flawed rendering engines.
Thankfully support has gotten better and Microsoft seems to be turning things around. Keep an eye out for conditional comments if you haven’t worked with them yet. They can prove to be invaluable in many cases where CSS properties just won’t work right and you need an alternative.
Adding a Table of Contents
This is an optional step which I have found to work wonders in my stylesheets. You can keep a table outside of the CSS document itself, but I have found this to be a bit counter-productive. Especially when it’s so easy to add comments in-line.
The main purpose of placing a Table of Contents into your styles would be ease of access and streamlining the editing process. Place markers in the beginning of your document to separate your code into easily-dividable sections.
A good way to approach this would be to create your own table key. For example, if you were splitting your table into each main area of the document (layout, font, header, navigation etc.) you could key them with a set of unique characters.
=!font could be used to delineate the layout and font sections, respectively. Since you probably won’t run into those exact pairs of characters anywhere in your code it’s easy to add them both in your table and at the start of each section in comments. Then using the Search or Find feature of your text editor you can skip down the sections of your CSS styles with ease.
This is also a great way to approach a teamwork project where many people will be looking at the same code. It keeps things organized and easier to find in the mess of styles we see today.
Although there are many ways to approach optimizing the efficiency of your code these examples are a great way to get started. CSS is an ever-changing subset of the design industry and has a lot of new ideas being built around it.
Passion and dedication are required to make it in the design industry. If you can hold onto your passion for digital design it shouldn’t be difficult to keep up with the curve on CSS practices. Reaching out to the community of web designers found all over the web is a leap forward. The experts of industry are more than happy to share their techniques for streamlined CSS which evoke bouts of innovation into others.