Borders: Styles, Widths, Colors, border-radius, border-image and corner-shape
Everything about CSS borders: style, width and color, why a border without a style disappears, logical sides, transparent borders, border-radius with elliptical corners and pills, corner-shape for squircles and bevels, border-image, and gradient borders.
kvi5hnuCode Sprout team member10 min readOn this page
A border is a line drawn between an element's padding and its margin. It's part of the box model (article 36), so its width adds to the box's size, and the background is painted underneath it. Borders look simple, but there are many details: three sub-properties, physical and logical sides, rounded and now shaped corners, and borders made from images.
Style, width and color
Every border has three parts, usually set together with the border shorthand:
.card { border: 1px solid #e3d9c9; } /* width, style, color, in any order */
| Part | Property | Initial value | Values |
|---|---|---|---|
| style | border-style | none | solid, dashed, dotted, double, groove, ridge, inset, outset, hidden, none |
| width | border-width | medium | a length, or thin (1px), medium (3px), thick (5px) |
| color | border-color | currentColor | any color |
body { font: 600 0.8rem system-ui, sans-serif; margin: 1rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr)); gap: 0.75rem; }
div { padding: 0.9rem 0.3rem; text-align: center; background: #f4efe6; color: #8a3b12; border: 4px #8a3b12; }
Some details:
doubledraws two lines, and needs a width of at least 3px to show both.groove,ridge,insetandoutsetfake 3D by shading sides lighter and darker. Browsers compute the shades differently, so these look dated and inconsistent.box-shadow(article 52) gives better control.- The color defaults to
currentColor, the element's text color.border: 1px solidalone picks up the text color, and follows it when it changes. - Percentages aren't allowed for border widths.
hiddenis likenone, except in tables with collapsed borders, where it wins over every other border (article 74).
No style, no border
The most common border bug: border-width: 2px; border-color: red; shows nothing, because the initial style is none. A border with border-style: none doesn't exist: its computed width is 0, whatever border-width says. Always include a style, which the border shorthand makes easy.
Shorthands and sides
The single-side shorthands set one border: border-top, border-right, border-bottom and border-left, or the logical border-block-start, border-block-end, border-inline-start and border-inline-end (article 47). border-block and border-inline set both sides on one axis.
border-style, border-width and border-color take one to four values, clockwise from the top, like padding (article 39). Their logical versions, such as border-inline-width, take start and end values.
A common pattern sets all four sides, then overrides one:
.tab { border: 1px solid #ccc; border-bottom: none; } /* the override must come after */
The border shorthand also resets border-image to its initial value, so declare a border-image after it.
Transparent borders
A transparent border takes space but isn't visible. That's useful for:
- Hover borders without movement. If a border appears only on hover, the element grows and the layout jumps. Reserve the space with
border: 2px solid transparent, and change only the color on hover. - Forced colors mode, where the browser turns transparent borders into visible ones (article 35).
.option { border: 2px solid transparent; }
.option:hover, .option:has(:checked) { border-color: #8a3b12; }
border-radius
border-radius rounds the corners of the border and the background:
.card { border-radius: 12px; }
.avatar { border-radius: 50%; } /* a circle on a square box, an ellipse otherwise */
.pill { border-radius: 999px; } /* fully rounded ends at any height */
- It works without a border: the background is rounded anyway.
- Up to four values go clockwise from the top-left:
border-radius: 1rem 0 1rem 0rounds the top-left and bottom-right corners. - A slash separates horizontal and vertical radii, for elliptical corners:
border-radius: 40px / 12px. - Percentages refer to the box's own size: horizontal radii to its width, vertical radii to its height. That's why
50%makes a non-square box an ellipse, while999pxmakes a pill. - If adjacent radii add up to more than the side's length, the browser scales all radii down by the same factor until they fit. That's what makes
999pxgive perfect semicircular ends. - The inner curve, at the padding edge, has a radius equal to the outer radius minus the border width. If the border is thicker than the radius, the inside corner is square.
- Content isn't clipped by the rounded corners: a child image's square corners show over them. Add
overflow: hiddenoroverflow: clip(article 43) to the rounded element to clip its content. - Rounded corners don't change the box's shape for layout: floating text still wraps around the square box, unless you use
shape-outside(article 55).

Each pair shows one rule from the list above. The thick borders make the inner curve easiest to see: it's the outer radius minus the border, or square when that would be negative.
Single corners
| Physical | Logical, in horizontal left-to-right text |
|---|---|
border-top-left-radius | border-start-start-radius |
border-top-right-radius | border-start-end-radius |
border-bottom-left-radius | border-end-start-radius |
border-bottom-right-radius | border-end-end-radius |
The logical names are block side first, then inline side: border-start-end-radius is the corner where the block start (top) meets the inline end (right). Each corner takes one or two values, horizontal and vertical, with a space instead of a slash.
Nested rounded corners
When a rounded box sits inside another with padding, matching radii look wrong: the inner corners look too round. For concentric curves, make the inner radius the outer radius minus the gap:
.outer { --r: 1.25rem; --pad: 0.5rem; border-radius: var(--r); padding: var(--pad); }
.inner { border-radius: calc(var(--r) - var(--pad)); }
corner-shape
corner-shape changes the shape of the curve that border-radius sizes. It has no effect without a radius:
.squircle { border-radius: 2rem; corner-shape: squircle; }
.ticket { border-radius: 1rem; corner-shape: scoop; }
.tag { border-radius: 0.75rem 0 0 0.75rem; corner-shape: bevel; }
body { font: 600 0.8rem system-ui, sans-serif; margin: 1rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr)); gap: 0.75rem; }
div { aspect-ratio: 1; display: grid; place-items: center; text-align: center; background: #f4c95d; border: 3px solid #8a3b12; border-radius: 30%; color: #5a2509; }
p { grid-column: 1 / -1; margin: 0; font-weight: 400; }
| Value | Shape |
|---|---|
round (initial) | the usual quarter ellipse |
squircle | a smoother curve between round and square, as in app icons |
bevel | a straight diagonal cut |
scoop | an inward, concave curve |
notch | an inward square notch |
square | a square corner, as if there were no radius |
superellipse(n) | any shape in between: 1 is round, 2 is squircle, 0 is bevel, negative values curve inward, infinity is square |
Borders, backgrounds, shadows, outlines and overflow clipping all follow the shape. corner-shape is a shorthand for the per-corner properties such as corner-top-left-shape, and takes up to four values. It's in Chrome 139 and the Safari 27.3 beta, and in preview in Firefox. Browsers without it show ordinary rounded corners, which is a fine fallback.
border-image
border-image draws the border from an image or gradient instead of a style. The image is cut into nine pieces by four slice lines: the four corners go into the border's corners, and the four edges are stretched or repeated along the sides.
.frame {
border: 12px solid #8a3b12; /* fallback, and sets the width */
border-image: url("frame.png") 30 round; /* source, slice, repeat */
}
.gradient-edge {
border: 4px solid;
border-image: linear-gradient(90deg, #8a3b12, #f4c95d) 1;
}
| Longhand | Meaning |
|---|---|
border-image-source | the image or gradient |
border-image-slice | where to cut: numbers are image pixels, percentages are of the image size; fill also draws the middle piece over the background |
border-image-width | the drawn width of the border image; default 1, which means 1 × border-width |
border-image-outset | how far it extends beyond the border box |
border-image-repeat | stretch (default), repeat, round (repeat, scaled to fit whole tiles) or space |
- The element needs a border style other than
none, or there's no border area to draw in, unlessborder-image-widthsets it. - With a gradient, a slice of
1is the usual choice: it uses the whole gradient for the corners and edges. border-imageignoresborder-radius: the border stays square, although the background is still rounded.
Gradient borders with rounded corners
To combine a gradient border with rounded corners, use two background layers instead: a solid layer clipped to the padding box, over a gradient layer that covers the border box, with a transparent border to show it:
.glow {
border: 3px solid transparent;
border-radius: 12px;
background:
linear-gradient(#fffdf8, #fffdf8) padding-box,
linear-gradient(135deg, #8a3b12, #f4c95d) border-box;
}
Article 48 covers background-clip and background-origin, which this uses.

Borders on inline elements
On inline elements such as <a> or <code>, left and right borders take space in the line. Top and bottom borders are drawn but don't affect line height, so they can overlap the lines above and below (article 45). When an inline element wraps, its left border appears only at its start, and its right border only at its end, unless you use box-decoration-break: clone (article 39).
Borders that don't change layout
Since borders add to the box's size, adding one shifts the layout. When that's unwanted, use:
outline(article 42), drawn outside the box with no layout effect;box-shadow: 0 0 0 2px #8a3b12, a "border" that followsborder-radius, orinset 0 0 0 2pxto draw it inside;- a transparent border that changes only its color.
What's current
corner-shapeis in Chrome 139 and the Safari 27.3 beta, in preview in Firefox. It falls back to round corners.- Border widths still don't accept percentages.
border-radiusandborder-imagehave worked everywhere for many years.
Common questions
Why doesn't my border show?
It has no style. border-style defaults to none, which makes the width 0. Use border: 1px solid.
Why does the image inside my rounded card stick out at the corners?
border-radius doesn't clip content. Add overflow: hidden or overflow: clip to the card, or round the image too.
What's the difference between border-radius: 50% and 999px?
50% rounds each corner by half the box's width and height, which makes a circle on a square and an ellipse on a rectangle. 999px is scaled down to half the shorter side, which makes a pill with semicircular ends.
Can border-image have rounded corners?
No. Use the two-background technique with a transparent border instead.
How do I add a border on hover without the layout jumping?
Give the element a transparent border of the same width beforehand, and change only border-color on hover. Or use outline or an inset box-shadow, which don't take space.
Summary
bordersets width, style and color. Without a style, a border doesn't exist and its width is 0. The color defaults tocurrentColor.- Single-side and logical versions exist for every border property. The
bordershorthand resetsborder-image. - Transparent borders reserve space and appear in forced colors mode.
border-radiusrounds borders and backgrounds: clockwise from the top-left, a slash for elliptical corners, percentages of the box's size. Oversized radii scale down, which makes pills.- Rounded corners don't clip content without
overflow. corner-shapegives radius corners other shapes:squircle,bevel,scoop,notchandsuperellipse().border-imageslices an image or gradient into a border, but ignoresborder-radius. For rounded gradient borders, layer backgrounds withpadding-boxandborder-box.
Practice questions
What's wrong with this rule, and how do you fix it in one declaration?
.box { border-width: 3px; border-color: #8a3b12; }
Answer
There's no border style, so the computed border width is 0 and nothing is drawn. Write border: 3px solid #8a3b12;.
Write CSS for a 3rem circular avatar image with a 2px white ring.
Answer
.avatar { width: 3rem; aspect-ratio: 1; border-radius: 50%; object-fit: cover; border: 2px solid white; }
A card has border-radius: 1.5rem and padding: 0.5rem, and contains an image. What radius should the image have to look concentric?
Answer
1rem: the outer radius minus the padding, calc(1.5rem - 0.5rem).
Which corners does border-radius: 1rem 0 round?
Answer
The top-left and bottom-right. Two values set top-left and bottom-right first, then top-right and bottom-left.
Previous: Margin Collapsing: When Vertical Margins Combine and How to Stop It
Next: Outlines and Focus Indicators: outline, outline-offset and Accessible Focus Styles

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.