CSS Border
Home Learning Path LAMP HTML/CSS PHP MySQL JavaScript YouTube Blog PHP Fiddle

Intro to CSS: Borders

Quick Copy Boxes



CSS allows you to create custom borders for your content.

At the bottom of this page there is a code editor pre-loaded with the lesson's code.

This heading, and the image below it, are placed in a bordered container.

Border-style

The first step in making a border is to pick a border-style.

Here are possible values for border-style:
 ✶dotted
 ✶dashed
 ✶solid
 ✶double
 ✶groove
 ✶ridge
 ✶inset
 ✶outset
 ✶none
 ✶hidden
 ✶mix

)

.withBorder {
   border-style: solid;
}

withBorder - This is our CSS class name.
border-style - It will have a solid line border.

HTML


  <div class = 'withBorder'>
    <h3>This heading, and the image below it, are placed in a bordered container.</h3>
    <img width = '200px;' src = '../logo.png'>
  </div>
   

Border-width

Next, we will decide how thick we want our border-line.


   .withBorder {
      border-style: solid;
      border-width: 4px;
   }
   

withBorder - This is our CSS class name.
border-style - It will have a solid line border.
border-width - Our border has a width of 4px.

HTML


     <div class = 'withBorder'>
       <h3>This heading, and the image below it, are placed in a bordered container.</h3>
       <img width = '200px;' src = '../logo.png'>
     </div>
      

Border-color

Finally we will pick a color.


 .withBorder {
    border-style: solid;
    border-width: 4px;
    border-color: red;
 }
 

withBorder - This is our CSS class name.
border-style - It will have a solid line border.
border-width - Our border has a width of 4px.
border-color - It is red.

HTML


   <div class = 'withBorder'>
     <h3>This heading, and the image below it, are placed in a bordered container.</h3>
     <img width = '200px;' src = '../logo.png'>
   </div>
    

Border by Side

Sometimes you may not want the same border on each side.


  .someBorder {
     border-top-style: dashed;
     border-right-style: none;
     border-bottom-style: dashed;
     border-left-style: none;
  }
  

someBorder - This is our CSS class name.
top - The top of the element will have a dashed line.
right - The right side of the element has no border
bottom - The bottom of the element will have a dashed line.
left - The left side of the element has no border.

HTML


    <div class = 'someBorder'>
      <h3>This container has a border above and below it.</h3>
      <img width = '200px;' src = '../logo.png'>
    </div>
     

This container has a border above and below it.


Color Selector



Hex:


RBG:

Play with the code in the code editor below. Don't forget to check-out the CSS tab. Also, continue working on the ad you started in CSS Color lesson.