SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
CSS
1. CSS Tutorial for Beginners — Learn CSS from Scratch 2. CSS Syntax Explained — Selectors, Properties & Values 3. CSS Selectors Tutorial — Class, ID, Attribute & More 4. How to Add CSS to HTML — Inline, Internal, External 5. CSS Colors Tutorial — HEX, RGB, RGBA, HSL Explained 6. CSS Backgrounds Tutorial — Images, Size & Position 7. CSS Borders Tutorial — Style, Width, Radius & Shadow 8. CSS Margin Explained — Shorthand, Auto & Collapse 9. CSS Padding Explained — Shorthand & Margin Difference 10. CSS Height and Width — px, %, em, rem, vw, vh Units 11. CSS Box Model Explained — Content, Padding, Border 12. CSS Text Styling Tutorial — Color, Align & Spacing 13. CSS Fonts Tutorial — font-family, Sizes & Google Fonts 14. CSS Link Styling — Hover, Visited, Active & Buttons 15. CSS Lists Styling — Markers, Counters & Shorthand 16. CSS Tables Styling — Zebra Stripes & Hover Rows 17. CSS Display Property — Block, Inline, None Explained 18. CSS Position Explained — Relative, Absolute, Fixed 19. CSS Overflow Explained — Hidden, Scroll, Auto & More 20. CSS Float and Clear — Layouts & Clearfix Trick 21. CSS Pseudo-classes — Hover, Focus, nth-child & More 22. CSS Pseudo-elements — ::before, ::after & ::first-line 23. CSS Form Styling — Inputs, Labels & Buttons Tutorial 24. CSS Navigation Bar Tutorial — Dropdown Menu Included 25. CSS Website Layout Tutorial — Header, Sidebar, Footer 26. CSS Flexbox Tutorial — Complete Guide with Examples 27. CSS Grid Tutorial — Columns, Rows & Layouts Guide 28. CSS Responsive Design — Media Queries Tutorial 29. CSS Transitions & Animations — No JavaScript Needed 30. CSS Variables Tutorial — :root, var() & Theming 31. CSS Transforms Explained — Rotate, Scale, Translate 32. CSS Filters Tutorial — Blur, Grayscale, Sepia & More 33. CSS Text Effects — Shadows, Wrapping & Overflow 34. CSS Keyframes Tutorial — Bouncing Ball Animation 35. CSS Grid Template Areas — Layout in Words, Not Numbers
Final Test — Certificate ₹10
Try this code live
Lesson 7 of 35

CSS Borders Tutorial — Style, Width, Radius & Shadow

4 min read · Free · No login needed

A border is a line drawn around an element, between its padding and its margin. Borders make cards, buttons, and boxes visible — without a border, a white card on a white page is invisible. CSS gives you full control: the style of the line, its thickness, its colour, and each side separately.

Diagram — see how it fits together
Diagram: CSS Borders

Syntax — the three parts of a border

A border needs three things: a style (what kind of line), a width (how thick), and a colour. You can write them as three properties, or all at once in the shorthand.

.card {
  border-style: solid;
  border-width: 2px;
  border-color: #f59e0b;
}
/* The same border, in one line: */
.card {
  border: 2px solid #f59e0b;
}
Note: The style is the only part that is truly required. If you write border-width: 2px; border-color: red; but no style, nothing appears — the default style is none. This is the single most common border mistake: the border is "there" in the code but invisible on the page.

Border styles

StyleWhat it looks like
solidOne straight line — the everyday choice.
dashedA line of dashes, like a coupon edge.
dottedA line of dots.
doubleTwo thin lines side by side.
groove / ridgeA carved-in or raised 3D look.
noneNo border at all — the default.

Each side separately

You can style one side at a time — useful for an underline effect or a coloured left edge on a notice box.

.notice {
  border-left: 5px solid green;
  border-top: 1px solid #ccc;
}
.box {
  border-radius: 12px;
}

border-left, border-right, border-top, and border-bottom each take the same three values as the shorthand. And border-radius rounds the corners: a small value like 12px gives soft corners, and 50% turns a square into a perfect circle — the trick behind round profile photos.

Outline — the border's cousin

An outline looks like a border, but it is drawn outside the border, and it does not take up any space — it never pushes other elements away. That makes it perfect for focus rings: the coloured ring you see around a button or a form field when you press Tab.

button:focus {
  outline: 3px solid blue;
}
Tip: Never remove outlines from a site without replacing them with another visible focus style. Keyboard users navigate by the outline — without it, they cannot see where they are on the page.

Box shadow — depth without a border

box-shadow adds a soft shadow behind an element, which makes it look raised off the page — the classic card look. The values are: horizontal offset, vertical offset, blur, and colour.

.card {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

Read it as: no sideways shift, 4 pixels down, 12 pixels of blur, in a soft black that is 20% opaque. Shadows cost nothing in layout — like outlines, they do not push anything around.

Common mistakes

  • Setting width and colour but no style — the border stays invisible, because the default style is none.
  • Writing border: solid; and expecting a colour — without a colour, the border uses the text colour, which is often not what you wanted.
  • Using border-radius: 50% on a rectangle — you get an oval, not a circle. A circle needs a square element first.
  • Removing outlines with outline: none; and giving keyboard users nothing in return.
  • Forgetting that a border adds to the element's size — a 300px box with a 2px border is 304px wide, unless box-sizing: border-box is set.

Remember

  • A border is style + width + colour — and style is the one you must never forget.
  • Shorthand: border: 2px solid red; sets all three at once.
  • border-left / right / top / bottom style one side only.
  • border-radius rounds corners; 50% on a square makes a circle.
  • Outline sits outside the border and takes no space; box-shadow adds depth without affecting layout.

Example explained

  • .profile { border: 3px solid #2563eb; border-radius: 12px; } — the profile card gets a solid blue border and softly rounded corners.
  • .avatar { border-radius: 50%; } — the photo is a square, so a 50% radius turns it into a perfect circle.
  • .coupon { border: 2px dashed #dc2626; } — a dashed red border, like the torn edge of a paper coupon.
  • .card { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); } — a soft shadow under the card, so it looks raised off the page.
  • button:focus { outline: 3px solid #2563eb; } — when the button is focused with the keyboard, a blue ring appears around it.

Example

Example
<!DOCTYPE html>
<html>
<head>
<title>Student Profile Card</title>
<style>
body { font-family: Verdana, sans-serif; background-color: #f1f5f9; }
.profile { border: 3px solid #2563eb; border-radius: 12px; background-color: white; width: 300px; padding: 20px; margin: 20px auto; text-align: center; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); }
.avatar { border-radius: 50%; border: 2px solid #2563eb; width: 100px; height: 100px; background-color: #dbeafe; line-height: 100px; margin: 0 auto; }
.coupon { border: 2px dashed #dc2626; padding: 10px; margin-top: 16px; color: #dc2626; }
button { padding: 10px 20px; margin-top: 16px; }
button:focus { outline: 3px solid #2563eb; }
</style>
</head>
<body>

<div class="profile">
<div class="avatar">RK</div>
<h2>Raj Kamal</h2>
<p>Student — Diploma in CSE</p>
<div class="coupon">50% OFF on summer training</div>
<button>Enrol Now</button>
</div>

</body>
</html>

Output

Output — how it looks in the browser
Output of CSS Borders Tutorial — Style, Width, Radius & Shadow

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. What three things make a border?

Style, width, and colour — and style is the one you must never forget, because the default style is none.

2. How do you make a circle with border-radius?

Use border-radius: 50% on a square element. On a rectangle it makes an oval, not a circle.

3. What is the difference between outline and border?

An outline sits outside the border and takes no space, while a border sits between the padding and the margin.

Why learn this yourself — and not just ask AI?

AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

Full Stack PHP Development Course 2026
₹3,000
View
CapCut Mobile Video Editing Course Beginner to Advance
₹99
View
Summer Training in Python Programming 2026
₹3,000
View
Browse all courses
CSS — Lessons
1. CSS Tutorial for Beginners — Learn CSS from Scratch 2. CSS Syntax Explained — Selectors, Properties & Values 3. CSS Selectors Tutorial — Class, ID, Attribute & More 4. How to Add CSS to HTML — Inline, Internal, External 5. CSS Colors Tutorial — HEX, RGB, RGBA, HSL Explained 6. CSS Backgrounds Tutorial — Images, Size & Position 7. CSS Borders Tutorial — Style, Width, Radius & Shadow 8. CSS Margin Explained — Shorthand, Auto & Collapse 9. CSS Padding Explained — Shorthand & Margin Difference 10. CSS Height and Width — px, %, em, rem, vw, vh Units 11. CSS Box Model Explained — Content, Padding, Border 12. CSS Text Styling Tutorial — Color, Align & Spacing 13. CSS Fonts Tutorial — font-family, Sizes & Google Fonts 14. CSS Link Styling — Hover, Visited, Active & Buttons 15. CSS Lists Styling — Markers, Counters & Shorthand 16. CSS Tables Styling — Zebra Stripes & Hover Rows 17. CSS Display Property — Block, Inline, None Explained 18. CSS Position Explained — Relative, Absolute, Fixed 19. CSS Overflow Explained — Hidden, Scroll, Auto & More 20. CSS Float and Clear — Layouts & Clearfix Trick 21. CSS Pseudo-classes — Hover, Focus, nth-child & More 22. CSS Pseudo-elements — ::before, ::after & ::first-line 23. CSS Form Styling — Inputs, Labels & Buttons Tutorial 24. CSS Navigation Bar Tutorial — Dropdown Menu Included 25. CSS Website Layout Tutorial — Header, Sidebar, Footer 26. CSS Flexbox Tutorial — Complete Guide with Examples 27. CSS Grid Tutorial — Columns, Rows & Layouts Guide 28. CSS Responsive Design — Media Queries Tutorial 29. CSS Transitions & Animations — No JavaScript Needed 30. CSS Variables Tutorial — :root, var() & Theming 31. CSS Transforms Explained — Rotate, Scale, Translate 32. CSS Filters Tutorial — Blur, Grayscale, Sepia & More 33. CSS Text Effects — Shadows, Wrapping & Overflow 34. CSS Keyframes Tutorial — Bouncing Ball Animation 35. CSS Grid Template Areas — Layout in Words, Not Numbers
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Please log in to download. You will stay on this page after logging in!

New here? Register now →