How to Create a CSS Triangle (Border Trick Explained)
CSS triangles are created by exploiting how borders meet at corners. When an element has zero width and height, its borders form triangles at each corner. By making three borders transparent and one colored, you get a single triangle pointing in any direction. It's the most elegant CSS hack that's survived into modern web development.
The Border Trick Explained
When you set width and height to 0, an element becomes just its borders. Each border forms a triangle meeting at the center:
.triangle-down {
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #00FFD1;
}The colored border (top) forms a downward-pointing triangle. The transparent side borders define the triangle's width. Change which border is colored to change direction.
Triangles in Every Direction
Point up: color border-bottom, transparent left+right. Point down: color border-top, transparent left+right. Point left: color border-right, transparent top+bottom. Point right: color border-left, transparent top+bottom. For a right-angled corner triangle, color two adjacent borders (say top and left) and make the other two transparent: together they fill the upper-left half of the box.
Practical Uses
Tooltip arrows (positioned with ::before or ::after pseudo-elements). Dropdown menu indicators. Breadcrumb separators. CSS-only accordion expand/collapse icons. Section divider shapes. The CSS Triangle Generator lets you set direction, size, and color visually, then copy the CSS.
Modern Alternatives
CSS clip-path: polygon() creates triangles (and any other shape) without the border hack:
.triangle { clip-path: polygon(50% 0%, 0% 100%, 100% 100%); }This is more readable and supports background images, gradients, and hover effects. Use clip-path for decorative shapes; use the border trick for small indicators like tooltip arrows where simplicity matters.
Worked Example: Border Trick vs clip-path, Measured
We drew the same 100 px-wide equilateral triangle both ways in Chromium 141 and checked what the browser actually paints and where it accepts clicks (script and results in our test folder, October 13, 2026):
| Border trick | clip-path | |
|---|---|---|
| Painted area (ideal 4,330 px²) | 4,300 px² | 4,325 px² |
| Height drawn for 86.6px | 86 px (border widths snap to whole pixels) | 86.6 px |
| Click in the empty top corner | Hits the element | Passes through |
| Click inside the triangle | Hits the element | Hits the element |
The visual difference is under 1% — either method looks right. The behavioural difference matters: a border-trick triangle used as a button or hover target reacts across its whole rectangle, including the transparent corners, so neighboring links can become hard to click. Use clip-path when the shape is interactive, and give a decorative border-trick caret pointer-events: none.
Frequently Asked Questions
How do I create a triangle in CSS?
Can I create an equilateral triangle in CSS?
Is clip-path better than the border trick?
Use the CSS Triangle Generator — free, no signup required.
⚡ Open CSS Triangle Generator