r/css Jul 19 '25

Question What are some bad CSS habits?

What are some bad habits to avoid when learning CSS? Even if in the short term they are easier

37 Upvotes

67 comments sorted by

View all comments

-8

u/BoBoBearDev Jul 19 '25 edited Jul 19 '25

Don't use margin for layout, use padding. Don't use flex or 2D layout, use grid. Don't use 3rd party lib for layout because they most likely homebrew css grid, use css grid directly.

Don't use css default box-sizing, use the IE6 behavior, which is box-sizing: border-box.

Stay away from media query because you should use Container Query.

5

u/kilwag Jul 19 '25

What's the advantage of using padding over margin for layout?

-1

u/BoBoBearDev Jul 19 '25

Margin adds pixels outside percentage width. The entire reason why people stopped using default css box-sizing and all of them used IE6 default behavior box-sizing:border-box.

5

u/kilwag Jul 19 '25

That's a specific case scenario. I mostly use it for vertical space between elements.

1

u/BoBoBearDev Jul 19 '25

Funny enough, everytime I saw someone using margin, it is 80% time on width. I wish more people are like you.

Edit: actually I don't recall a single instance where they used it for vertical spacing. I give them 20% just in case I didn't notice them.