Pen Settings

HTML

CSS

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.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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.

+ add another resource

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>CSS Borders</h1>
<h2>CSS Border Properties</h2>
<p>The CSS <span>border</span> properties allow you to specify the style, width and color of an element's border.

<h2>Border Style</h2>

<p>The <span>border-style</span> property specifies what kind of border to display.</p>

<p>The following values are allowed:</p>
<ul>
  <li><span>dotted</span> - Defines a dotted border</li>
  <li><span>dashed</span> - Defines a dashed border</li>
  <li><span>solid</span> - Defines a solid border</li>
  <li><span>double</span> - Defines a double border</li>
  <li><span>groove</span> - Defines a 3D grooved border. The effect depends on the border-color value</li>
<li><span>ridge</span> - Defines a 3D ridged border. The effect depends on the border-color value
  <li><span>inset</span> - Defines a 3D inset border. The effect depends on the border-color value</li>
  <li><span>outset</span> - Defines a 3D outset border. The effect depends on the border-color value</li>
  <li><span>none</span> - Defines no border</li>
  <li><span>hidden</span> - Defines a hidden border</li>
</ul>

<p>The <span>border-style</span> property can have from one to four values (for the top border, right border, bottom border, and the left border).</p>
<div>
  <h2>Example</h2>

  <p class="dotted">p.dotted {border-style: dotted;}</p>
  <p class="dashed">p.dashed {border-style: dashed;}</p>
  <p class="solid">p.solid {border-style: solid;}</p>
  <p class="double">p.double {border-style: double;}</p>
  <p class="groove">p.groove {border-style: groove;}</p>
  <p class="ridge">p.ridge {border-style: ridge;}</p>
  <p class="inset">p.inset {border-style: inset;}</p>
  <p class="outset">p.outset {border-style: outset;}</p>
  <p class="none">p.none {border-style: none;}</p>
  <p class="hidden">p.hidden {border-style: hidden;}</p>
  <p class="mix">p.mix {border-style: dotted dashed solid double;}</p>
</div>

<h2>Border Width</h2>

<p>The <span>border-width</span> property specifies the width of the four borders.</p>

<p>The width can be set as a specific size (in px, pt, cm, em, etc) or by using one of the three pre-defined values: thin, medium, or thick.</p>

<p>The <span>border-width</span> property can have from one to four values (for the top border, right border, bottom border, and the left border).</p>

<div>
  <h2>Example</h2>
  <p class="one">
    p.one {
        border-style: solid;
        border-width: 5px;
    }
  </p>
  <p class="two">
    p.two {
        border-style: solid;
        border-width: medium;
    }
  </p>
   <p class="three">
      p.three {
          border-style: solid;
          border-width: 2px 10px 4px 20px;
      }
   </p>
</div>

<h2>Border Color</h2>

<p>The <span>border-color</span> property is used to set the color of the four borders.</p>

<p>The color can be set by:</p>
<ul>
  <li>name - specify a color name, like "red"</li>
  <li>Hex - specify a hex value, like "#ff0000"</li>
  <li>RGB - specify a RGB value, like "rgb(255,0,0)"</li>
  <li>transparent</li>
</ul>

<p>The <span>border-color</span> property can have from one to four values (for the top border, right border, bottom border, and the left border).</p>

<p>If <span>border-color</span> is not set, it inherits the color of the element.</p>

<div>
  <h3>Example</h3>
  <p class="one-color">
    p.one-color {
        border-style: solid;
        border-color: red;
    }
  </p>
  <p class="two-color">
    p.two-color {
        border-style: solid;
        border-color: green;
    }
  </p>
  <p class="three-color">
    p.three-color {
        border-style: solid;
        border-color: red green blue yellow;
    }
  </p>
</div>

<h2>Border - Individual Sides</h2>

<p>From the examples above you have seen that it is possible to specify a different border for each side.</p>

<p>In CSS, there is also properties for specifying each of the borders (top, right, bottom, and left):</p>

<div>
  <h3>Example</h3>
  <p class="individual-sides">
    p.individual-sides {
        border-top-style: dotted;
        border-right-style: solid;
        border-bottom-style: dotted;
        border-left-style: solid;
    }
  </p>
</div>

<p>So, here is how it works:</p>

<p>If the <span>border-style</span> property has four values:</p>
  <ul>
    <li><strong>border-style: dotted solid double dashed;</strong></li>
      <ul>
        <li>top border is dotted</li>
        <li>right border is solid</li>
        <li>bottom border is double</li>
        <li>left border is dashed</li>
      </ul>
  </ul>
<p>If the <span>border-style</span> property has three values:</p>

<strong>border-style: dotted solid double;</strong>
top border is dotted
right and left borders are solid
bottom border is double
<p>If the <span>border-style</span> property has two values:</p>
<strong>border-style: dotted solid;</strong>
top and bottom borders are dotted
right and left borders are solid
<p>If the <span>border-style</span> property has one value:</p>
<strong>border-style: dotted;</strong>
all four borders are dotted
<ul>
<p>The <span>border-style</span> property is used in the example above. However, it also works with <span>border-width</span> and <span>border-color.</span></p>
  <li>top and bottom borders are dotted</li>
    <li>right and left borders are solid</li>
  </ul>
</ul>

<p>If the <span>border-style</span> property has one value:</p>
<ul>
  <li><strong>border-style: dotted;</strong></li>
  <ul>
    <li>all four borders are dotted</li>
  </ul>
</ul>

<p>The <span>border-style</span> property is used in the example above. However, it also works with <span>border-width</span> and <span>border-color.</span></p>

<h2>Border - Shorthand Property</h2>
<p>As you can see from the examples above, there are many properties to consider when dealing with borders.</p>

<p>To shorten the code, it is also possible to specify all the individual border 
  properties in one property.</p>

<p>The <span>border</span> property is a shorthand property for the following individual border</p>

<p>properties:</p>
<ul>
  <li>border-width</li>
  <li>border-style (required)</li>
  <li>border-color</li>
</ul>

<div>
  <h3>Example</h3>
  <p class="short-hand">
    p.short-hand {
        border: 5px solid red;
    }
  </p>
</div>

<h2>Rounded Borders</h2>
<p>The <span>border-radius</span> property is used to add rounded borders to an element:</p>

<div>
  <h3>Example</h3>
  <p class="radius-5px">
    p.radius-5px {
        border: 2px solid red;
        border-radius: 5px;
    }
  </p>
  <p class="radius-10px">
    p.radius-10px {
        border: 2px solid red;
        border-radius: 10px;
    }
  </p>
  <p class="radius-20px">
    p.radius-20px {
        border: 2px solid red;
        border-radius: 20px;
    }
  </p>
              
            
!

CSS

              
                span {
  color: red;
}

p.dotted {border-style: dotted;}
p.dashed {border-style: dashed;}
p.solid {border-style: solid;}
p.double {border-style: double;}
p.groove {border-style: groove;}
p.ridge {border-style: ridge;}
p.inset {border-style: inset;}
p.outset {border-style: outset;}
p.none {border-style: none;}
p.hidden {border-style: hidden;}
p.mix {border-style: dotted dashed solid double;}

div {
  border-left: green 3px solid;
  padding: 20px 20px 20px 20px;
  background-color: lightgrey;
}

p.one {
    border-style: solid;
    border-width: 5px;
}

p.two {
    border-style: solid;
    border-width: medium;
}

p.three {
    border-style: solid;
    border-width: 2px 10px 4px 20px;
}

p.one-color {
    border-style: solid;
    border-color: red;
}

p.two-color {
    border-style: solid;
    border-color: green;
}

p.three-color {
    border-style: solid;
    border-color: red green blue yellow;
}

p.individual-sides { border-top-style: dotted; border-right-style: solid; border-bottom-style: dotted; border-left-style: solid; 
}

p.short-hand {
    border: 5px solid red;
}

p.radius-5px {
    border: 2px solid red;
    border-radius: 5px;
}


p.radius-10px {
    border: 2px solid red;
    border-radius: 10px;
}


p.radius-20px {
    border: 2px solid red;
    border-radius: 20px;
}
              
            
!

JS

              
                
              
            
!
999px

Console