← #125 Transform values from a JSON representation
#126

Create shapes with the clip path property

Topics: CSS

In the old days, we often used the :before and :after pseudo elements to create shapes, triangles, arrows for example.

Nowadays, it can be accomplished with a single CSS property named clip-path. As the name implies, it creates a clipping region from the original element.

If you're looking for a complex shape, then check this amazing CSS clip-path maker

Arrow

.arrow-left {
clip-path: polygon(
40% 0%, 40% 20%, 100% 20%, 100% 80%,
40% 80%, 40% 100%, 0% 50%
);
}
.arrow-right {
clip-path: polygon(
0% 20%, 60% 20%, 60% 0%, 100% 50%,
60% 100%, 60% 80%, 0% 80%
);
}

Bubble

.bubble {
clip-path: polygon(
0% 50%, 15% 60%, 15% 85%, 85% 85%,
85% 15%, 15% 15%, 15% 40%
);
}

Circle

.circle {
clip-path: circle(50% at 50% 50%);
}

Decagon

.decagon {
clip-path: polygon(
50% 0%, 80% 10%, 100% 35%, 100% 70%,
80% 90%, 50% 100%, 20% 90%, 0% 70%,
0% 35%, 20% 10%
);
}

Diamond

.diamond {
clip-path: polygon(15% 50%, 50% 85%, 85% 50%, 50% 15%);
}

Heptagon

.heptagon {
clip-path: polygon(
50% 0%, 90% 20%, 100% 60%, 75% 100%,
25% 100%, 0% 60%, 10% 20%
);
}

Hexagon

.hexagon {
clip-path: polygon(
25% 0%, 75% 0%, 100% 50%,
75% 100%, 25% 100%, 0% 50%
);
}

Ellipse

.ellipse {
clip-path: ellipse(25% 40% at 50% 50%);
}

Nonagon

.nonagon {
clip-path: polygon(
50% 0%, 83% 12%, 100% 43%, 94% 78%,
68% 100%, 32% 100%, 6% 78%, 0% 43%,
17% 12%
);
}

Octagon

.octagon {
clip-path: polygon(
30% 0%, 70% 0%, 100% 30%, 100% 70%,
70% 100%, 30% 100%, 0% 70%, 0% 30%
);
}

Parallelogram

.parallelogram {
clip-path: polygon(
5% 20%, 25% 80%, 95% 80%, 75% 20%
);
}

Pentagon

.pentagon {
clip-path: polygon(
50% 0%,
100% 38%,
82% 100%,
18% 100%,
0% 38%
);
}

Rectangle

.rectangle {
clip-path: polygon(0% 25%, 0% 75%, 100% 75%, 100% 25%);
}

Square

.square {
clip-path: polygon(15% 15%, 15% 85%, 85% 85%, 85% 15%);
}

Star

.star {
clip-path: polygon(
50% 0%, 61% 35%, 98% 35%, 68% 57%,
79% 91%, 50% 70%, 21% 91%, 32% 57%,
2% 35%, 39% 35%
);
}

Trapezoid

.trapezoid {
clip-path: polygon(25% 20%, 5% 80%, 95% 80%, 75% 20%);
}

Triangle

.triangle-up {
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}
.triangle-down {
clip-path: polygon(100% 0%, 0% 0%, 50% 100%);
}
.triangle-left {
clip-path: polygon(100% 0%, 0% 50%, 100% 100%);
}
.triangle-right {
clip-path: polygon(100% 50%, 0% 0%, 0% 100%);
}
.triangle-top-left {
clip-path: polygon(0 0, 0% 100%, 100% 0);
}
.triangle-top-right {
clip-path: polygon(0 0, 100% 100%, 100% 0);
}
.triangle-bottom-left {
clip-path: polygon(0 0, 0 100%, 100% 100%);
}
.triangle-bottom-right {
clip-path: polygon(100% 0, 0 100%, 100% 100%);
}
Fix a typo or suggest an improvement
#127 Lazy loading images with the loading attribute