CSS Borders

Border style, width, colour and radius.

✍️ 3 exercises + code challenge in this lesson

The border property draws a line around an element. It combines three values:

border: 2px solid #2563EB; → width, style, colour.

Border styles

solid, dashed, dotted, double, groove, ridge, inset, outset, none.

Individual sides and rounded corners

  • border-top, border-right, border-bottom, border-left
  • border-radius rounds the corners; 50% on a square makes a circle.

Key Takeaways: CSS Borders

Mastering CSS Borders helps you write clean and reliable CSS code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

CSS Borders Code Example

CSS
<style>
  p { padding: 10px; margin: 10px 0; }
  .solid  { border: 3px solid #2563EB; }
  .dashed { border: 3px dashed #14B8A6; }
  .dotted { border: 3px dotted #E34F26; }
  .left   { border-left: 8px solid #EAB308; background: #FEFCE8; }
  .round  { border: 2px solid #071A2F; border-radius: 16px; }
  .circle { width: 80px; height: 80px; border-radius: 50%; background: #2563EB; }
</style>

<p class="solid">Solid border</p>
<p class="dashed">Dashed border</p>
<p class="dotted">Dotted border</p>
<p class="left">Only a left border</p>
<p class="round">Rounded corners</p>
<div class="circle"></div>
Free sign-in required · Google login available

CSS Borders Practice Exercises

Check what you learned in “CSS Borders”.

/ 3 solved
Fill in the blank

Add a 2px solid black border.

div {
  border:   black;
}
✓ Correct! Not quite. Try again.
Multiple choice

Which property rounds the corners of an element?

✓ Correct! Not quite. Try again.
Code challenge

Give the box a 3px dashed border and 10px rounded corners.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services