7 tips to improve your CSS
Are you looking to improve your stylesheets by creating better CSS? Then take a look at these tips.
1. Create conventions for standard structure elements
If you work often with stylesheets, you should definitly make sure that you have a commonly used classes and ids naming structure. This way you will gain a lot of time by not having to endlessly scan your stylesheet.
2. Format your CSS with sections
For better structuring of your stylesheet, a good idea also is to create delimited sections of your CSS. It’ll make it easier to scan through and quickly find what you are looking for.
3. Keep your CSS separated form the HTML
Even if you are using page-specific CSS, you are probably better off creating a specific stylesheet regrouping all page-specific CSS rather than using inline or in-page CSS.
4. Use classes and id’s where appropriate
Only use ids for unique identification of a page element, for everything else use classes. If you are not careful with this you could run into problems when modifying your website.
5. Format your CSS consistently
I am not going to tell you if it’s better to format your CSS with one line per element or by using block display, but when you made your choice you should stick to it or your stylesheet may turn into CSS hell.
6. Use shorthand as much as possible
Shorthand CSS not only makes your stylesheet lighter, it also helps to make it easier to scan by having less properties.
7. Include color references
It took me a long time to get started using this tip, but I don’t regret it. Including your color scheme’s references will definitly be a time-saver on the long term.
Advertisements
18 responses so far!
-
7 tips to improve your CSS…
Are you looking to improve your stylesheets by creating better CSS? Then take a look at these tips….
-
7 tips to improve your CSS…
Are you looking to improve your stylesheets by creating better CSS? Then take a look at these tips….
-
“Include color references”
You’ll need to explain that one a bit more – it’s way too vague.
-
[...] Visit Source. [...]
-
[...] 7 tips to improve your CSS [...]
-
I try to keep my CSS clean and easy to read, but then I will clean it up for production…
How can I not subscribe to a website named CSS Orgy? That’s great..
-
Thank you for the refresher!
@Dean – Adding your color scheme to the CSS: Whatever color scheme you are using for your site – include this in your CSS comments. Let’s say you are using White, Black and Blue as your color scheme on your site: Place this inside your CSS:
White: #fff
blue #192543
black: #000
It is recommended to add this in your top Comments above all Styles. Included in these comments should be the author, date and title of the site. An example may be:/* 12-12-09
My First Website
Brian Jones
Colors:
White: #fff
Blue: #192543
Black: #000
*/ -
I started adding my color scheme at the top of my css file about a year ago and I can’t sing the praises of this tip enough.
It’s also very helpful when creating alternate color schemes for premium & free themes.
-
[...] CSS Orgy » Blog Archive » 7 tips to improve your CSS [...]
-
[...] 7 tips to improve your CSS [...]
-
[...] 7 tips to improve your CSS [...]
-
its excellent! useful tips.
-
[...] CSS Orgy » Blog Archive » 7 tips to improve your CSS (tags: css tips) [...]
-
This article has been shared on favSHARE.net. Go and vote it!
-
[...] Read the original article [...]
-
Hello,
This is blog.How can I improve it ?
-
I’m a newbie with css, maybe your tut will help me one step further, thnx
-
Nice article! Coding conventions are a must! To anyone who plans on ever doing web design in a team environment, it is very important to have consistent conventions used in your code. This improves the readability for those who did not author the code but must adjust it. I believe the most underrated convention is that of the order of your CSS. Where do you put your general classes, your tag specific classes? It’s extremely easy to find a solution with your CSS code and be done with it. What separates good coders from decent coders is the patience the good coders have to collect themselves after successful results and focus hardcore on readability and logic in the code. Just because the code works doesn’t mean it’s good code!

Loading...


