Margin considered harmful

Max Stoiber:

We should ban margin from our components. Hear me out.

By banning margin from all components you have to build more reusable and encapsulated components.

I think the message is a bit more nuanced though: margins of course still are allowed and used throughout your CSS, but if you want to allow a developer to tweak the spacing used inside your component provide a prop to let them do so.

However, don’t let them set a direct size (e.g. 1em), but give them several options to choose from. Think of Tailwind’s .m-0, .m-1, .m-2, etc. to tweak the margin itself, or Bootstrap’s .btn-sm and .btn-lg to make buttons small or big.

Margin considered harmful →

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.