SVG Clip Path
A block cut into a five-pointed star by a real SVG clipPath, tilting and growing on hover; gradient, text or photo inside.
Updated
This effect is part of Effect.Labs — 840 vanilla effects, some free, some premium. SVG has 30 effects, including 3 free. Explore the category →
3 usage examples



How it works
The HTML holds a small invisible SVG (width="0" height="0") whose only job is to define a <clipPath>: a 10-point polygon, the 5 tips and 5 notches of a regular star. Its coordinates run from 0 to 1 (clipPathUnits="objectBoundingBox"): the star fits the box of the clipped element, whatever its size.
The .stc-star block is a square (aspect-ratio:1, 200 px by default) filled with a pink → magenta gradient and cut by clip-path:url(#…). Everything inside is cut with it: the centred word “Star”, or an <img> filling the square (object-fit:cover). On mouse hover, on focus of a link placed inside the star, or with the stc-on class, it tilts 15° and grows 10% over 0.3 s.
The small script gives each copy its own clipPath id (fx-0623-star- followed by random characters) and writes it into its star's clip-path. Two stars on one page never depend on each other, even when the first sits in a closed tab. Without JavaScript the fixed fx-0623-star id in the HTML is the default.
Accessibility
- Hidden SVG: the definition SVG has
aria-hidden="true"andfocusable="false"; it draws nothing and is not announced. - Readable content: the text inside the star is a real
<span>. A photo placed inside keeps itsalt; leave it empty when the person's name is written right next to it, as in the food bank example. - Keyboard and touch: the star itself is not a control. If it contains a link or button, keyboard focus triggers the same tilt (
:focus-within). Touch has no hover: the:hoverrule is limited to devices that have one (@media (hover:hover)) so the star does not stay tilted after a tap; addstc-onfrom JS if the tilt should follow a tap. - Reduced motion: under
prefers-reduced-motion: reducethe transition is removed; the star switches angle at once, with no animated rotation.
Browser compatibility
clip-path:url() to an SVG <clipPath> on an HTML element (-webkit- prefix included), aspect-ratio, inset, @media (hover:hover). Measured in Chromium, Firefox and WebKit (Playwright): star cut-out (removing the clip changes 14.7% of the image), tilt on hover, two copies with distinct ids, lone copy shown when the first one is hidden, 390 px, reduced motion.
Without aspect-ratio (browsers older than those listed) the block loses its height: give it a height equal to --stc-size. If the clipPath does not apply, the whole square shows, content included.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0623-root">
<svg class="stc-defs" width="0" height="0" aria-hidden="true" focusable="false">
<clipPath id="fx-0623-star" clipPathUnits="objectBoundingBox">
<polygon points="0.500,0.048 0.612,0.393 0.976,0.393 0.682,0.607 0.794,0.952 0.500,0.739 0.206,0.952 0.318,0.607 0.024,0.393 0.388,0.393"/>
</clipPath>
</svg>
<div class="stc-star">
<span class="stc-label">Star</span>
</div>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Size (CSS — --stc-size) |
200px | Side of the clipped square; the star follows and keeps its proportions. |
Fill (CSS — --stc-fill) |
linear-gradient(135deg, #f43f5e, #ec4899, #d946ef) | Any background value: colour, gradient, image. An <img> placed in .stc-star fills it too. |
Tilt (CSS — --stc-tilt) |
15deg | Angle on hover; a negative value turns the other way, 0deg keeps only the growth. |
Growth (CSS — --stc-grow) |
1.1 | Scale on hover. Leave room around it: at 1.25 a 200 px star takes 250 px. |
Duration (CSS — --stc-speed) |
.3s | Transition time, both ways. |
Active state without hover (stc-on class on .stc-star) |
absent | Same tilt as hover, set from JS: tap on touch screens, reward, hover on a parent. |
Block background and height (CSS — --stc-page, --stc-height) |
#0a0a0f / 300px | transparent and 0px to drop the star into a card, a badge or a row of icons. |
Shape (HTML — points of the <polygon>) |
5-pointed star | Coordinates between 0 and 1. For a slimmer star, move the 5 notch points closer to the centre (0.5, 0.5). |
FAQ
clip-path points to an id that does not exist on the page: definition SVG left out when pasting, or id edited by hand. Keep the .stc-defs SVG inside the root; the script links each star to its clipPath itself.<span class="stc-label"> with <img src="photo.jpg" alt="…">. It fills the square (object-fit:cover), then the whole thing is cut. Keep the subject centred: the tips only keep thin strips of the picture.stc-on class in a pointerdown listener, or put a link inside the star: focus has the same effect.