CSS Triangle Generator
Generate pure CSS triangles and arrows with live preview using the border trick or clip-path.
关于此工具
Create pixel-perfect CSS-only triangles without any images or SVG. Choose from 8 directions: up, down, left, right, and all four diagonal corners. Control width, height, and color with instant live preview. Two techniques are generated side by side: the classic border-trick for maximum browser compatibility and the modern clip-path polygon approach. Also generates CSS arrows (border + rotation transform) for UI chevrons and pointers. Copy-paste ready CSS output for any approach.
使用方法
- 1 Select triangle direction (up, down, left, right, or diagonal corner).
- 2 Set the base width and height using the sliders.
- 3 Pick a fill color with the color picker.
- 4 Copy the border-trick CSS or the clip-path CSS — both are shown.
- 5 Use the Arrow section to generate a hollow arrow (chevron) CSS snippet.
Why a triangle is just a clever border
HTML elements are rectangles, yet you constantly see triangular shapes: dropdown carets, tooltip pointers, breadcrumb arrows. The classic trick exploits how browsers draw borders. When an element has zero width and height but thick borders, the four border edges meet at the center as diagonal seams — each side becomes a triangle that fans out from the middle. Make three of those borders transparent and color only the fourth, and the single visible triangle is your shape. This generator builds exactly that CSS and shows a live preview as you adjust it.
For an upward-pointing triangle, the recipe is left and right borders transparent and the bottom border colored:
| Property | Value | Role |
|---|---|---|
width / height | 0 | Collapses the box so only borders remain |
border-left | 30px solid transparent | Forms the left slope |
border-right | 30px solid transparent | Forms the right slope |
border-bottom | 60px solid #6366f1 | The visible colored face |
The half-width left/right borders set the base, and the bottom border sets the height. Diagonal triangles (a corner wedge for a ribbon or notch) use just two borders instead of three.
How width and height map to the output
The two sliders feed the border math directly. For up/down arrows the colored border equals your height while each transparent side border is half the width, so a 60×60 triangle gets 30px side borders and a 60px colored border. For left/right arrows the roles swap. Pick a direction from the nine-button grid, and the generator regenerates both the border CSS and a modern clip-path equivalent on the fly.
Border trick vs. clip-path: which to use
This tool gives you both, because they suit different jobs:
- Border trick — works in every browser ever shipped, needs no fixed dimensions, and is the bulletproof choice for tooltip and dropdown arrows. Its downside: the element has zero content box, so you can't put text or a background image inside the triangle, and it only makes straight-edged isosceles or right triangles.
- clip-path — defines the shape with a
polygon()of percentage points, for examplepolygon(50% 0%, 0% 100%, 100% 100%)for an upward triangle. The element keeps real width and height, so you can layer gradients, images, or even text behind the clip, and the points can describe any polygon. The catch is that you must give it explicit dimensions, and very old browsers ignore it.
A good rule: reach for the border trick for tiny UI pointers, and clip-path when the triangle needs to hold content or be an arbitrary shape.
The bonus CSS arrow
The third output is a chevron arrow — the thin ">" shape used for "next" buttons and accordion toggles. It is built differently from the filled triangle: a small square element shows only its right and bottom borders and is then rotated with transform: rotate(). Rotating that L-shaped corner by 45°, 135°, 225°, or 315° points it in any of the four diagonal directions, giving you a crisp outline arrow that scales with border thickness rather than a solid wedge.
Practical tips and pitfalls
- Position a tooltip pointer with the element's own borders. Place the triangle as a
::beforeor::afterpseudo-element and nudge it with negative margins so it overlaps the bubble's edge seamlessly. - Match the color to the parent. A tooltip arrow only looks attached if its colored border is the exact same value as the bubble's background — copy the hex from one place to both.
- Don't set a border on a triangle you also gave width. The border trick relies on width and height being
0; add real dimensions and the borders draw as a frame, not a triangle. Use the clip-path version instead when you need size. - Anti-aliasing on rotated chevrons. At small sizes a rotated chevron can look slightly soft; bump the border thickness up a pixel for a cleaner edge on high-density screens.
All CSS is generated in your browser as you type, and the copy buttons place each snippet on your clipboard — nothing is uploaded.
常见问题
可视化构建CSS边框、轮廓和盒子阴影,带实时预览和即时代码输出。
Visually generate CSS clip-path shapes — polygon, circle, ellipse, inset — with draggable handles, preset shapes, and live preview.
Create decorative SVG wave dividers for websites with live preview and one-click download.