cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <p>This pen explores the differences between using <code>border: 0</code>, <code>border: hidden</code> and <code>border: none</code>. It already includes a short explanation for each case, but please inspect the CSS to really understand what is happening.</p>

<p>Inspired by this Stack Overflow question: <a href="https://stackoverflow.com/questions/2922909/should-i-use-border-none-or-border-0/">Should I use 'border: none' or 'border: 0'?</a></p>

<h1>Common base style</h1>

<p>Each element in these test cases has the following base style: <code>border: 2px dotted blue;</code></p>

<p>This style is usually replaced by other styles defined in more specific rules, but we can still see it in some cases.</p>

<h1>Case 1 - simple divs</h1>

<p>Here, each <code>div</code> element has only two rules applied: the base rule (as described above) and the more specific rule (described inside each element).</p>

<p>Since the more specific rule either overrides the <code>border-style</code> or the <code>border-width</code>, the end effect is removing the borders from these elements. No surprises here.</p>

<section class="blocks">
  <div class="hidden">border: hidden;</div>
  <div class="zero">border: 0;</div>
  <div class="none">border: none;</div>
  <div class="stylehidden">border-style: hidden;</div>
  <div class="widthzero">border-width: 0;</div>
  <div class="stylenone">border-style: none;</div>
</section>

<h1>Case 2 - table context in collapsing border model</h1>

<p>The CSS 2.1 spec defines <a href="http://www.w3.org/TR/CSS21/tables.html#border-conflict-resolution">rules for resolving borders in a collapsing border model</a>. Essentially, <code>border-style: hidden</code> takes precedence over anything else, <code>border-style: none</code> has the lowest priority, and wider borders have higher priority over narrow borders.</p>

<p>In this case, the green dashed border of the table has higher priority than <code>none</code> or <code>0</code>, but lower priority than <code>hidden</code>.</p>

<table>
  <tr>
    <td class="hidden">border: hidden;</td>
    <td class="zero">border: 0;</td>
    <td class="none">border: none;</td>
  </tr>
  <tr>
    <td class="stylehidden">border-style: hidden;</td>
    <td class="widthzero">border-width: 0;</td>
    <td class="stylenone">border-style: none;</td>
  </tr>
</table>

<h1>Case 3 - divs with more specific <code>border-width</code></h1>

<p>In this section, a <code>border-width: 2px</code> rule has been applied to these <code>div</code> elements, using a selector with <a href="http://www.w3.org/TR/CSS2/cascade.html#specificity">higher specificity</a>.</p>

<p>When using the shortand <code>border: 0</code> property, both the <code>border-width</code> is set to <code>0</code> and the <code>border-style</code> is set to <code>none</code>. This means that, even if a more specific rule only changes the width, the style is still <code>none</code>, preventing the border from showing.</p>

<section class="inheritance width">
  <div class="hidden">border: hidden;</div>
  <div class="zero">border: 0;</div>
  <div class="none">border: none;</div>
  <div class="stylehidden">border-style: hidden;</div>
  <div class="widthzero">border-width: 0;</div>
  <div class="stylenone">border-style: none;</div>
</section>

<h1>Case 4 - divs with more specific <code>border-style</code></h1>

<p>In this section, a <code>border-style: dashed</code> rule has been applied to these <code>div</code> elements, using a selector with <a href="http://www.w3.org/TR/CSS2/cascade.html#specificity">higher specificity</a>.</p>

<p>The <a href="http://www.w3.org/TR/CSS21/box.html#border-width-properties">initial value for <code>border-width</code> is <code>medium</code></a> and the <a href="http://www.w3.org/TR/CSS21/box.html#border-color-properties">initial value for <code>border-color</code> is the same color as <code>color</code> property</a>. Whenever we override the <code>border-style</code> property, we can clearly see the medium border with the same color as the text.</p>

<section class="inheritance style">
  <div class="hidden">border: hidden;</div>
  <div class="zero">border: 0;</div>
  <div class="none">border: none;</div>
  <div class="stylehidden">border-style: hidden;</div>
  <div class="widthzero">border-width: 0;</div>
  <div class="stylenone">border-style: none;</div>
</section>

            
          
!
            
              div,
td {
  border: 2px dotted blue;
}
.hidden      { border: hidden; background: #FDD; }
.zero        { border: 0;      background: #DFD; }
.none        { border: none;   background: #DDF; }
.stylehidden { border-style: hidden; background: #FFD; }
.widthzero   { border-width: 0;      background: #DFF; }
.stylenone   { border-style: none;   background: #FDF; }

table {
  border-collapse: collapse;
  border: 2px dashed lime;
}
.inheritance.width > div {
  border-width: 2px;
}
.inheritance.style > div {
  border-style: dashed;
}

/* Styling/layout rules below, unrelated to the borders. */
html, body {
  font-family: Arial, "Liberation Sans", "DejaVu Sans", sans-serif;
  font-size: 14px;
  background: white;
  color: black;
}
.blocks,
table {
  margin: 1em 0;
}
.blocks > div,
.inheritance > div {
  display: inline-block;
  width: 30%;
  padding: 1ex;
  margin: 1ex;
  box-sizing: border-box;
}
table {
  margin-left: 1ex;
  margin-right: 1ex;
}
table td {
  width: 15%;
}
h1 {
  font-size: 1.5em;
  margin: 1em 0 0 0;
}
code {
  white-space: pre-wrap;
  background: #eee;
  padding: 1px 5px;
}
            
          
!
999px
Loading ..................

Console