How to write CSS like a professional. Best techniques to get from idea to polished result. (2024)

After spending a long time learning CSS, finally you have mastered it. Now you feel ready to tackle any project. You start building your first project and everything works as you expect it to. The page looks exactly as you want it to but your CSS file is more than 1000 lines long. And then you need to make a change. After minutes of trying to find where to make the change you realize that you need to organize your code better.

In this article I will give you the best techniques to keep your CSS organized and its size as small as possible. First let me introduce myself. I am a FileMaker Pro developer for more than 20 years. I have built complete solutions and also I have contributed to many others. The last couple of years I switched interest in Web development. This article is a summary of what I have learned so far in CSS.

Before starting it is necessary to use the proper tools for the job. A code editor like VS Code, Brackets, Atom is necessary. Not only they highlight the syntax but also they catch any misspelling errors. With the proper plug-ins they also auto-fill while you are typing, speeding the whole process.

1. Reset the CSS Default Values

How to write CSS like a professional. Best techniques to get from idea to polished result. (3)

Each browser comes with each own default styles for every page. This causes a page to appear different from browser to browser. The purpose of the reset stylesheet is to reduce this type of inconsistencies. It resets the values of elements like default line heights, margins and font sizes of headings, and so on.

My favorite tool for the job is CSS reset. http://meyerweb.com/eric/tools/css/reset/

2. Use CSS variables

How to write CSS like a professional. Best techniques to get from idea to polished result. (4)

CSS variables also known as custom properties they can reused throughout a document. Complex sites have many repeated values. For example instead of using the same color again and again you can assign it to a CSS variable. This way when you need to make a global change there is only one place to do it.

3. Use Meaningful Names on Your Classes and IDs

How to write CSS like a professional. Best techniques to get from idea to polished result. (5)

It is important to think ahead when naming you classes and ids. It will make your life easier when you want to make changes on the page. For example if you have a class ‘background-blue’ it might be meaningless when you change the color of the background.

Let’s assume you have your page design ready and you know all the elements you need. You should assign the same class to all the elements with the same styling. For example you might have a few pictures of people that need to be the same size, border and shadow. Assign them to the same class name class=“people-picture”. For elements that have partially the same styling but there are one or two differences, you can still assign them the same class and use a second class to style only the differences. If only one item is different, for example CEOs pic use an id for the extra styling. Remember that more specific selectors get precedence over the less specific ones.

4. Use comments to organize your CSS selectors according to your HTML elements

How to write CSS like a professional. Best techniques to get from idea to polished result. (6)

Usually when styling you move from one part of the page to another, while writing a few CSS lines for each part to style it. This makes your code fragmented. It is easier to write the CSS selectors in the same order as the elements of the page. So first you have the general styles, for the whole page then the Header, Navbar, body etc. This way when you need to do a change it is very easy to quickly jump to the correct lines in your CSS file.

5. Group your selectors by Element, Class and ID

How to write CSS like a professional. Best techniques to get from idea to polished result. (7)

In the above example all the styling for class deals and all its sub-elements are grouped together. This way it is easier to visualize what is happening and make changes if needed.

6. Do not Use Named ‘Colors’

How to write CSS like a professional. Best techniques to get from idea to polished result. (8)

Use hex codes for your colors. It is harder to read but they have some advantages. First they are rendered faster than using color names. Second browsers do not agree on what some color names mean. Third you have a choice of 16,777,216 colors to choose from. Also it will be easier to address them once you start playing with Javascript.

But wait. You are not finished yet. There are a couple of steps more needed to ensure the best experience for your users.

7. Use a CSS Validator

How to write CSS like a professional. Best techniques to get from idea to polished result. (9)

Although your page loads properly in your browser it might have unexpected appearance in another browser. Or there might be bugs that do not appear in your browser. Validators check your CSS for errors or bugs and ensure cross-platform, cross-browser and future compatibility. My preferred one is https://jigsaw.w3.org/css-validator/

While you are there you can also validate your html files.

8. Reduce your CSS File Size

How to write CSS like a professional. Best techniques to get from idea to polished result. (10)

Smaller CSS file means faster page loading and better user experience. First you have to remove unnecessary code. To achieve this check for redundant or duplicate CSS code using a tool like this one: http://unused-css.com/

Also shrink the size of the css file by using a css compressor. There are many. One of my favorites is CSS minifier: http://www.cssminifier.com/

By following these little steps you will help yourself and your teamates when you will need to add or modify your code in the future.

I learned most of these tricks as a student in microverse.org. The free school which you pay after you get a job. Why don’t you join me and learn together?

Have feedback? Have more useful techniques you wish to be added to this article? Please say hello 🙋‍♂️ at Twitter or LinkedIn

How to write CSS like a professional. Best techniques to get from idea to polished result. (2024)
Top Articles
Hyperlink
6 Best Ways To Get Revenge on Your Boss - Best of HR
Using GPT for translation: How to get the best outcomes
Best Team In 2K23 Myteam
Regal Amc Near Me
Faint Citrine Lost Ark
Here are all the MTV VMA winners, even the awards they announced during the ads
Mileage To Walmart
Songkick Detroit
Mustangps.instructure
Noaa Swell Forecast
Legacy First National Bank
MADRID BALANZA, MªJ., y VIZCAÍNO SÁNCHEZ, J., 2008, "Collares de época bizantina procedentes de la necrópolis oriental de Carthago Spartaria", Verdolay, nº10, p.173-196.
The Many Faces of the Craigslist Killer
Weekly Math Review Q4 3
Gfs Rivergate
What Happened To Maxwell Laughlin
Katherine Croan Ewald
Soccer Zone Discount Code
Puretalkusa.com/Amac
Plan Z - Nazi Shipbuilding Plans
Vintage Stock Edmond Ok
MLB power rankings: Red-hot Chicago Cubs power into September, NL wild-card race
Vegas7Games.com
John Chiv Words Worth
Sienna
Sand Dollar Restaurant Anna Maria Island
Bay Area Craigslist Cars For Sale By Owner
Cognitive Science Cornell
Wood Chipper Rental Menards
Nottingham Forest News Now
Mobile crane from the Netherlands, used mobile crane for sale from the Netherlands
Stolen Touches Neva Altaj Read Online Free
Gas Prices In Henderson Kentucky
Rise Meadville Reviews
Nacho Libre Baptized Gif
Bay Focus
Baywatch 2017 123Movies
Tinfoil Unable To Start Software 2022
[Teen Titans] Starfire In Heat - Chapter 1 - Umbrelloid - Teen Titans
How To Customise Mii QR Codes in Tomodachi Life?
Brown launches digital hub to expand community, career exploration for students, alumni
Senior Houses For Sale Near Me
Vagicaine Walgreens
Jimmy John's Near Me Open
Dayton Overdrive
Ajpw Sugar Glider Worth
Fine Taladorian Cheese Platter
Msatlantathickdream
Ciara Rose Scalia-Hirschman
King Fields Mortuary
Blippi Park Carlsbad
Latest Posts
Article information

Author: Kelle Weber

Last Updated:

Views: 6419

Rating: 4.2 / 5 (53 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Kelle Weber

Birthday: 2000-08-05

Address: 6796 Juan Square, Markfort, MN 58988

Phone: +8215934114615

Job: Hospitality Director

Hobby: tabletop games, Foreign language learning, Leather crafting, Horseback riding, Swimming, Knapping, Handball

Introduction: My name is Kelle Weber, I am a magnificent, enchanting, fair, joyous, light, determined, joyous person who loves writing and wants to share my knowledge and understanding with you.