Borders and rounding
Definition and purpose
Borders surround the padding edge and participate in box sizing. Border radius shapes the corners of the border and background; it does not automatically clip all descendants.
Card border
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> #a { border: 2px solid navy; border-radius: 12px; padding: 12px; } </style> </head> <body> <div id="a">Sample A</div> <div id="b">Sample B</div> </body></html>The card has a visible stroke, space inside and rounded corners.
Syntax and mental model
border: 2px solid navy specifies width, style and color. Individual sides can override it. border-radius: 12px sets all corners; four values proceed top-left, top-right, bottom-right, bottom-left. Percent radii refer to corresponding box dimensions.
Asymmetric corner radii
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> #a { border: 3px solid green; border-bottom-width: 6px; border-radius: 4px 8px 12px 16px; } </style> </head> <body> <div id="a">Sample A</div> <div id="b">Sample B</div> </body></html>The bottom edge is thicker and each corner has its own radius.
Common mistakes
A width and color alone are insufficient when border-style is none. Radius is not a substitute for padding, and a rounded card should not clip meaningful focus indicators.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Gradients. Next lesson: Outlines and shadows.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Borders and rounding — knowledge check
Five questions on borders and rounding.
Which components belong in border shorthand?
With border-style none, what is the computed border width?
Which is the third radius in four-value order?
Does radius replace padding?
Does radius alone clip all overflowing descendants?