CSS border-radius Property

The border-radius property rounds the corners of an element's outer border edge.

It can create circular or elliptical corners using lengths, percentages, and shorthand values. Each corner can have a different radius, allowing designs ranging from slightly rounded panels to pill-shaped buttons and circular images.

The property also affects how backgrounds and border images are clipped, although it does not clip an element's content unless an appropriate overflow setting is used.

border-radius Syntax

The border-radius property accepts one to four values for circular corners or two sets of values separated by a slash for elliptical corners.

selector {
  border-radius: 10px;
}

The general syntax is:

selector {
  border-radius: <length-percentage>{1,4} / <length-percentage>{1,4};
}

The slash and second set of values are optional.

Single Radius

.panel {
  border-radius: 12px;
}

Two Values

.panel {
  border-radius: 12px 24px;
}

Three Values

.panel {
  border-radius: 10px 20px 30px;
}

Four Values

.panel {
  border-radius: 5px 15px 25px 35px;
}

Percentage Radius

.panel {
  border-radius: 50%;
}

Elliptical Radius

.panel {
  border-radius: 40px / 20px;
}

Mixed Values

.panel {
  border-radius: 20px 40% / 10px 25%;
}

Calculated Radius

.panel {
  border-radius: calc(10px + 1vw);
}

CSS-Wide Keywords

.inherited {
  border-radius: inherit;
}
.reset {
  border-radius: initial;
}
.unset {
  border-radius: unset;
}
.reverted {
  border-radius: revert;
}
.layer-reverted {
  border-radius: revert-layer;
}

Negative radius values are invalid. A zero radius produces a square corner.

Property Values

The property accepts non-negative lengths, percentages, calculated values, and CSS-wide keywords.

Value Description
<length> Specifies a corner radius using a non-negative length such as 10px, 1rem, or 2em.
<percentage> Specifies a radius relative to the corresponding dimensions of the element's border box.
0 Creates a square corner.
/ Separates horizontal and vertical radii for elliptical corners.
calc() Calculates a radius from compatible CSS length and percentage values.
var() Uses a custom property containing valid radius values.
inherit Inherits the computed corner radii from the parent element.
initial Resets all corner radii to zero.
unset Resets all corner radii to zero because the properties are not inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value 0 for each corner radius
Inherited No
Applies to Elements that support border-radius properties
Computed value Two absolute lengths or percentages per corner, with length-percentage combinations preserved as appropriate
Animation type By computed value of the individual corner radii
Percentages Relative to border box width for horizontal radii and border box height for vertical radii
Negative values Not accepted
Property type Shorthand
Initial corner shape Square

The property is a shorthand for the four physical corner radius properties.

How It Works

The browser uses the radius values to replace square corners with curved corners.

Step 1: Start With a Square Box

.panel {
  width: 250px;
  padding: 20px;
  background-color: #1769aa;
}

Without a border radius, the element has square corners.

Step 2: Add Rounded Corners

.panel {
  width: 250px;
  padding: 20px;
  background-color: #1769aa;
  border-radius: 12px;
}

All four corners become rounded using the same radius.

Step 3: Use Different Corner Radii

.panel {
  border-radius: 10px 20px 30px 40px;
}

Each corner receives a different radius.

Step 4: Create Elliptical Corners

.panel {
  border-radius: 40px / 20px;
}

The horizontal radius is 40 pixels, while the vertical radius is 20 pixels.

Step 5: Create a Circle

.circle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background-color: #1769aa;
}

A square element with a 50% radius becomes circular.

Rounded corners do not require a visible border. They also affect the shape of an element's background.

One to Four Values

Without a slash, the property accepts one to four values. Each value is used for both the horizontal and vertical radius of its assigned corner.

One Value

.panel {
  border-radius: 20px;
}

All four corners use a 20-pixel radius.

Two Values

.panel {
  border-radius: 10px 30px;
}

The top-left and bottom-right corners use 10 pixels. The top-right and bottom-left corners use 30 pixels.

Three Values

.panel {
  border-radius: 10px 20px 30px;
}

The top-left corner uses 10 pixels, the top-right and bottom-left corners use 20 pixels, and the bottom-right corner uses 30 pixels.

Four Values

.panel {
  border-radius: 5px 15px 25px 35px;
}

The values apply clockwise, beginning at the top-left corner.

Number of Values Corner Assignment
1 All four corners
2 Top-left and bottom-right / top-right and bottom-left
3 Top-left / top-right and bottom-left / bottom-right
4 Top-left / top-right / bottom-right / bottom-left

The clockwise order is based on physical corners and does not change with writing direction.

Elliptical Corners

Elliptical corners use separate horizontal and vertical radii. A slash separates the two sets of values.

Basic Elliptical Radius

.panel {
  border-radius: 40px / 20px;
}

Each corner uses a 40-pixel horizontal radius and a 20-pixel vertical radius.

Tall Elliptical Corners

.panel {
  border-radius: 20px / 50px;
}

The vertical radius is larger than the horizontal radius.

Different Horizontal and Vertical Values

.panel {
  border-radius: 10px 30px / 20px 40px;
}

The horizontal radii alternate between 10 and 30 pixels. The vertical radii alternate between 20 and 40 pixels.

Four Horizontal and Vertical Values

.panel {
  border-radius: 10px 20px 30px 40px / 15px 25px 35px 45px;
}

Each corner receives its own horizontal and vertical radius.

Mixed Lengths and Percentages

.panel {
  border-radius: 20% 40px / 30px 50%;
}

Lengths and percentages can be combined within either set.

Understanding the Slash

Position Purpose
Before the slash Horizontal corner radii
After the slash Vertical corner radii

Each side of the slash independently follows the same one-to-four-value corner assignment rules.

Percentage Values

Percentage radii are calculated relative to the element's border box dimensions.

Horizontal percentages use the border box width. Vertical percentages use the border box height.

50% Radius

.shape {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background-color: #1769aa;
}

Because the element is square, the result is a circle.

Elliptical Shape

.shape {
  width: 240px;
  height: 120px;
  border-radius: 50%;
  background-color: #1769aa;
}

The rectangular element becomes an ellipse.

Percentage-Based Corners

.panel {
  border-radius: 10% 25%;
}

The radii scale with the element's dimensions.

Mixed Percentage and Length

.panel {
  border-radius: 20% 15px;
}

Elliptical Percentages

.panel {
  border-radius: 40% / 20%;
}

The horizontal radii use 40% of the border box width, while the vertical radii use 20% of the border box height.

Percentage radii are useful for shapes that should scale with their container, but the final appearance depends on the element's aspect ratio.

Individual Corner Properties

The border-radius shorthand controls four physical corner radius properties.

Property Corner
border-top-left-radius Top-left
border-top-right-radius Top-right
border-bottom-right-radius Bottom-right
border-bottom-left-radius Bottom-left

Equivalent Longhand Properties

.panel {
  border-top-left-radius: 10px;
  border-top-right-radius: 20px;
  border-bottom-right-radius: 30px;
  border-bottom-left-radius: 40px;
}

This is equivalent to:

.panel {
  border-radius: 10px 20px 30px 40px;
}

Round Only the Top Corners

.panel {
  border-radius: 16px 16px 0 0;
}

Round Only the Bottom Corners

.panel {
  border-radius: 0 0 16px 16px;
}

Round One Corner

.panel {
  border-radius: 0;
  border-top-left-radius: 30px;
}

Elliptical Longhand

.panel {
  border-top-left-radius: 40px 20px;
}

Individual corner properties use a space between horizontal and vertical radii, not a slash.

Use longhand properties when only one corner needs to change without resetting the other corners.

Radius Adjustment

When corner radii are too large to fit within the element's dimensions, the browser proportionally reduces them.

Oversized Radii

.panel {
  width: 200px;
  height: 100px;
  border-radius: 150px;
  background-color: #1769aa;
}

The browser adjusts the radii so adjacent corner curves do not overlap.

Different Large Radii

.panel {
  width: 200px;
  height: 100px;
  border-radius: 100px 80px 70px 60px;
}

The radii are scaled proportionally as needed to fit the border box.

Elliptical Adjustment

.panel {
  width: 200px;
  height: 100px;
  border-radius: 150px 100px / 90px 80px;
}

Both horizontal and vertical radii participate in the adjustment. A common scaling factor is used to preserve the relative proportions.

This automatic adjustment prevents overlapping curves and ensures the resulting border shape remains valid.

Large radius values are therefore not always rendered at their specified size.

Backgrounds and Borders

The border-radius property affects the shape of borders and the area where backgrounds are painted.

Rounded Background

.panel {
  padding: 20px;
  background-color: #1769aa;
  border-radius: 16px;
}

The background follows the rounded outer border edge even without a visible border.

Rounded Border

.panel {
  padding: 20px;
  border: 5px solid #1769aa;
  border-radius: 16px;
}

Background Clipping

.panel {
  padding: 20px;
  border: 5px solid #1769aa;
  border-radius: 16px;
  background-color: #dcecf8;
  background-clip: padding-box;
}

The background is clipped to the rounded padding edge rather than extending underneath the border.

Transparent Border

.panel {
  padding: 20px;
  border: 6px solid transparent;
  border-radius: 16px;
  background-color: #dcecf8;
  background-clip: padding-box;
}

The transparent border reserves space while the background follows the rounded padding edge.

Border Images

.panel {
  border: 12px solid transparent;
  border-image: linear-gradient(45deg, #1769aa, #27ae60) 1;
  border-radius: 20px;
}

Although border-radius rounds the element's border edge, border images are not clipped by the radius. A gradient border that must visibly follow rounded corners generally requires a different technique, such as layered backgrounds.

The final appearance depends on the border style, background clipping, and any border image used.

Overflow and Clipping

Rounded corners do not automatically clip an element's overflowing content.

Rounded Container

.card {
  border-radius: 16px;
  background-color: #f3f8fc;
}

The card's background is rounded, but overflowing child content may extend beyond the curved corners.

Clip Overflowing Content

.card {
  border-radius: 16px;
  overflow: hidden;
}

The content is clipped to the rounded padding edge.

Rounded Image

.profile-image {
  width: 150px;
  height: 150px;
  object-fit: cover;
  border-radius: 50%;
}

The image itself is clipped to a circular shape.

Rounded Image Container

.image-frame {
  width: 240px;
  height: 160px;
  border-radius: 20px;
  overflow: hidden;
}
.image-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

The container clips the image to its rounded corners.

Using overflow: clip

.card {
  border-radius: 16px;
  overflow: clip;
}

The content is clipped without creating a scroll container.

Use overflow clipping carefully because it can also hide content, shadows, or positioned elements that extend outside the container.

Physical vs. Logical Corners

The border-radius shorthand assigns values to physical corners. Logical corner properties adapt to writing mode and direction.

Physical Corner Radius

.panel {
  border-top-left-radius: 20px;
}

The top-left corner is rounded regardless of writing direction.

Logical Start-Start Corner

.panel {
  border-start-start-radius: 20px;
}

In horizontal left-to-right writing, this targets the top-left corner. In horizontal right-to-left writing, it targets the top-right corner.

Logical Corner Properties

Logical Property Horizontal LTR Corner
border-start-start-radius Top-left
border-start-end-radius Top-right
border-end-end-radius Bottom-right
border-end-start-radius Bottom-left

Right-to-Left Example

.panel {
  direction: rtl;
  border-start-start-radius: 20px;
}

The logical start-start corner maps to the physical top-right corner.

Vertical Writing Example

.panel {
  writing-mode: vertical-rl;
  direction: ltr;
  border-start-start-radius: 20px;
}

In this writing mode, the logical start-start corner maps to the physical top-right corner.

Use physical corner properties for fixed visual placement and logical corner properties for layouts that must adapt to writing direction.

Cascade and Overrides

The CSS cascade determines which corner radii apply when shorthand and longhand declarations overlap.

Later Declaration

.panel {
  border-radius: 10px;
  border-radius: 20px;
}

The later 20-pixel declaration wins when both have equal cascade priority.

Higher Specificity

.panel {
  border-radius: 10px;
}
.panel.featured {
  border-radius: 24px;
}

The featured panel uses a 24-pixel radius.

Longhand Override

.panel {
  border-radius: 16px;
  border-top-left-radius: 0;
}

All corners are rounded except the top-left corner.

Later Shorthand Reset

.panel {
  border-top-left-radius: 30px;
  border-radius: 10px;
}

The later shorthand resets all four corners to 10 pixels.

Physical and Logical Conflict

.panel {
  border-top-left-radius: 10px;
  border-start-start-radius: 30px;
}

In horizontal left-to-right writing, both declarations target the top-left corner. The later logical declaration wins when cascade priority is otherwise equal.

CSS Layers

@layer base, components;
@layer base {
  .panel {
    border-radius: 8px;
  }
}
@layer components {
  .panel {
    border-radius: 20px;
  }
}

For normal declarations, the later layer takes precedence.

When corner rounding appears incorrect, check shorthand resets, longhand declarations, specificity, cascade layers, and logical corner properties.

CSS Custom Properties

CSS custom properties can store reusable corner radii for components and themes.

Shared Radius

:root {
  --panel-radius: 16px;
}
.panel {
  border-radius: var(--panel-radius);
}

Fallback Radius

.panel {
  border-radius: var(--panel-radius, 12px);
}

The fallback is used when the custom property is unavailable or has the guaranteed-invalid value.

Component Variants

.card {
  --card-radius: 12px;
  border-radius: var(--card-radius);
}
.card.rounded {
  --card-radius: 24px;
}
.card.square {
  --card-radius: 0;
}

Theme-Based Radius

:root {
  --component-radius: 8px;
}
[data-theme="rounded"] {
  --component-radius: 24px;
}
.panel {
  border-radius: var(--component-radius);
}

Elliptical Custom Property

:root {
  --shape-radius: 40px / 20px;
}
.panel {
  border-radius: var(--shape-radius);
}

Calculated Radius

:root {
  --base-radius: 8px;
}
.panel {
  border-radius: calc(var(--base-radius) * 2);
}

Custom properties make it easier to maintain consistent corner shapes throughout a design.

Interactive States

Corner radii can change in response to hover, focus, selection, and other interface states.

Hover State

.button {
  border-radius: 8px;
}
.button:hover {
  border-radius: 20px;
}

Focus State

.form-field {
  border-radius: 6px;
}
.form-field:focus {
  border-radius: 12px;
}

Keyboard Focus

.form-field {
  border-radius: 8px;
}
.form-field:focus-visible {
  border-radius: 12px;
  outline: 2px solid #1769aa;
  outline-offset: 3px;
}

Selected Card

.card {
  border-radius: 8px;
}
.card.is-selected {
  border-radius: 24px;
}

Active Navigation

.nav-link {
  border-radius: 6px;
}
.nav-link[aria-current="page"] {
  border-radius: 20px;
  background-color: #dcecf8;
}

Invalid Form Field

.form-field {
  border-radius: 8px;
}
.form-field[aria-invalid="true"] {
  border-radius: 0;
  border-color: #c0392b;
}

Corner shape can reinforce interface states, but important information should also be communicated through text, color, or accessible attributes.

Transitions and Animation

The border-radius property can transition and animate between compatible corner radius values.

Basic Radius Transition

.panel {
  border-radius: 8px;
  transition: border-radius 0.3s ease;
}
.panel:hover {
  border-radius: 30px;
}

The corners gradually become more rounded when the element is hovered.

Square to Circle

.shape {
  width: 120px;
  height: 120px;
  border-radius: 0;
  background-color: #1769aa;
  transition: border-radius 0.4s ease;
}
.shape:hover {
  border-radius: 50%;
}

Keyframe Animation

@keyframes radius-change {
  0% {
    border-radius: 0;
  }
  50% {
    border-radius: 30%;
  }
  100% {
    border-radius: 50%;
  }
}
.animated-shape {
  width: 120px;
  height: 120px;
  background-color: #1769aa;
  animation: radius-change 3s ease-in-out infinite alternate;
}

Asymmetric Radius Animation

@keyframes corner-change {
  from {
    border-radius: 10px 30px 10px 30px;
  }
  to {
    border-radius: 30px 10px 30px 10px;
  }
}
.animated-panel {
  animation: corner-change 2s ease-in-out infinite alternate;
}

Reduced Motion Preference

.panel {
  border-radius: 8px;
  transition: border-radius 0.3s ease;
}
.panel:hover {
  border-radius: 24px;
}
@media (prefers-reduced-motion: reduce) {
  .panel {
    transition: none;
  }
}

Respect reduced motion preferences when adding animated shape changes to interactive components.

Responsive Design

Corner radii can adapt to viewport size, container size, and component dimensions.

Media Query

.panel {
  border-radius: 24px;
}
@media (max-width: 600px) {
  .panel {
    border-radius: 12px;
  }
}

Container Query

.panel-container {
  container-type: inline-size;
}
.panel {
  border-radius: 8px;
}
@container (min-width: 500px) {
  .panel {
    border-radius: 24px;
  }
}

Fluid Radius

.panel {
  border-radius: clamp(8px, 2vw, 30px);
}

Percentage Radius

.shape {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
}

The square shape remains circular as its width changes.

Responsive Custom Property

:root {
  --panel-radius: 24px;
}
@media (max-width: 600px) {
  :root {
    --panel-radius: 10px;
  }
}
.panel {
  border-radius: var(--panel-radius);
}

Responsive radii can keep corners proportional to component size without changing the content structure.

Practical Uses

The border-radius property is commonly used for cards, buttons, images, badges, and decorative shapes.

Rounded Card

.card {
  padding: 24px;
  border: 1px solid #d5dce3;
  border-radius: 16px;
  background-color: #ffffff;
}

Pill-Shaped Button

.button {
  padding: 12px 24px;
  border: 0;
  border-radius: 9999px;
  background-color: #1769aa;
  color: #ffffff;
}

A large radius creates fully rounded ends when the button's dimensions allow it.

Circular Profile Image

.profile-image {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 50%;
}

Rounded Top Corners

.card-header {
  padding: 16px;
  border-radius: 16px 16px 0 0;
  background-color: #1769aa;
  color: #ffffff;
}

Asymmetric Panel

.feature-panel {
  padding: 24px;
  border-radius: 8px 40px 8px 40px;
  background-color: #dcecf8;
}

Elliptical Badge

.badge {
  display: inline-block;
  padding: 10px 24px;
  border-radius: 50% / 100%;
  background-color: #27ae60;
  color: #ffffff;
}

Rounded Form Controls

.form-field {
  padding: 12px;
  border: 1px solid #cccccc;
  border-radius: 8px;
}

Use a consistent radius scale to create visual unity across related interface components.

border-radius Example

The following example demonstrates different corner radius values and shapes.

<div class="border-radius-demo">
  <div class="demo-box radius-0">0</div>
  <div class="demo-box radius-10">10px</div>
  <div class="demo-box radius-25">25px</div>
  <div class="demo-box radius-50">50%</div>
  <div class="demo-box radius-mixed">10px 30px</div>
  <div class="demo-box radius-ellipse">40px / 20px</div>
</div>
.border-radius-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 20px;
}
.border-radius-demo .demo-box {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 150px;
  height: 100px;
  max-width: 100%;
  padding: 10px;
  background-color: #1769aa;
  color: #ffffff;
  font-weight: bold;
  text-align: center;
}
.border-radius-demo .radius-0 {
  border-radius: 0;
}
.border-radius-demo .radius-10 {
  border-radius: 10px;
}
.border-radius-demo .radius-25 {
  border-radius: 25px;
}
.border-radius-demo .radius-50 {
  border-radius: 50%;
}
.border-radius-demo .radius-mixed {
  border-radius: 10px 30px;
}
.border-radius-demo .radius-ellipse {
  border-radius: 40px / 20px;
}
Browser Result
0
10px
25px
50%
10px 30px
40px / 20px

Each box uses the same dimensions and background color. Only the corner radius changes.

The 50% example becomes elliptical rather than circular because the box is wider than it is tall.

Important Considerations

Keep the following points in mind when using border-radius:

  • Purpose: Rounds the corners of an element's outer border edge.
  • Property type: Shorthand for four physical corner radius properties.
  • Initial value: Zero for every corner.
  • Inheritance: The property is not inherited.
  • One to four values: Control corner radii in clockwise order, starting at the top-left.
  • Elliptical corners: Use a slash to separate horizontal and vertical radii.
  • Lengths: Non-negative CSS lengths are accepted.
  • Percentages: Horizontal radii use border box width; vertical radii use border box height.
  • Negative values: Not accepted.
  • Zero radius: Produces a square corner.
  • Large radii: Automatically scale down when adjacent curves would overlap.
  • Visible border: Not required for rounded backgrounds.
  • Backgrounds: Follow the rounded border shape according to background clipping rules.
  • Border images: Are not clipped by border-radius.
  • Overflow: Child content may extend beyond rounded corners unless clipping is applied.
  • Physical corners: Shorthand values always follow physical corner order.
  • Logical corners: Logical radius properties adapt to writing mode and direction.
  • Shorthand resets: Later border-radius declarations replace all four corner radii.
  • Animation: Compatible corner radius values can transition smoothly.
  • Custom properties: Can store reusable radius values.
  • Responsive design: Supports media queries, container queries, and fluid radius calculations.
  • Accessibility: Rounded shapes should not be the only indicator of an important interface state.
  • Browser support: Supported by all major browsers.

Use border-radius for consistent rounded corners, and individual corner properties when more precise control is needed.

Browser Support

The border-radius property is widely supported in Chrome, Edge, Firefox, Safari, and other major browsers.

Modern browsers support circular and elliptical radii without vendor prefixes. Very old browser versions used prefixed implementations.

.panel {
  border-radius: 16px;
}

For current compatibility details, visit Can I Use? and search for border-radius.

Specifications

The border-radius property is defined in the CSS Backgrounds and Borders Module Level 3 specification.

CSS Backgrounds and Borders Module Level 3

The specification defines circular and elliptical corner radii, shorthand value distribution, and automatic radius adjustment when curves would overlap.