Cover image for My 5 Practical CSS Tips

My 5 Practical CSS Tips

idoshamun profile image Ido Shamun Originally published at daily.dev ・2 min read

This is going to be a short post with my best CSS tips. I'll do my best to share references for every tip so you can read more and get a better understanding.


When you use pixels, you ignore the user's browser settings and break your website accessibility. If the user chooses to change its default font-size, by using pixels you override this setting. Enter rem! rem is a CSS unit to set an property relative to the HTML root font-size (16px by default). Using rem makes your site responsive to font-size changes and aligned to the user's settings.



Nesting is still not an official CSS feature (it's in discussion) but already very common. It's available in frameworks such as PostCSS, and Sass.
By utilizing nested selectors, you improve the readability and maintainability of your CSS code. It eliminates the need to duplicate classes, ids, and selectors all around.



content-visibility is a new CSS property that boosts your rendering performance. You can tell your browser to lazy render an element. The browser will skip the rendering which includes both layout and painting until it's necessary. You can set content-visibility: auto on any below the fold elements for an immediate performance boost.


Using padding-top to keep aspect ratio

It might be surprising by padding in percentages is calculated based on the parent element's width. Yes, yes, even padding-top and padding-bottom. This is super weird by it's handy if you want to keep an aspect ratio. Why? For example when using images. It's a best practice to set the size of an element that is dependent on a large payload, such as an image. It prevents annoying changes in layout and makes it easier to design responsive components.


Use a framework

PostCSS (my favorite), Sass, no matter what just use one. They usually have a built-in prefixer to add browser compatibility at build-time. And they have plugins that will make CSS development a bit easier.


Daily delivers the best programming news every new tab. We will rank hundreds of qualified sources for you so that you can hack the future.

Daily Poster

Posted on by:

idoshamun profile

Ido Shamun


Co-Founder of daily.dev and a passionate software developer


Editor guide

Using padding-top to keep aspect ratio

This is a glorious tip, but since you've mentioned the quite recent content-visibility, also aspect-ratio is very recent (support in Chrome 79 and Firefox 71). If only we had that in, like, 2003...

Use a framework

I wouldn't call PostCSS and SASS "frameworks". I'd say they're more like "processors", "compilers" or something like that. They allow you to use syntaxes that aren't in CSS, basically superpowering the language.
I'd call Bootstrap a CSS framework. Let me know if you agree.


You're right about aspect-ratio, no doubt. I'm just so used to padding-top but aspect-ratio is another way to achieve the same thing.

I agree processors are much a better wording for them. Thanks for clarifying.


Damn, I didn't even know that content-visibility exists.


Now you do! Enjoy ✨


Content-visibility is so promising, need to actually start testing it out.


Yes, it's one of the most hyped CSS properties right now πŸ¦„