Table of contents
1.
Introduction
2.
Definition & Usage  
2.1.
Key Features
3.
CSS Syntax
4.
Example of Shapes
5.
Property Values
5.1.
Circle
5.2.
Ellipse
5.3.
Polygon
5.4.
Inset
6.
Example
7.
Example  
7.1.
 Example: Profile Card with Clip-Path  
8.
Practical Use Cases
9.
Browser Support
10.
Frequently Asked Questions
10.1.
Can I use clip-path with images?
10.2.
What happens if the browser doesn’t support clip-path?
10.3.
Can I animate clip-path?
11.
Conclusion
Last Updated: Jan 18, 2025
Easy

CSS clip-path property

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

The CSS clip-path property is a powerful feature that allows developers to define custom shapes and clip parts of an element, making only specific areas visible. This property is commonly used to create creative and unique designs, such as circular images, polygonal layouts, or custom transitions. By specifying a clipping path, you can control how an element appears within a container.

CSS clip-path property

In this article, we will discuss what the clip-path property is, how it works, and its practical usage with examples and code snippets.

Definition & Usage  

The `clip-path` property in CSS is used to define a specific region of an element that should be visible. Everything outside this region is hidden or "clipped." Think of it as using a stencil to paint only a specific part of an image or element.  

For example, if you have a rectangular image but want to display it as a circle, you can use `clip-path` to achieve this effect. The property works with basic shapes like circles, ellipses, polygons, & even complex paths defined using SVG.  

For example: 

<!DOCTYPE html>  
<html lang="en">  
<head>  
  <meta charset="UTF-8">  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">  
  <title>Clip-Path Example</title>  
  <style>  
    .image-container {  
      width: 300px;  
      height: 300px;  
      overflow: hidden;  
    }  


    img {  
      width: 100%;  
      height: 100%;  
      object-fit: cover;  
      clip-path: circle(50% at 50% 50%);  
    }  
  </style>  
</head>  
<body>  
  <div class="image-container">  
    <img src="https://via.placeholder.com/300" alt="Example Image">  
  </div>  
</body>  
</html>  


Output

Output

In this Code:  

1. HTML Structure:  

  • We have a `div` with the class `image-container` that holds an `img` element.  
     
  • The `img` tag uses a placeholder image for demonstration.  
     

2. CSS Styling:  

  • The `.image-container` is set to a fixed size of 300x300 pixels & has `overflow: hidden` to ensure the clipped part of the image doesn’t spill outside the container.  
     
  • The `img` element is set to cover the entire container using `width: 100%` & `height: 100%`.  
     
  • The `clip-path: circle(50% at 50% 50%)` property clips the image into a circle. Here, `50%` is the radius of the circle, & `at 50% 50%` positions the circle’s center at the middle of the image.  

Key Features

  • It supports shapes like circles, ellipses, polygons, and more.
     
  • You can use clip-path with images, videos, or other elements like <div>.
     
  • It enhances design flexibility without using extra HTML elements or external image editing tools.
     

For example, you can use clip-path to make an image appear circular:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Clip Path Example</title>
  <style>
    .circle {
      width: 200px;
      height: 200px;
      background: url('https://via.placeholder.com/200') no-repeat center/cover;
      clip-path: circle(50%);
    }
  </style>
</head>
<body>
  <div class="circle"></div>
</body>
</html>


Output: The image inside the <div> will appear as a circle.

CSS Syntax

The clip-path property uses the following syntax:

clip-path: <shape>;


Here’s a breakdown of the components:

<shape>: Defines the shape of the clipped area, such as circle(), ellipse(), polygon(), or inset().

Example of Shapes

Circle:

clip-path: circle(50%);


Ellipse:

clip-path: ellipse(50% 25%);


Polygon:

clip-path: polygon(0% 0%, 100% 0%, 50% 100%);


Inset Rectangle:

clip-path: inset(10px 20px 30px 40px);

Property Values

Circle

Creates a circular clip path. The value specifies the radius and center position.

clip-path: circle(75px at 50% 50%);

 

Example:

<div style="width: 300px; height: 300px; background: coral; clip-path: circle(100px at center);"></div>

 

Output: A coral-colored circle clipped from the center of a square.

Ellipse

Defines an elliptical shape. You can adjust the x and y radii independently.

clip-path: ellipse(50% 25% at 50% 50%);

 

Example:

<div style="width: 300px; height: 200px; background: lightblue; clip-path: ellipse(75px 50px at 50% 50%);"></div>

 

Polygon

Creates a polygonal shape by specifying points in a coordinate system.

clip-path: polygon(0% 0%, 100% 0%, 50% 100%);

 

Example:

<div style="width: 200px; height: 200px; background: pink; clip-path: polygon(50% 0%, 100% 100%, 0% 100%);"></div>


Output: A pink triangle shape.

Inset

Clips an element to a rectangle with specified offsets.

clip-path: inset(20px 30px 20px 30px);


Example:

<div style="width: 250px; height: 150px; background: green; clip-path: inset(20px 30px);"></div>


Output: A clipped green rectangle with insets.

Example

Here’s how to combine multiple clip paths for creative designs:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Clip Path Shapes</title>
  <style>
    .shape-container {
      display: flex;
      gap: 20px;
    }
    .shape {
      width: 100px;
      height: 100px;
      background: orange;
    }
    .circle {
      clip-path: circle(50%);
    }
    .ellipse {
      clip-path: ellipse(50% 25%);
    }
    .polygon {
      clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
    }
  </style>
</head>
<body>
  <div class="shape-container">
    <div class="shape circle"></div>
    <div class="shape ellipse"></div>
    <div class="shape polygon"></div>
  </div>
</body>
</html>


Output

Output

Three shapes—circle, ellipse, and triangle—are displayed in a row.

Example  

Let’s take a practical example to see how `clip-path` can be used in a real-world scenario. We’ll create a profile card with a circular image & a polygon-shaped background. This example will combine the concepts we’ve discussed so far.  

 Example: Profile Card with Clip-Path  

<!DOCTYPE html>  
<html lang="en">  
<head>  
  <meta charset="UTF-8">  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">  
  <title>Profile Card with Clip-Path</title>  
  <style>  
    body {  
      font-family: Arial, sans-serif;  
      display: flex;  
      justify-content: center;  
      align-items: center;  
      height: 100vh;  
      background-color: f4f4f4;  
      margin: 0;  
    }  

    .profile-card {  
      width: 300px;  
      background-color: white;  
      border-radius: 10px;  
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);  
      overflow: hidden;  
      text-align: center;  
    }  

    .profile-bg {  
      width: 100%;  
      height: 150px;  
      background-color: lightseagreen;  
      clip-path: polygon(0 0, 100% 0, 100% 75%, 0 100%);  
    }  

    .profile-img {  
      width: 100px;  
      height: 100px;  
      border-radius: 50%;  
      margin-top: -50px;  
      border: 4px solid white;  
      clip-path: circle(50% at 50% 50%);  
    }  
    .profile-info {  
      padding: 20px;  
    }  
    .profile-info h2 {  
      margin: 10px 0;  
      font-size: 24px;  
    }  

    .profile-info p {  
      color: 555;  
      font-size: 16px;  
    }  
  </style>  
</head>  
<body>  
  <div class="profile-card">  
    <div class="profile-bg"></div>  
    <img src="https://via.placeholder.com/100" alt="Profile Image" class="profile-img">  
    <div class="profile-info">  
      <h2>John Doe</h2>  
      <p>Web Developer</p>  
    </div>  
  </div>  
</body>  
</html>  

 

Output

Output

In this Code:  

1. Profile Card Structure:  

  • The `.profile-card` is the main container for the card. It has a white background, rounded corners, & a subtle shadow for a clean look.  
     
  • The `.profile-bg` div creates a background with a polygon shape using `clip-path: polygon(0 0, 100% 0, 100% 75%, 0 100%)`. This gives it a slanted bottom edge.  


2. Profile Image:  

  • The `.profile-img` class styles the profile image. It’s clipped into a circle using `clip-path: circle(50% at 50% 50%)`.  
     
  • The image is positioned halfway over the background using `margin-top: -50px` & has a white border to make it stand out.  


3. Profile Information:  

  • The `.profile-info` section contains the user’s name & job title. It’s centered & padded for better readability.  

Practical Use Cases

  • User Profiles: Display user information in a visually appealing way.  
     
  • Team Pages: Showcase team members with unique designs.  
     
  • Portfolios: Highlight skills & achievements creatively.  

Browser Support

The clip-path property is widely supported in modern browsers, with the exception of some older versions. Below is a compatibility table:

BrowserSupported Versions
Chrome55+
Firefox54+
Safari10.1+
Edge16+
Opera42+


To ensure cross-browser compatibility, always test your designs in multiple browsers.

Frequently Asked Questions

Can I use clip-path with images?

Yes, you can use clip-path with images, videos, or other elements to create unique shapes or hide certain parts.

What happens if the browser doesn’t support clip-path?

If a browser doesn’t support clip-path, the element will display in its default, unclipped shape. You can provide fallback styles for better compatibility.

Can I animate clip-path?

Yes, you can animate clip-path using CSS transitions or keyframes, making it a great tool for creative animations.

Conclusion

The clip-path CSS property is a versatile tool for creating custom shapes and enhancing your web designs. From circles to polygons, this property allows for endless creativity without needing external tools. By understanding the syntax and practical examples shared here, you’re now ready to use clip-path in your projects and make visually appealing designs.

Live masterclass