CSS Best Practices

I have always tried to write a perfect CSS, but I think nobody can say that they're written CSS is perfectly and optimized. May be, one can say that perfect CSS writing is a myth. But with the skills and experience you can write some good style sheets.

If you look for some suggestions to write a perfect CSS, than might be possible to get many different ways to write a good CSS because everybody will give their own perfect style codes suggestion.

Though I have tried to list down few practical points to write a better style sheet. These points surely will help you to make your CSS less complex, optimized and clean-up.

There are few points which needs to be keep in mind while writing a CSS.

  • Stay organized while writing the CSS. i. e. Make sure your header, nav bars, main selectors should come first.
  • Make your CSS readable.
  • Create a logical structure of CSS. I.e. overrides, margins, links and types, main layout, secondary layouts, form elements, etc. depending on the application structure.
  • Make sure CSS classes name must be in small case.
  • Use “-” instead of “_”.
  • Naming convention of CSS class must be meaningful and useful.
  • Use short hand CSS.


        Example:

               margin-top: 10px;


                  margin-right: 24px;

                  margin-bottom: 12px;

                  margin-left: 0;

          Use 

                  margin: 10px 24px 12px 0;

  • Use External Style Sheets.
  • Use hex color codes instead of color names.
  • Try to use Reset.
  • Use multiple CSS classes.
  • Comment your CSS to make other understand well.
  • Group the classes which can be repeat on mostly elements.
  • Use margin:0 to make layout in centre.
  • Use List to present data in a structured way.
  • Shrink CSS file size so that CSS will be lightweight and loading time could be faster.
  • Simplify css using equivalences or unique commands.
  • Don’t use extra selectors.
  • Try to make a library of common css classes.
  • Use proper document structure.

CSS is easy to use and lightweight and loads faster. There are many more advantages of using CSS. It helps webpages to make responsive on any devices.

References:

https://hackhands.com/70-Expert-Ideas-For-Better-CSS-Coding/

https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Writing_efficient_CSS

https://code.tutsplus.com/tutorials/30-css-best-practices-for-beginners--net-6741

https://www.smashingmagazine.com/2009/08/designing-a-html-5-layout-from-scratch/

http://learn.shayhowe.com/html-css/writing-your-best-code/


Can u give answer margin have negative value or not...

Like
Reply

To view or add a comment, sign in

More articles by Swati Singh

  • IOT (Internet of Things)

    What is the Internet of Things? What we understand from the term “Internet of things” aka “IOT”, very popular these…

  • Overview of AngularJS

    Prerequisite Basic knowledge of HTML Basic knowledge of CSS JavaScript Implementation Why AngularJS? Two-way data…

  • ECMAScript 2015 (ES6) – New Features – PART 1

    Constant: We heard many times about Constant variables in Object Oriented Programming like C++, Java etc. now…

  • Importance of choosing website layout

    While making websites responsive we heard many terms like fixed, fluid, responsive and adaptive. All these terms have…

  • So Do You Think PhotoShop is Dead for Web Design?

    So, let’s start with the flow. Since the ancient time of website making there is a simple flow our designer makes the…

  • Develop Your Skills To Be Productive and Effective

    In any profession you are or you want to be, you need abilities and aptitude required for the same. The greater part of…

  • Dare To Believe

    Dare to remember, Dare to believe..

    2 Comments
  • Result Of Thought

    "All that we are is a result of what we thought" because thoughts becomes words which become your actions which becomes…

    6 Comments
  • Motivation Lies Within Us

    What lies behind and what lies before us is tiny matters compared to what lies within us. You may hear above quote many…

    1 Comment
  • Boost Your Self Confidence

    Confidence is a tool we can use in our everyday life. This manage our fears and make us able to do more of the things…

    4 Comments

Others also viewed

Explore content categories