Tutorials CSS Border
Ch 13 / 60
Chapter 13 Beginner 7 min read CSS

CSS Border

Borders are the visible edge of every element — and in CSS they are far more powerful than a simple line. With border styles, radius, individual sides and gradient borders, you can build beautiful UI components without a single image.

What you'll learn
The three sub-properties: border-width, border-style, border-color
All 9 border styles with live demos
The border shorthand
Individual side borders — border-top, border-bottom, etc.
border-radius — circles, pills, and custom shapes
Creative border effects — gradients, accents, double borders

What is a CSS Border?

A border is a line drawn around an element's padding (and content). It sits between the padding and the margin in the CSS Box Model. A border has three characteristics that you must define for it to be visible:

border-width
How thick the border line is. Accepts any CSS length (px, rem, em) or keyword: thin, medium, thick.
border-style ← required!
The visual pattern of the line. This is the only required property. Without a style, the border is invisible regardless of width and color.
border-color
The colour of the border. Defaults to the element's color (text colour) if not set. Accepts any CSS colour value.
CSS — three sub-properties
.box {
  border-width: 2px;
  border-style: solid;   /* ← required for border to appear */
  border-color: #264de4;
}

/* Without border-style, no border renders */
.invisible {
  border-width: 5px;
  border-color: red;
  /* No border-style → nothing visible */
}

/* border-color defaults to the element's text color */
.inherits-color {
  color:        #264de4;
  border:       2px solid; /* border is also blue */
}

Border Styles — All 9 Values

CSS supports 9 named border style values. solid is by far the most common in real projects, but the others are useful for specific design effects:

solid
solid
dashed
dashed
dotted
dotted
double
double
groove
groove
ridge
ridge
inset
inset
outset
outset
no border
none
CSS — border-style values
.solid  { border-style: solid; }    /* continuous line — most common */
.dashed { border-style: dashed; }   /* dashes — upload areas, dividers */
.dotted { border-style: dotted; }   /* dots */
.double { border-style: double; }   /* two lines — needs width ≥ 3px */
.groove { border-style: groove; }   /* 3D carved-in look */
.ridge  { border-style: ridge; }    /* 3D raised look */
.inset  { border-style: inset; }    /* sunken into page */
.outset { border-style: outset; }   /* popping out of page */
.none   { border-style: none; }    /* no border (default) */
.hidden { border-style: hidden; }  /* same as none but for table border conflicts */

/* Mix styles on different sides */
.mixed {
  border-style: solid dashed dotted double;
  /*             top   right  bottom  left */
}

The border Shorthand

The border shorthand combines all three sub-properties in one declaration. The order is: width → style → color. All three values are optional except style — but you should always include all three for clarity.

CSS — border shorthand
/* border: width style color */
.card     { border: 1px solid #e5e7eb; }
.btn      { border: 2px solid #264de4; }
.error    { border: 2px solid #ef4444; }
.dashed   { border: 2px dashed #264de4; }
.success  { border: 2px solid #22c55e; }

/* Remove border */
.no-border{ border: none; }
button    { border: 0; } /* also removes border */

/* Using CSS keywords for width */
.thin     { border: thin solid #264de4; }   /* ~1px */
.medium   { border: medium solid #264de4; } /* ~3px */
.thick    { border: thick solid #264de4; }  /* ~5px */

/* Using currentColor — matches text color */
.icon-btn {
  color:  #264de4;
  border: 2px solid currentColor; /* border matches text */
}

Individual Side Borders

You can set borders on specific sides only using the four individual shorthand properties: border-top, border-right, border-bottom, border-left. Each accepts the same width style color format.

border-top only
border-top: 3px solid
border-bottom only
border-bottom: 3px solid
border-left accent
border-left: 4px solid
border-right accent
border-right: 4px solid
top + bottom only
border-top + border-bottom
left + right dashed
border-left + border-right
CSS — Individual side borders
/* Individual shorthand — width style color */
.top-only  { border-top:    2px solid #264de4; }
.bottom    { border-bottom: 1px solid #e5e7eb; }
.left-bar  { border-left:   4px solid #264de4; } /* card accent */

/* Individual sub-properties per side */
.custom {
  border-top-width:  3px;
  border-top-style:  solid;
  border-top-color:  #264de4;

  border-right-width: 0;  /* no right border */
  border-right-style: none;
}

/* Common pattern: reset then add specific side */
.underline {
  border:        none;            /* clear all */
  border-bottom: 2px solid #264de4; /* add bottom only */
}

/* Width shorthand accepts 1–4 values (same as padding/margin) */
.mixed-width {
  border-style: solid;
  border-width: 4px 1px 4px 1px; /* top right bottom left */
  border-color: #264de4;
}
Left accent pattern
border-left: 4px solid #264de4 is one of the most used patterns in UI design — it creates a coloured left accent bar on cards, blockquotes, alerts and sidebar menu items. Always pair it with a small padding-left to indent the content away from the bar.

border-radius — Rounded Corners

border-radius rounds the corners of an element. It works whether or not a visible border exists — it also clips the background colour and any child overflow to the rounded shape.

0
Square
border-radius: 0
4px
Subtle
border-radius: 4px
8px
Card
border-radius: 8px
16px
Soft
border-radius: 16px
pill
Pill
border-radius: 999px
50%
Circle
border-radius: 50%
CSS — border-radius
/* Single value — all four corners */
.card     { border-radius: 12px; }
.btn      { border-radius: 8px; }
.pill     { border-radius: 999px; }  /* fully rounded ends */
.circle   { border-radius: 50%; }   /* circle when width = height */

/* Two values — top-left&bottom-right | top-right&bottom-left */
.diagonal { border-radius: 12px 4px; }

/* Four values — TL TR BR BL (clockwise from top-left) */
.custom   { border-radius: 12px 4px 12px 4px; }

/* Individual corners */
.modal {
  border-radius:              16px;          /* all corners */
  border-bottom-left-radius:  0;
  border-bottom-right-radius: 0;             /* flat bottom */
}

/* Elliptical radius — horizontal / vertical */
.leaf { border-radius: 60% 40% 60% 40% / 40% 60% 40% 60%; }

Advanced Shapes with border-radius

By setting individual corner radii with different values — and using the elliptical horizontal/vertical syntax — you can create organic shapes without any SVG or images:

Circle
border-radius: 50%
Arch / Tab
999px 999px 0 0
Leaf
elliptical / syntax
Half-pill
0 50% 50% 0 / 50%
Dome
50% 50% 0 0
Blob
uneven elliptical

Creative Border Effects

CSS borders can do far more than a simple line. Here are the most useful creative effects — all pure CSS, no images:

Gradient border
Gradient border via pseudo-element
Top accent bar
Top accent — headers, section starts
Left accent bar
Left accent — cards, blockquotes, alerts
Dashed border
Dashed — drag zones, placeholders
Double border
Double — decorative frames
Inner + outer (outline)
border + outline together
Bottom gradient line
border-image gradient underline
Inset 3D
border-style: inset
CSS — Creative border effects
/* ── Gradient border using pseudo-element ── */
.gradient-border {
  border:     3px solid transparent;
  background-clip: padding-box;
  position:  relative;
}
.gradient-border::before {
  content:    '';
  position:  absolute;
  inset:      -3px; /* matches border-width */
  border-radius: inherit;
  background: linear-gradient(135deg, #264de4, #a855f7);
  z-index:    -1;
}

/* ── Top accent card ── */
.accent-card {
  border:    1px solid #e5e7eb;
  border-top:3px solid #264de4; /* accent overrides top */
  border-radius: 8px;
}

/* ── Left accent blockquote ── */
blockquote {
  border:         none;
  border-left:    4px solid #264de4;
  padding-left:   16px;
  font-style:     italic;
}

/* ── border-image gradient underline ── */
.gradient-line {
  border-bottom: 3px solid transparent;
  border-image:  linear-gradient(90deg, #264de4, #a855f7) 1;
}

/* ── Double border with outline ── */
.double-ring {
  border:         2px solid #264de4;
  outline:        2px solid #264de4;
  outline-offset: 4px; /* gap between border and outline */
}

border-image

border-image replaces the standard border colour with a gradient or image that is sliced and applied to each border segment. It is the only CSS-native way to have a true gradient border without a pseudo-element hack.

CSS — border-image
/* border-image: source slice / width / outset repeat */

/* Gradient border — requires border-style to be set */
.gradient-border {
  border:       3px solid transparent;
  border-image: linear-gradient(135deg, #264de4, #a855f7) 1;
  /* The '1' at the end = slice value (fill the border area) */
}

/* Gradient bottom line only */
h2 {
  border-bottom: 3px solid;
  border-image:  linear-gradient(90deg, #264de4, transparent) 1;
}

/* Note: border-image does NOT work with border-radius!   */
/* For rounded gradient borders use the pseudo-element    */
/* technique shown in the creative effects section above. */
border-image + border-radius don't mix
border-image overrides border-radius — rounded corners will not appear when you use border-image. For rounded gradient borders, use the ::before pseudo-element technique shown in the creative effects section.
Free Resource
CSS3 Cheat Sheet — All Properties & Selectors
One printable page covering every CSS3 property including all border, radius and box model reference.
Download PDF

Try It Yourself

This editor showcases borders in real components — cards, buttons, badges, blockquote and an alert. Try changing border-style, border-radius or border-color values to experiment.

Live Editor
✎ Editor
👁 Preview
Featured Course — Enroll Now
Modern Web Development With AI
Master HTML, CSS, JavaScript, React and Node.js with real projects and placement support.
120+
Chapters
40 hrs
Content
10 Real
Projects
4.9 ⭐
Rating
HTML5CSS3JavaScriptReact.jsNode.jsTailwind CSSAI Tools

Quick Check — Chapter 13

Questions & Answers
CSS borders have three sub-properties:

1. border-width — how thick the border line is. Accepts px, rem, em or keywords (thin, medium, thick). Defaults to medium.

2. border-style ← REQUIRED — the pattern of the line: solid, dashed, dotted, double, groove, ridge, inset, outset, none. Without this property set, no border renders regardless of width and colour.

3. border-color — the colour of the border. Defaults to the element's current color (text colour) if not specified.

The shorthand is border: width style color, e.g. border: 2px solid #264de4.
Set border-radius: 50% on an element where the width equals the height. The 50% value creates a radius equal to half the element's width/height on all corners, which produces a perfect circle.

Example:
.avatar { width: 48px; height: 48px; border-radius: 50%; }

If the element is not square (width ≠ height), border-radius: 50% produces an ellipse instead. For avatar images, always set both width and height to the same value.

For a fully rounded pill (like a badge or button), use border-radius: 999px instead — this rounds the shorter dimension completely regardless of the element's proportions.
Use the four individual side shorthand properties, each accepting the same width style color format:

border-top: 2px solid #264de4
border-right: 1px dashed #264de4
border-bottom: 2px solid #264de4
border-left: 4px solid #264de4

A common pattern is to reset all borders then add only specific ones:
border: none;
border-bottom: 1px solid #e5e7eb;

Or to override a single side after the shorthand:
border: 1px solid #e5e7eb;
border-top: 4px solid #264de4; — this top overrides the top border from the shorthand.
There are two techniques:

Method 1 — border-image (simple, no border-radius):
border: 3px solid transparent;
border-image: linear-gradient(135deg, #264de4, #a855f7) 1;

Limitation: border-image overrides border-radius — corners won't be rounded.

Method 2 — pseudo-element (supports border-radius):
Set the element to border: 3px solid transparent; background-clip: padding-box; position: relative, then use a ::before pseudo-element with the gradient as its background, positioned with inset: -3px and z-index: -1. This creates the gradient behind the element's border, producing rounded gradient borders.
1 value: border-radius: 12px — applies 12px rounding to all four corners equally.

2 values: border-radius: 12px 4px — first value = top-left and bottom-right, second = top-right and bottom-left.

4 values: border-radius: 12px 4px 8px 20px — clockwise from top-left: TL=12px, TR=4px, BR=8px, BL=20px.

Individual corner properties: border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius.

The elliptical slash syntax border-radius: 60% 40% / 40% 60% sets separate horizontal and vertical radii for each corner — used for organic blob shapes.
Multiple Choice Questions
Question 1 of 5
Which property MUST be set for a CSS border to be visible?
Question 2 of 5
What is the correct order for the border shorthand?
Question 3 of 5
What value of border-radius makes a perfect circle (assuming width equals height)?
Question 4 of 5
If you use border-image with a gradient, what limitation applies?
Question 5 of 5
What does border: 2px solid currentColor mean?
Chapter Summary
  • A CSS border has three characteristics: border-width, border-style (required), and border-color. Without border-style, nothing renders.
  • CSS supports 9 border styles: solid, dashed, dotted, double, groove, ridge, inset, outset, none.
  • Shorthand order: border: width style color. border-color defaults to currentColor (inherits text colour).
  • Individual sides: border-top, border-right, border-bottom, border-left — same width style color format.
  • border-radius rounds corners. 50% = circle (when square). 999px = pill. Accepts 1–4 values clockwise from top-left. Elliptical radii with / syntax for organic shapes.
  • Gradient border — two methods: border-image (simple but breaks border-radius) or the ::before pseudo-element technique (supports rounded corners).
  • Common patterns: left-accent blockquotes/cards, top-accent section cards, pill badges with border-radius: 999px, outline buttons with transparent background.
~7 min read
Beginner level
Chapter 13 of 60

Rate Us on Google

4.8 / 5
Enjoying this tutorial?
Your 5-star review helps other learners discover our free tutorials and encourages us to keep creating quality content.
80+ reviews
Write a Google Review
Join WhatsApp Channel