CSS borders, border-radius and outlines explained
A CSS border is drawn between an element's padding and margin and is defined by three values per side: width, style and color. The border shorthand sets all four sides at once (border: 2px solid #4f46e5), border-top and friends set one side, and border-width, border-style and border-color accept one to four values in clockwise order — top, right, bottom, left. A border is only painted when its style is not none, which is the default.
border-radius rounds the corners and also clips the background and box-shadow to the same shape. It accepts one to four values starting at the top-left corner and moving clockwise, and an optional slash introduces separate vertical radii for elliptical corners: border-radius: 50% 30% / 20% 40%. Percentages are relative to the element's width (horizontal radii) and height (vertical radii), so 50% turns a square into a circle.
outline looks similar but behaves differently: it takes no space, never shifts layout, can be pushed away from the element with outline-offset, and — in all current browsers — follows border-radius. That makes it ideal for focus indicators. This generator compares several equivalent forms and outputs the shortest correct CSS.
How to use the CSS Border Generator
- Set the width, style and color for all sides, or untick "Same border on all sides" and pick a side to style individually.
- Choose a radius unit and set one radius for every corner, or unlink the corners. Turn on elliptical corners for organic, blob-like shapes.
- Optionally add an outline with its own width, style, color and offset.
- Check the live preview, then copy the generated shorthand CSS.
Example
A card with a single accent edge and a visible keyboard focus ring:
.callout {
border: none;
border-left: 4px solid #4f46e5;
border-radius: 0 8px 8px 0;
}
.callout:focus-visible {
outline: 3px solid #a5b4fc;
outline-offset: 2px;
}Tips
- Borders add to an element's size unless you use
box-sizing: border-box, which most CSS resets apply to every element. - Use a large pixel radius such as
500pxinstead of50%for pill buttons —50%creates an ellipse on non-square elements. - Never remove focus outlines without a replacement.
:focus-visiblelets you show a ring for keyboard users only. The Button Generator adds one automatically. groove,ridge,insetandoutsetderive their light and dark shades from the border color, so they need a width of at least 3px to be noticeable.- For a border that follows a gradient, combine
border: 2px solid transparentwith two background layers, or useborder-image(which ignoresborder-radius). Build the gradient with the CSS Gradient Generator. - Add depth to bordered cards with the Box Shadow Generator.
Frequently Asked Questions
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 without affecting layout and cannot be set per side. Outlines can be offset with outline-offset, which makes them the standard choice for focus indicators.
What order do the four border-radius values use?
Top-left, top-right, bottom-right, bottom-left — clockwise from the top-left. With two values the first applies to top-left and bottom-right, the second to top-right and bottom-left. With three values the middle one covers top-right and bottom-left.
What does the slash in border-radius do?
Values before the slash are horizontal radii and values after it are vertical radii, creating elliptical corners. border-radius: 40px / 20px gives every corner a 40px wide and 20px tall curve.
Why does my border not show?
The default border-style is none, so a border with only a width and color is invisible. Always include a style, e.g. border: 1px solid #ccc. A width of 0 hides it as well.
Does outline follow border-radius?
Yes, in all current versions of Chrome, Edge, Firefox and Safari (Safari since 16.4). Older browsers draw a rectangular outline around rounded elements.