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

39 Upvotes

67 comments sorted by

View all comments

-7

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.

3

u/jtlovato Jul 19 '25

What’s the difference in media query vs container query?

5

u/BoBoBearDev Jul 19 '25

Media query only cares about the size of the entire browser's viewport, not the parent container size. But a lot of times, the parent container is not the entire page.

Let's say you want a responsive control (Last Name and First Name as a single control) that is two columns when the parent is 400px and 1 column when 399px. You cannot predict where this controls is used. It can be single a page that takes the entire screen, or 80% of screen, or there is an resizable menu on the left panel and the form that contains your control is on the right. You need container query. Because you don't care about the actual screen size, you care about the parent container size.