CSSMar 19, 2026 · Updated Oct 13, 2026 · 3 min read

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.

▲
Try the CSS Triangle Generator
Free, no signup
→
DG
Derek Giordano
Designer & Developer
In this guide
01The Border Trick Explained02Triangles in Every Direction03Practical Uses04Modern Alternatives05Worked Example: Border Trick vs clip-path, Measured

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 trickclip-path
Painted area (ideal 4,330 px²)4,300 px²4,325 px²
Height drawn for 86.6px86 px (border widths snap to whole pixels)86.6 px
Click in the empty top cornerHits the elementPasses through
Click inside the triangleHits the elementHits 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?+
Set width and height to 0, make three borders transparent, and color the fourth. The colored border forms a triangle pointing away from its side. The transparent borders control the triangle's width.
Can I create an equilateral triangle in CSS?+
Yes. For an upward equilateral triangle with side s: border-left and border-right of s ÷ 2 and border-bottom of s × 0.866 (√3/2), which is the triangle's height. For s = 100px that is 50px, 50px and 86.6px. Browsers draw border widths in whole device pixels, so Chromium renders the 86.6px border as 86px at 1x zoom; clip-path: polygon(50% 0%, 0% 100%, 100% 100%) on a 100px × 86.6px box keeps the fraction.
Is clip-path better than the border trick?+
For anything interactive, usually yes. In our Chromium test a click in the transparent corner of a border-trick triangle still hit the element (the whole 100 × 86 px box is clickable and hoverable), while clip-path also clips hit-testing, so only the visible triangle responds. clip-path also takes backgrounds, gradients and images. The border trick is still fine for small decorative carets.
Try it yourself

Use the CSS Triangle Generator — free, no signup required.

⚡ Open CSS Triangle Generator
DG
Derek Giordano
Written by the creator of Ultimate Design Tools. BA in Business Marketing.