Skip to main content

CSS Image Shapes

Clipping images into circles, ellipses, and polygons takes very little CSS.


CSS clip-path Property and the circle() Function

To cut an element down to a basic shape, use clip-path.

One such shape is circle(), described by its radius and position.

Circle with 50% radius

A radius of 50% is all this image's circular clip needs.

Prompt
Create an HTML page that displays an image clipped to a circle using CSS clip-path with the circle() function at 50% radius. Use a placeholder image of about 300x300 pixels.
Output: complete HTML page

Circle positioned right

A circle's center is adjustable too. It accepts a length, a percentage, or one of the keywords left, right, top, and bottom; if you set none, it stays at center.

This image keeps the 50% radius, but the circle's center moves to the right.

Prompt
Create an HTML page that displays an image clipped to a circle using CSS clip-path with circle(50% at right), positioning the center of the circle to the right. Use a placeholder image of about 300x300 pixels.
Output: complete HTML page

CSS shape-outside and circle()

When inline content wraps around a floated element, shape-outside decides the shape it follows.

Here that shape comes from circle(), which takes a radius and a position.

Example

The text follows a curve here because shape-outside is a circle of 45% radius, while the image itself is clipped to a circle of 40% radius.

Prompt
Create an HTML page with a floated image clipped to a circle using clip-path: circle(40%), and use shape-outside: circle(45%) so surrounding text wraps around the circular shape. Include a paragraph of lorem ipsum text next to the image.
Output: complete HTML page

CSS clip-path and ellipse()

Besides circles, clip-path can clip an element to other basic shapes.

ellipse() is one of them, and it needs two radii, x and y.

Ellipse clip

The radii for this image's elliptical clip are 50% for x and 35% for y.

Prompt
Create an HTML page that displays an image clipped to an ellipse using CSS clip-path with ellipse(50% 35%). Use a placeholder image of about 300x300 pixels.
Output: complete HTML page

Ellipse positioned right

Ellipses can have their center moved as well, using a length, a percentage, or the keyword left, right, top, or bottom. Leaving it out means center.

With the same 50% x and 35% y radii, this image's ellipse is centered to the right.

Prompt
Create an HTML page that displays an image clipped to an ellipse using CSS clip-path with ellipse(50% 35% at right), positioning the center of the ellipse to the right. Use a placeholder image of about 300x300 pixels.
Output: complete HTML page

CSS shape-outside and ellipse()

Text can wrap around an elliptical shape too, by giving shape-outside an ellipse() value.

Example

The clip on this image is an ellipse of 40% x and 50% y radius. shape-outside uses a slightly larger one, 45% x and 50% y, and the text wraps around that elliptical shape.

Prompt
Create an HTML page with a floated image clipped to an ellipse using clip-path: ellipse(40% 50%), and use shape-outside: ellipse(45% 50%) so surrounding text wraps around the elliptical shape. Include a paragraph of lorem ipsum text next to the image.
Output: complete HTML page

CSS polygon() Function

A polygon shape is described with polygon().

Its arguments are a list of points, each one an x and y coordinate pair given as lengths or percentages. The top-left corner is 0 0, and the bottom-right corner is 100% 100%.

Two properties accept this function: clip-path and shape-outside.

Example

The polygon used to clip this image forms a diamond.

Prompt
Create an HTML page that displays an image clipped to a diamond polygon shape using CSS clip-path with polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%). Use a placeholder image of about 300x300 pixels.
Output: complete HTML page

CSS Properties and Functions

A recap of what this chapter used, properties and functions alike:

  • clip-path - clips an element to a basic shape or to an SVG source.
  • shape-outside - gives wrapping inline content a shape to follow.
  • circle() - a circle, set by its radius and position.
  • ellipse() - an ellipse, set by its x and y radii.
  • polygon() - a polygon.