What Is the CSS circle() Function?
The CSS circle() function is a fundamental basic shape function defined in the CSS Shapes Module Level 1 that creates perfect circular shapes for use with various CSS properties. Whether you're cropping images into circular thumbnails, wrapping text around circular elements, or creating motion paths for animations, understanding circle() is essential for modern web development.
The circle() function generates a circular clipping region or shape based on a center position and radius. It works seamlessly with properties like clip-path for masking elements, shape-outside for text wrapping effects, and offset-path for creating circular motion animations. This versatility makes it one of the most practical basic shape functions in CSS.
How circle() Fits Into CSS Shapes
The circle() function is part of a broader CSS Shapes ecosystem that includes four basic shape functions: circle(), ellipse(), inset(), and polygon(). While each serves different purposes, circle() stands out for its simplicity in creating perfect circles with a 1:1 aspect ratio.
When you use circle(), the function calculates the shape relative to the element's reference box. By default, this reference box is the border-box, meaning the circle's position and radius are calculated based on the element's border area. This default behavior provides predictable results for most use cases, though you can modify this using geometry-box values when needed.
CSS circle() Syntax
The circle() function follows a straightforward formal syntax that makes it easy to use: circle( <shape-radius>? [ at <position> ]? ). Both the radius parameter and the position parameter are optional, which means you can simply write circle() and get a default circle centered in the element.
When you omit the radius, the function defaults to using the closest-side keyword, meaning the circle's radius extends from the center to the closest edge of the reference box. When you omit the position, the circle is automatically centered within the element. This default behavior works remarkably well for most circular clipping scenarios, especially when you want the circle to fill as much of the element as possible.
1/* Complete syntax */2circle( <shape-radius>? [ at <position> ]? )3 4/* Examples */5circle() /* Default: closest-side, centered */6circle(100px) /* Fixed radius, centered */7circle(50% at center) /* Percentage radius, centered */8circle(closest-side) /* Explicit default */9circle(farthest-side at 50% 50%) /* Farthest side from center */10circle(100px at center) /* Explicit center position */11circle(100px at 25% 25%) /* Offset from top-left */The Radius Parameter
The radius parameter determines the size of your circle and can be specified in several ways. Length values like pixels, ems, or rems create fixed-size circles, while percentage values create circles relative to the reference box dimensions. For responsive designs, percentages are often preferred as they scale with the element.
The closest-side keyword (which is the default) calculates the radius as the distance from the center to the closest edge of the reference box. This ensures the circle always fits within the element without overflow. Conversely, the farthest-side keyword calculates the radius to the farthest edge, which can cause the circle to extend beyond the element's boundaries.
When using percentages, the radius is calculated based on the width and height of the reference box. For circle(), the percentage is calculated using the reference box's width for the horizontal axis and height for the vertical axis, then using the smaller of the two values to maintain a perfect circle aspect ratio.
1/* Fixed pixel radius */2.circle-fixed {3 clip-path: circle(100px);4}5 6/* Percentage radius (responsive) */7.circle-percent {8 clip-path: circle(50%);9}10 11/* Using closest-side (default) */12.circle-closest {13 clip-path: circle(closest-side);14}15 16/* Using farthest-side */17.circle-farthest {18 clip-path: circle(farthest-side);19}20 21/* Using viewport units */22.circle-viewport {23 clip-path: circle(10vw);24}The Position Parameter
The position parameter, introduced with the at keyword, specifies the center point of your circle. This follows the same syntax as the background-position property, giving you flexibility in how you define the center location. You can use keywords like center, top, bottom, left, and right, or provide specific length or percentage values.
The two-value syntax allows you to specify horizontal and vertical positions independently. For example, circle(100px at 50% 50%) places the center at the exact middle of the element. You can also use single keywords like circle(100px at center) for common positions or combine keywords like circle(100px at top right) for corner positioning.
When using percentages, the values are calculated relative to the reference box dimensions, with 0% 0% representing the top-left corner and 100% 100% representing the bottom-right corner. This positioning system makes it intuitive to place circles exactly where you need them within your design.
1/* Center position */2.circle-center {3 clip-path: circle(100px at center);4}5 6/* Using keywords */7.circle-top-left {8 clip-path: circle(100px at top left);9}10 11.circle-bottom-right {12 clip-path: circle(100px at bottom right);13}14 15/* Using percentage values */16.circle-offset {17 clip-path: circle(100px at 25% 75%);18}19 20/* Mixed syntax */21.circle-mixed {22 clip-path: circle(100px at 50% top);23}Using circle() with clip-path
The clip-path property combined with the circle() function is the most common way to create circular clipping effects on web elements. When you apply clip-path: circle(), you're defining a clipping region that determines which parts of an element are visible. Any content outside the circular region is hidden, effectively creating a circular crop. For more advanced clipping techniques, see our guide on CSS clip-path.
This technique works on any element type, including images, divs, videos, and text containers. The clipped element maintains its original dimensions in the document flow, but only the circular portion is rendered visually. This makes it perfect for creating circular profile images, decorative cutouts, and shaped containers for content.
According to MDN Web Docs, browser support for clip-path with basic shapes has been Baseline widely available since January 2020, meaning you can use it confidently in modern web projects with minimal compatibility concerns.
1/* HTML: <img class="circular-img" src="photo.jpg" alt="Profile"> */2 3.circular-img {4 clip-path: circle(50% at 50% 50%);5 width: 200px;6 height: 200px;7 object-fit: cover;8}9 10/* Circular div container */11.circular-div {12 clip-path: circle(100px at center);13 width: 200px;14 height: 200px;15 background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);16}Creating Circular Avatar Images
Circular avatar images are one of the most prevalent design patterns on the modern web, appearing in user profiles, comment sections, and social media interfaces. The clip-path circle() approach offers precise control over the clipping region and works seamlessly with responsive layouts.
To create effective circular avatars, ensure your images are square before clipping or use object-fit: cover to maintain aspect ratio within a square container. This prevents distortion and ensures a clean circular shape regardless of the original image dimensions. For production websites, consider adding a fallback border-radius approach for browsers with limited support, though this is largely unnecessary given the excellent browser compatibility.
The combination of clip-path with hover effects creates engaging user interactions. You can animate the radius or position for subtle effects, or transition between different circle sizes for responsive states. Our web development team regularly implements these techniques for client projects requiring polished user interfaces.
1<!-- Basic circular avatar -->2<div class="avatar">3 <img src="profile.jpg" alt="User profile" />4</div>5 6<!-- Avatar with hover effect -->7<div class="avatar-hover">8 <img src="profile.jpg" alt="User profile" />9</div>10 11<style>12.avatar img {13 width: 80px;14 height: 80px;15 clip-path: circle(50% at 50% 50%);16 object-fit: cover;17}18 19.avatar-hover img {20 width: 80px;21 height: 80px;22 clip-path: circle(50% at 50% 50%);23 object-fit: cover;24 transition: clip-path 0.3s ease;25}26 27.avatar-hover:hover img {28 clip-path: circle(45% at 50% 50%);29}30</style>Using circle() with shape-outside
The shape-outside property revolutionizes how text flows around elements by allowing content to wrap around custom shapes instead of rectangular boxes. When combined with circle(), this creates elegant magazine-style layouts where text follows the curve of circular images or decorative elements.
Unlike clip-path which hides content, shape-outside affects only the text flow around a floated element. The element itself remains visible, but surrounding text dynamically wraps to conform to the circular shape. This creates sophisticated layouts impossible with traditional CSS float alone.
For shape-outside to work correctly, the element must be floated. You can also use shape-margin to add spacing between the shape and the wrapping text, creating breathing room for visual hierarchy. This technique is particularly effective for editorial designs, product showcases, and creative portfolio layouts.
1/* HTML:2<div class="circular-float">3 <img src="product.jpg" alt="Product" />4</div>5<p>Text wraps around the circular image...</p>6*/7 8.circular-float {9 float: left;10 width: 200px;11 height: 200px;12 shape-outside: circle(50% at 50% 50%);13 shape-margin: 20px;14}15 16.circular-float img {17 width: 100%;18 height: 100%;19 clip-path: circle(50% at 50% 50%);20 object-fit: cover;21}22 23/* Right-side circular float */24.circular-float-right {25 float: right;26 shape-outside: circle(50% at 50% 50%);27 shape-margin: 15px;28}Using circle() with offset-path
The offset-path property enables elements to move along defined paths, and circle() creates perfect circular motion paths for animations. This combination opens up possibilities for orbital animations, rotating loaders, and engaging visual effects that draw user attention.
When you set offset-path: circle(), you're defining a circular track along which an element can travel. The element's position on this path is controlled by the offset-distance property, which accepts percentage values. Animating offset-distance from 0% to 100% creates smooth circular motion.
This technique is particularly powerful for loading indicators, decorative animations, and interactive elements that need to draw attention. Combined with CSS keyframe animations, you can create continuous orbital motion, pulsating effects, or complex multi-element animations that follow synchronized circular paths.
1.orbit-container {2 width: 200px;3 height: 200px;4 position: relative;5}6 7.satellite {8 width: 20px;9 height: 20px;10 background: #667eea;11 border-radius: 50%;12 position: absolute;13 offset-path: circle(50% at 50% 50%);14 animation: orbit 3s linear infinite;15}16 17@keyframes orbit {18 0% {19 offset-distance: 0%;20 }21 100% {22 offset-distance: 100%;23 }24}25 26/* Continuous rotation effect */27.satellite.continuous {28 offset-rotate: 0deg;29}Reference Box and Positioning
Understanding the reference box concept is crucial for predictable circle() behavior. By default, circle() uses the border-box as its reference box, meaning all calculations for radius and position are based on the element's border area. However, CSS provides several alternative reference boxes for different use cases.
The margin-box extends to include the element's margins, useful when you want the circle to account for space outside the border. The padding-box uses the padding area as reference, and content-box bases calculations on the content area alone. For SVG elements, additional options include fill-box, stroke-box, and view-box for more precise control.
As documented by MDN Web Docs, the geometry-box value allows you to explicitly specify which reference box to use, giving you fine-grained control over how your circular shapes are calculated and positioned.
Understanding Coordinate Systems
The coordinate system for circle() positioning starts at the top-left corner of the reference box, with positive values extending right and down. When you specify position as percentages, these are calculated relative to the reference box dimensions. A position of 50% 50% means the center of the circle is at the exact center of the element.
For responsive designs, using percentage-based positioning ensures your circles scale proportionally across different screen sizes. However, be aware that percentage-based radius calculations use the smaller dimension to maintain a perfect circle, which can lead to unexpectedly small circles on highly rectangular elements. In such cases, consider using fixed units or the closest-side keyword for more predictable results.
Browser Support and Fallbacks
The circle() function enjoys excellent browser support across all modern browsers. As noted in the web.dev CSS learning resources, clip-path with basic shapes has been Baseline widely available since January 2020, meaning it works out of the box in Chrome, Firefox, Safari, and Edge without prefixes or polyfills.
For projects requiring support for older browsers, progressive enhancement remains the best strategy. Use CSS @supports queries to detect browser capability and provide graceful fallbacks where needed. Most commonly, the fallback is a rectangular element with no clipping, which maintains layout integrity while the enhanced circular version displays in capable browsers.
Testing across browsers remains important, particularly for complex offset-path animations which may have subtle implementation differences. Consider using tools like MDN's browser compatibility data to verify specific use cases before deployment.
1/* Base styles (all browsers) */2.circular-img {3 width: 150px;4 height: 150px;5}6 7/* Enhanced styles (supporting browsers) */8@supports (clip-path: circle(50%)) {9 .circular-img {10 clip-path: circle(50% at 50% 50%);11 }12}13 14/* Fallback for older browsers */15@supports not (clip-path: circle(50%)) {16 .circular-img {17 border-radius: 50%;18 }19}Comparing circle() to Related Functions
While circle() excels at creating perfect circles, understanding how it compares to other basic shape functions helps you choose the right tool for each situation. The ellipse() function creates oval shapes by accepting separate horizontal and vertical radii, making it ideal for non-square aspect ratios. For rectangular or irregular shapes, the inset() function works well, and polygon() handles complex multi-point shapes.
The circle() function is simpler than ellipse() for true circular shapes since it requires only one radius value instead of two. For most avatar images and circular containers, circle() is the most straightforward choice. However, when you need elliptical shapes (like elongated backgrounds or oval decorations), ellipse() becomes the appropriate tool.
For simple circular clipping, border-radius: 50% often provides a simpler alternative to clip-path circle(). However, circle() offers advantages for advanced use cases including precise radius control, custom positioning, shape-outside text wrapping, and offset-path animations. The border-radius approach works only for clipping rectangular elements into circles, while circle() integrates with the broader CSS Shapes ecosystem.
Practical applications of the CSS circle() function across modern web design
Circular Profile Images
Create clean circular avatars for user profiles, comments, and team pages. The clip-path circle() approach maintains aspect ratio and provides precise control over the clipping region.
Text Wrapping Effects
Design magazine-style layouts with text flowing around circular images using shape-outside. Perfect for editorial content, product showcases, and creative portfolio designs.
Motion Path Animations
Build engaging orbital animations and rotating elements using offset-path with circle(). Creates compelling loading indicators and interactive visual effects.
Decorative Cutouts
Apply circular clipping to create unique visual effects on images, backgrounds, and interactive elements. Combine with animations for engaging user experiences.
Frequently Asked Questions
Sources
- MDN Web Docs - clip-path - Comprehensive reference for clip-path including circle() function syntax, browser support, and geometry-box values
- web.dev - Paths, shapes, clipping, and masking - Google's Learn CSS course covering basic shapes including circle() with practical examples and guidance