polygon() CSS Function
Description
The polygon() CSS function is a powerful tool used to define complex, multi-sided shapes for clipping, masking, and other graphical effects. It is most commonly used with the clip-path property to create non-rectangular regions that control which parts of an element are visible. Unlike simple geometric shapes like circles or ellipses, polygon() allows you to specify an arbitrary number of vertices, each defined by an x and y coordinate, enabling precise and custom shapes.
Coordinates within polygon() can be expressed in percentages, relative to the element’s dimensions, or in absolute units such as pixels. This flexibility allows shapes to scale dynamically with the element. The points are connected in the order they are defined, automatically forming straight edges between consecutive points, and the last point is connected back to the first to close the shape.
You can also combine polygon() with other functions like inset() or circle() in clip-path for layered effects or compound clipping regions.
Example Usage:
div {
width: 200px;
height: 200px;
background-color: #3498db;
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
In this example, a square div is clipped into a diamond shape by connecting four points defined as percentages relative to its width and height.
The polygon() function is ideal for creating decorative elements, custom shapes for buttons, cards, or images, and can significantly enhance the visual design of a webpage without relying on images or SVGs.
Syntax
polygon() = polygon( [<fill-rule>,]? [<shape-arg> <shape-arg>]# )
Values
- <fill-rule>Specifies a fill-rule to use to determine the interior of the polygon. Can be either nonzero or evenodd. The default value is nonzero.
- <shape-arg>This can be specified in either of the following ways:
- <length> - Specifies a <length> value to use (e.g. px, em, vw, etc) for the radius.
- <percentage> - Specifies a <percentage> value to use. The percentage value uses the width and height of the reference box.
Example
Browser Support
The following information will show you the current browser support for the CSS polygon() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
This function is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 31st December 2025
