🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Expert Masterclasses.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

CSS Borders

Define the edges of your elements. Learn about style, width, color, and how to master the shorthand syntax.

style.css
.box {
width: 100px;
border: 2px solid white;
border-radius: 12px;
}
🎨
borders.html
1 / 9
📦

Tutor:Every element in HTML is a box. The border property sits between the padding and the margin, outlining the element's content.


CSS Mastery: Borders

Unlock nodes by learning properties, shorthands, and radius.

Concept 1: Border Basics

To display a border, the border-style property is mandatory. Without it, width and color are ignored.

System Check

Which property is mandatory for a border to appear?


CSS Architect Hub

Share Your Designs

Created a cool button or card style? Share your border snippets with the community.

Enjoying this guide?

Codesyllabus is 100% free and open-source. Support our mission, pay for server infrastructure, and fuel new tutorials by buying us a coffee!

CSS Borders Explained

Author

Pascual Vila

Frontend Instructor.

The CSS border property allows you to specify the style, width, and color of an element's border. It is one of the fundamental layers of the CSS Box Model, sitting directly between the padding and the margin.

The Three Pillars

To render a visible border, you generally need to define three properties:

  • border-width: The thickness of the border (e.g., 1px, 5px, thin).
  • border-style: The line type. This is mandatory. Common values are solid, dashed, dotted, and double.
  • border-color: The color of the border. If omitted, it defaults to the element's current text color.

The Shorthand

Instead of writing three separate lines, you can use the border shorthand. The standard order is width, style, then color:
border: 2px solid red;

Border Radius

The border-radius property adds rounded corners to an element. You can use pixel values for a constant radius or percentages for a responsive curve. Setting border-radius: 50% on a square element will create a perfect circle.

CSS Border Glossary

border-style
Specifies what kind of border to display. Values include solid, dotted, dashed, double, groove, ridge, inset, outset, none, and hidden.
border-width
Specifies the width of the four borders. Can be a specific size (in px, pt, cm, em, etc) or using one of the three pre-defined values: thin, medium, or thick.
border-radius
Defines the radius of the element's corners. This property allows you to add rounded corners to elements.
Box Model
A box that wraps around every HTML element. It consists of: margins, borders, padding, and the actual content.