CSS Borders
CSS Borders are decorative lines that surround an element's content and padding, defined by border-width, border-style, and border-color properties, which can be set individually for each side of an element.
How do you add a border in CSS?
Use the border shorthand with a width, a style and a colour: border: 1px solid #ccc. The style is required; without it no border shows. Round the corners with border-radius, and style one side at a time with properties like border-bottom.
.card { border: 1px solid #e5e7eb; border-radius: 12px; }
.tab { border-bottom: 2px solid transparent; }
.tab.active { border-bottom-color: #3b82f6; }
.avatar { border-radius: 50%; } /* circle */Border Properties
Width
- • Thin, medium, thick
- • Pixels (px)
- • Ems, rems
- • Percentages
Style
- • Solid
- • Dashed
- • Dotted
- • Double
Color
- • Hex codes
- • RGB values
- • Named colors
- • Transparent
Border Styles Demo
Explore different border styles, effects, and techniques. Click on any box to see dynamic border changes!
Code Editor
<div class="b solid">solid</div>
<div class="b dashed">dashed</div>
<div class="b one-side">bottom only</div>
<div class="b round">rounded</div>
<div class="avatar"></div>Preview
Border Styles
Basic Styles
A single solid line
A series of dashes
A series of dots
Two parallel lines
Advanced Styles
3D grooved effect
3D ridged effect
3D inset effect
3D outset effect
Border Shorthand
Complete Border Shorthand
Border Radius
Border Image
Your Learning Path
Master CSS borders and visual framing
What You've Learned
- ▶Border width, style, and color properties
- ▶Different border styles and effects
- ▶Border radius for rounded corners
- ▶Individual border sides control
- ▶Border shorthand properties
What's Next
- ▶CSS Margins - Control external spacing
- ▶CSS Padding - Manage internal spacing
- ▶CSS Height & Width - Element dimensions
- ▶CSS Box Model - Complete layout system
Pro Border Tip
Use borders strategically to create visual hierarchy and guide user attention. Combine borders with shadows and gradients for modern, polished designs.
CSS Borders — step by step
Border Shorthand and Individual Sides
Use border: 2px solid red as a shorthand, or control each side independently with border-top, border-right, border-bottom, border-left.
🎯 Quick Check
Which property creates a border WITHOUT affecting the element's layout size?
CSS Borders: summary
Key points
- Border styles include
solid,dashed,dotted,doubleandnone. border-radius: 50%on a square element makes a circle.- Borders add to an element's size unless you use
box-sizing: border-box. - For a line that doesn't affect layout, use
outlineor an insetbox-shadow.
Frequently asked questions
›Why is my border not showing?
A border-style is missing. border: 1px red shows nothing; border: 1px solid red works.
›What is the difference between border and outline?
A border is part of the box model and takes up space. An outline is drawn outside the border, takes up no space, and can't have per-side styles. Outlines are mainly used for focus indicators.