agyanadda@gmail.com

CSS Borders

Styling Elements 1 min read Updated Dec 1, 2026 Topic 9 of 39

A border is a line around an element.

Border properties

  • border-style: solid, dashed, dotted, double, none
  • border-width: 2px, thin, thick
  • border-color: any colour

Shorthand

border: 2px solid #1f386b; (width, style, colour)

One side only

border-bottom: 3px dashed orange;

Rounded corners

border-radius: 10px; rounds the corners. border-radius: 50%; on a square makes a circle.

Note: a border is only visible when border-style is set.

Example

Example — Border styles and radius HTML
<style>
  div { padding: 12px; margin: 10px 0; }
  .solid { border: 2px solid #1f386b; }
  .dashed { border: 2px dashed tomato; }
  .rounded { border: 2px solid green; border-radius: 12px; }
  .circle { width: 80px; height: 80px; border: 4px solid purple; border-radius: 50%; }
</style>

<div class="solid">Solid border</div>
<div class="dashed">Dashed border</div>
<div class="rounded">Rounded corners</div>
<div class="circle"></div>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which property rounds the corners?

Exercise 2 True / False

A border shows even if border-style is not set.

Exercise 3 Fill in the Blank

border: 1px ___ red; draws a continuous line.

Frequently Asked Questions

By default yes — the border is added to the width. Use box-sizing: border-box to keep the set width.