How To Manually Minify CSS Codes In Static Websites

Sep 23, 2018 | Knowledge Base

minify css code

Webmasters minify CSS codes to reduce their size so that they load faster. Online business success depends on many factors. One of them is your website speed. Most online marketers focus more on the design, content and SEO. They forget the technical aspect of improving the load times to give the internet users a good experience.

This simple tutorial is intended to help webmasters to learn how they can manually minify CSS codes in static websites. It’s intended to help web designers to create sites with downsized CCS markups. A minified CSS source code leads to improvement in the website load time performance, hence a good experience to internet users. It also leads to a better search engine ranking.

What does it mean to minify CSS codes?

The term minification is usually used in computer programming languages. To minify CSS codes is to remove all unnecessary characters from the source code without altering its functionality or the way it works. These unnecessary characters include the following:

Whitespace characters – these represent horizontal and vertical space in the typography.
New line – special characters that indicate the end of a line of text.
Comments – these are source code comments that make it easier to understand the code
Blocks – statement blocks usually signified by the use of brace brackets { }.

Literally, to minify CSS codes is to reduce them, to shorten them, to downsize them, to trim them, to compress them or compact them. A minified CSS code and the one that is not minified both display your website layout in the same way. The only difference is that with minified CSS source codes, a few bytes of CSS markup are sent and the number of requests to get the bits is reduced. The reverse is true with CSS codes that aren’t minified. More CSS bytes are sent leading to increased number of requests.

How do you minify CSS source codes?

There are several minify CSS tools which you can use to compress your CSS such as CSS Compressor. But in this tutorial I would like to show you how you can manually do it. To effectively minify your CSS markup, do the following:

First, remove all the CSS source code comments.

These are usually used with the aim of making the source code easier to understand in programming. But they has nothing to do with They look like in the examples below:

/* tells browsers that don’t read html 5 tags to render likedivs */

/* Copyright (c) 2012 Goleza Designers Limited, All rights reserved
———————————————————————————-*/

/* Reset v1.0 | 20080212 – http://meyerweb.com/eric/tools/css/reset/
———————————————————————————-*/

Secondly, remove whitespace characters in the source code.

Examples of white space are as follows:

U+0020 | SPACE (HTML:  )
ASCII space ( )
ASCII tab ( )
Zero-width space (​)

Thirdly, format your CSS codes on a single line.

Your CSS blocks should look like as in Block A and NOT as in Block B

Block A

h3 {color:#FF8000;font-family: Verdana,Arial, “Times New Roman”;text-align:center;text-height:1em;}

 

Block B

h3 {
color:#FF8000;
font-family: Verdana,Arial, “Times New Roman”;
text-align:center;
text-height:1em;
}

Lastly, remove newlines.

These are characters that signify the end of the text line. They are also referred to as line endings, line breaks or end of line.

A well minified source code should therefore look like as in the example below:

#mainLeft{float:left;padding-top:40px;position:relative;width:325px;text-align:left;}
#mainLeft img{border:none;position:absolute;top:250px;z-index:5;}
#mainLeft .hostgator{border:none;position:absolute;top:670px;left:102px;z-index:5;}
#mainLeft h2{color:#444;font-size:0.8em;text-transform:uppercase;text-align:center;}
#mainLeft h1 span{font-size:40px;color:#FF8000;font-weight:bold;}
#mainLeft h2 span{top:493px !important;}
Conclusion

In conclusion, when you minify CSS code using the steps mentioned above, you will reduce the network latency, enhance compression and improve browser loading time and execution. A fast-loading website is key to your online business success.

0 Comments

Submit a Comment

Your e-mail address will not be published. Required fields are marked *