DEV Community

Discussion on: 8 SCSS Best Practices to Keep in Mind

Collapse
 
liaowow profile image
Annie Liao

Cool, thanks for the tip Joel! I was a bit surprised too when I saw that the guideline advised against using IDs. I have been quite cautious about using !important statements though.

Collapse
 
joelbonetr profile image
JoelBonetR πŸ₯‡

Some points on guides around here have their reasons that may not fit into your project or needs. Remember that html and css (or sass/scss) are not programming languages so there's no much point on getting "best practices" or "do this instead of that". They simply work or not, this tips are about increasing performance, readability or scalability.
With this in mind, there's tones of opinionated articles that didn't tested or benchmarked anything about the content, always test this tips by yourself 😁 assomeone else may go for performance and you want scalability or vice versa (some tips are contradictory depending on the tarjet), get that ones which fits best for you πŸ˜†

Thread Thread
 
gilfewster profile image
Gil Fewster

CSS is a programming language.

But even it it wasn’t, why would you say there’s no point in teams or developers formulating lists of best practice which are most suited to their needs?

Thread Thread
 
joelbonetr profile image
JoelBonetR πŸ₯‡

CSS is NOT a programming language. CSS is a design language to define how HTML (which is a markup language and in fact, not a programming language) elements should be displayed.

Dev teams can of course define a list of best practices for a given project (not a generic one for all projects) depending on the goal they want to achieve. That's performance, accessibility, readability, compatibility (with old browsers) or scalability, or a mix of some or all of them. But you'll find some points where doing something could benefit a target and harm another.

For example, using multiple isolated classes can definitely benefit readability and scalability but can harm compatibility with old browsers ( I.E. 6 and older wasn't good managing multiple classes on a single html element).

So if you are into a project where you need compatibility, you must take the decision on doing one or another, you can't keep it all. That's why there's no much point on defining some things as "css best practices" globally or generically.

I wrote an article of css best practices by myself some weeks ago that you can check here:
dev.to/joelbonetr/css-and-scss-bes...
where I tried to explain what I do and why I do this, so you can discern if it fits into your code or not.

I'm not giving compatibility to old browsers because the users of my client's sites that use old browsers are less than 0,05%. I don't care much about accessibility on standard projects (clients usually does not want to pay the extra analysis and development for it) so I usually go for performance and scalability to make the modifications faster (and cheaper) to us, and getting better SEO due to mobile friendly and site low weight.

After all, everyone has to check all best practices, understand the details of every statement and check if each one can fit into their needs or not for a given project.

Thread Thread
 
gilfewster profile image
Gil Fewster

Why is CSS not a programming language?

Thread Thread
 
joelbonetr profile image
JoelBonetR πŸ₯‡ • Edited

HTML and CSS are not programming languages because HTML and CSS are not generally β€œexecuted” by a computer. They are parsed by an engine, and then algorithms stored in a renderer determine execution tasks.

When you write <h1>foo</h1> , you’re not programming that element. You are denoting a piece of data. You haven’t β€œinstructed” the browser to execute a task.

Likewise with CSS, anyone who’s written it for longer than 5 minutes knows that even something as simple as float: left; may not do that just because you asked. The browser will parse your instruction, and follow a set of algorithms over which you have no control to determine if and how something floats.

By the way you can't do anything different from a static webpage with HTML and CSS only, so that's not too different to what you can achieve using photoshop or microsoft word (you'll get a static content as result).

*Static meaning you can not interact with this view for store, modify or delete anything; no login, no user profile, no custom theme, no personal data... You can only read (view) the result "as is".

Thread Thread
 
gilfewster profile image
Gil Fewster

CSS may not be executed directly, but it directly affects those algorithmically determined execution tasks. CSS is used to instruct, direct or modify the application's output.

You can certainly modify content with just HTML and CSS. CSS also has functions, variables, mathematical functions and boolean logic.

We can get pedantic about strict definitions of execution, runtime interpreters and the like if you wish, but why quibble?

Thread Thread
 
joelbonetr profile image
JoelBonetR πŸ₯‡ • Edited

That's not a matter of discussion usually. You can not code an application using plain CSS, you cannot add functionality, only describe how the information is painted and styled πŸ€·πŸ»β€β™€οΈ
If you add enough features on CSS (server calls and handling of responses for example) it can become a programming language but you already have JavaScript for that tasks, which is a programming language.