How to Make a Triangle in CSS (3 Ways)

By Marko Denic
Contents
  1. Triangle with clip-path
  2. Triangles in every direction
  3. clip-path points for each direction
  4. Equilateral triangle
  5. The border trick
  6. How it works
  7. Tooltip and dropdown arrows
  8. Other ways
  9. A rotated square
  10. A gradient triangle
  11. Which method to use
  12. FAQ

The modern way to make a triangle in CSS is clip-path: take any box and cut it to a three-point polygon.

Triangle with clip-path

The points are x y pairs, measured from the top-left corner. This one is the top center, bottom right and bottom left. Because it’s a real box, you can give it a gradient, an image or a transition.

css
.triangle {
  width: 100px;
  height: 100px;
  background: #1d4ed8;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

Demo:

clip-path up
clip-path right
with gradient
border trick
corner
Tooltip
arrow

Triangles in every direction

clip-path points for each direction

Change the polygon points to change the direction. Corner triangles use three corners of the box.

css
.up    { clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.down  { clip-path: polygon(0 0, 100% 0, 50% 100%); }
.left  { clip-path: polygon(100% 0, 100% 100%, 0 50%); }
.right { clip-path: polygon(0 0, 100% 50%, 0 100%); }

.top-left     { clip-path: polygon(0 0, 100% 0, 0 100%); }
.bottom-right { clip-path: polygon(100% 0, 100% 100%, 0 100%); }

Equilateral triangle

All three sides equal: the height must be about 0.866 times the width (√3 ÷ 2). aspect-ratio keeps that ratio at any size. See how aspect-ratio works.

css
.equilateral {
  width: 100px;
  aspect-ratio: 1 / 0.866;
  background: #1d4ed8;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

The border trick

Before clip-path, every CSS triangle used borders, and you’ll still see it everywhere. It works because borders meet at a diagonal: on a box with no width or height, each border is a triangle.

How it works

Make the box zero-sized, give it a colored border on one side and transparent borders on the two sides next to it. The colored border is the triangle; the transparent ones set its width. The triangle points away from the colored side.

css
/* Points up: color the bottom border */
.triangle-up {
  width: 0;
  height: 0;
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  border-bottom: 80px solid #1d4ed8;
}

/* Points down: color the top border */
.triangle-down {
  width: 0;
  height: 0;
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  border-top: 80px solid #1d4ed8;
}

Tooltip and dropdown arrows

The border trick is still the simplest way to add an arrow to a tooltip or dropdown, using a ::after pseudo-element. A box with transparent borders on all sides and one colored side gives a neat arrow.

css
.tooltip {
  position: relative;
  background: #0f172a;
}

.tooltip::after {
  content: "";
  position: absolute;
  top: 100%;            /* just below the tooltip */
  left: 50%;
  translate: -50% 0;
  border: 7px solid transparent;
  border-top-color: #0f172a;  /* points down */
}

Other ways

A rotated square

Rotate a square 45° and hide half of it inside its parent. Unlike the other methods, this one can have a real border and a shadow, which is why it’s often used for speech-bubble arrows with outlines.

css
.bubble::before {
  content: "";
  position: absolute;
  bottom: -8px;
  left: 24px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-right: 1px solid #cbd5e1;
  border-bottom: 1px solid #cbd5e1;
  rotate: 45deg;
}

A gradient triangle

A hard-stop linear-gradient splits a box diagonally, so half of it is a right triangle. Useful as a background decoration without extra elements, just like CSS stripes.

css
.corner-ribbon {
  background: linear-gradient(to top right, transparent 50%, #1d4ed8 50%);
}

Which method to use

  • clip-path: the default. Any size, any background, easy to animate, and the shape scales with the box.
  • Border trick: small arrows on tooltips and dropdowns, solid color only.
  • Rotated square: when the arrow needs a border or shadow.
  • SVG: for icons and complex shapes, an inline <svg> with a <polygon> is often clearer than any CSS trick.

FAQ

How do I make a triangle in CSS?

Give an element a width, height and background, then clip-path: polygon(50% 0, 100% 100%, 0 100%). That’s an upward-pointing triangle.

Can a CSS triangle have a border?

Not with clip-path or the border trick, since clip-path cuts the border off too. Stack two triangles (a bigger one behind in the border color), use a rotated square with borders, or use SVG with a stroke.

Can I add a shadow to a triangle?

box-shadow follows the box, not the triangle. Use filter: drop-shadow() on the parent instead; it follows the visible shape.

How do I make a triangle pointing down?

clip-path: polygon(0 0, 100% 0, 50% 100%), or with the border trick, color the border-top.