<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jesse de Bruijne</title>
    <description>The latest articles on DEV Community by Jesse de Bruijne (@jessedebruijne).</description>
    <link>https://dev.to/jessedebruijne</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F260377%2Ffdd0203e-469e-4fd6-ba6e-92fa2eccbd4a.jpeg</url>
      <title>DEV Community: Jesse de Bruijne</title>
      <link>https://dev.to/jessedebruijne</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jessedebruijne"/>
    <language>en</language>
    <item>
      <title>How to choose the right CSS properties</title>
      <dc:creator>Jesse de Bruijne</dc:creator>
      <pubDate>Wed, 05 Jan 2022 15:10:16 +0000</pubDate>
      <link>https://dev.to/jessedebruijne/how-to-choose-the-right-css-properties-48ca</link>
      <guid>https://dev.to/jessedebruijne/how-to-choose-the-right-css-properties-48ca</guid>
      <description>&lt;p&gt;CSS might seem very daunting. There are many properties to choose from, and it may sometimes look like it's not doing what you tell it to. Or, sometimes you find yourself thinking: "There is more than one way to do this in CSS". In this blog post I'll cover some of these scenarios, and help you understand how you can justify your CSS decisions.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Edge cases
&lt;/h2&gt;

&lt;p&gt;In my opinion, the most important reasoning behind your CSS usage. If you find yourself in a situation where you have multiple CSS solutions, this should be your first thought. Think of scenarios that might not be included in the design, and how your CSS would react to those. Examples of edge cases include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What if the text in this element becomes very long?&lt;/li&gt;
&lt;li&gt;What if the user uses a smaller device?&lt;/li&gt;
&lt;li&gt;What if the user zooms in using the browser zoom?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's take for example: how to center a div.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"example"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"number"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;1&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.example&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;magenta&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;.example&lt;/code&gt; element is a magenta circle of 40x40. Say we want to place this &lt;code&gt;1&lt;/code&gt; exactly in the middle of the &lt;code&gt;.example&lt;/code&gt; div. You &lt;em&gt;could&lt;/em&gt; do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.example&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;11px&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which works, and looks like this:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/Essej2/embed/WNZyGvq?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Looks perfect! But now watch what happens if it's not 1, but 11 as a number:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/Essej2/embed/NWazRxV?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Now the text is not centered in the div anymore! A different approach like Flexbox might be your preferred solution then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.example&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/Essej2/embed/zYEaKBN?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Thinking outside of the box can help a great deal in deciding which CSS solution is the right fit, because it actually eliminates "wrong" solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Browser support
&lt;/h2&gt;

&lt;p&gt;The never-ending struggle of the front-end developer. Browsers all have their unique quirks and features! Or as we developers call them, bugs and inconsistencies. Taking browser support into account can be a deciding factor on which CSS properties to use. The main browsers to take into account are &lt;strong&gt;Safari&lt;/strong&gt; and, to a lesser extent, &lt;strong&gt;Internet Explorer 11&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;
  If you want to know more about why these browsers specifically, click here
  &lt;br&gt;
Safari has a very different approach to development compared to Edge, Chrome or Firefox. They only release new versions every 6 months, and so bugs are always there for at least 6 months. &lt;a href="https://httptoolkit.tech/blog/safari-is-killing-the-web/"&gt;To read a more extensive rant on Safari, I can recommend this article.&lt;/a&gt;

&lt;p&gt;&lt;a href="https://blogs.windows.com/windowsexperience/2021/05/19/the-future-of-internet-explorer-on-windows-10-is-in-microsoft-edge/"&gt;Internet Explorer 11 is reaching its end of life very soon&lt;/a&gt;, and the whole development world will breathe a sigh of relief when it does. The browser has been ridiculously outdated for a while now, and new awesome features like CSS Grid, or Flexbox, were either not implemented at all, or implemented in their own way. This resulted in many inconsistencies when comparing your page in IE11 to for example Google Chrome.&lt;br&gt;
&lt;/p&gt;

&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;For example, let's say you want to change the opacity of an element. You could use either of these two lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first way, using &lt;code&gt;filter&lt;/code&gt;, actually performs better because browsers can use hardware acceleration. However, &lt;a href="https://caniuse.com/css-filters"&gt;it's not supported in IE11&lt;/a&gt;. So, if your users use IE11, you might want to avoid using &lt;code&gt;filter&lt;/code&gt;. Alternatively, some browsers offer compatibility through the use of &lt;em&gt;prefixes&lt;/em&gt; like &lt;code&gt;-webkit-animation&lt;/code&gt; instead of &lt;code&gt;animation&lt;/code&gt;. Many projects these days use a form of &lt;a href="https://github.com/postcss/autoprefixer"&gt;Autoprefixer&lt;/a&gt; to automatically do this for you.&lt;/p&gt;

&lt;p&gt;Whenever you're in doubt about what CSS to use, you could check which approach works best in all browsers. Test your solution in Safari or Internet Explorer, or use &lt;a href="https://caniuse.com/"&gt;Caniuse&lt;/a&gt; to check if something is supported in all (or enough) browsers. If there is a clear difference, you'll have your answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Maintainability
&lt;/h2&gt;

&lt;p&gt;From this point the reasoning becomes more subjective, and so I've stopped numbering them. Whatever floats your boat more.&lt;/p&gt;

&lt;p&gt;What if someone has to come back to your HTML/CSS and made some adjustments? Will that person be able to understand what's going on in the ruleset? Can they easily amend some of the HTML without the rules becoming invalid? Keep in mind, this person could be you! Think of the future when you write your CSS.&lt;/p&gt;

&lt;p&gt;For example, let's say your HTML structure looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;nav&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Options&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want your options button to be aligned to the right within the nav, you could achieve that like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;nav&lt;/span&gt;&lt;span class="nd"&gt;:first-child&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
  &lt;span class="nl"&gt;margin-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that would be completely fine! For now. If a developer comes back to this after a month or two and makes a slight tweak to the HTML, this CSS will not work anymore. &lt;br&gt;
Here's some HTML tweaking examples that break this CSS rule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;nav&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Blogs&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- Now this element is targeted --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Options&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;nav&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- This is now the first child, and it has no sibling --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Options&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;nav&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"company-logo"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"..."&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- Now this element is targeted --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Options&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Furthermore, it is not very easy to read. Instead, you could do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;nav&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"home-button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"options-button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Options&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;nav&lt;/span&gt; &lt;span class="nc"&gt;.options-button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
  &lt;span class="nl"&gt;margin-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This CSS is much clearer to read (the &lt;code&gt;.options-button&lt;/code&gt; in the &lt;code&gt;nav&lt;/code&gt; should have space to the left). It is also unaffected if for example a wrapper &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; is added around the buttons, or if more menu items are added before it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Semantics
&lt;/h2&gt;

&lt;p&gt;This is in my opinion the best way to settle 50/50 questions like: should I use &lt;code&gt;padding&lt;/code&gt; or &lt;code&gt;margin&lt;/code&gt;? Should the top element have &lt;code&gt;margin-bottom&lt;/code&gt; or should the bottom element have &lt;code&gt;margin-top&lt;/code&gt;? Let me explain what I mean.&lt;/p&gt;

&lt;p&gt;Let's take as an example a button containing some text.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"example-button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;Click me!&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You could use either of these rulesets to achieve the same effect:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.example-button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.example-button&lt;/span&gt; &lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/Essej2/embed/mdBKrrG?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;But which of these rules make more sense? Is it more logical that the button should always have 10px of breathing room on the inside, or that the div inside the button always has 10px of breathing room on the outside?&lt;/p&gt;

&lt;p&gt;A trick I like to use here is: &lt;em&gt;try to imagine there's another element in the equation&lt;/em&gt;. In this case, maybe the button has an icon before the text. In that case, is it more important that the button has the padding, or that the text has the margin? Then it seems more logical that the button should have padding.&lt;/p&gt;

&lt;p&gt;Let's look at another example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h2&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"example-header"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Beautiful header&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"example-text"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Lovely bit of text&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's say we want to add 20px of space between these elements. Do you give the &lt;code&gt;.example-header&lt;/code&gt; a &lt;code&gt;margin-bottom&lt;/code&gt;? Or the &lt;code&gt;.example-text&lt;/code&gt; a &lt;code&gt;margin-top&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;If we apply the same trick as before, we can for example imagine another paragraph before &lt;code&gt;.example-text&lt;/code&gt;. Would you want the 20px space to be between the two paragraphs, or between the header and the first paragraph? By looking at it this way it makes more sense to add the margin on the bottom of the header.&lt;/p&gt;

&lt;h2&gt;
  
  
  Less is more
&lt;/h2&gt;

&lt;p&gt;Performance is important. Longer CSS means more bytes. More bytes means longer loading time. It's not the reasoning I use often, since the differences are often minimal and not as impactful as reducing your JavaScript code, but it's a valid reason to write &lt;code&gt;margin: 0 3px 6px 1px;&lt;/code&gt; instead of spelling out each individual property.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I hope this post will help you either make a decision on which CSS properties to use, or justify a decision that you've already made. I now leave it up to you to put these in your personal order of importance. Personally, I love semantics and I find myself often basing my CSS decisions on that rule, after checking for edge cases or browser support. However, I know preferences differ and I want everybody to write their CSS the way they want to. Just, keep this in the back of your mind 😉.&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>design</category>
    </item>
  </channel>
</rss>
