How to make a triangle with CSS
- Choose a direction: up, down, left, right or one of the four corners.
- Set the width, height and color.
- Pick a method: clip-path or the border trick.
- Copy the CSS for your
.triangleelement or pseudo-element.
clip-path vs the border trick
- clip-path: a normal box with a
polygon()mask. It is easy to read, accepts gradients and background images, and scales with the element. - Border trick: a zero-size element where one border is colored and the neighbouring borders are transparent. The borders meet at diagonal angles, which forms the triangle. It works everywhere and is common in older code and tooltip arrows.
Tooltip and dropdown arrows
To add an arrow to a tooltip, put the triangle on a ::before or ::after pseudo-element with content: "" and position: absolute, then place it on the edge of the bubble. Match its color to the bubble's background. With the border method the arrow color must be a solid color; with clip-path it can match a gradient.
Tips
- Use an equilateral triangle by setting the height to about 0.866 times the width (for example 120 by 104).
- Triangles drawn with borders cannot have their own border or shadow; stack two triangles, or use
filter: drop-shadow(). - Decorative triangles should be hidden from screen readers with
aria-hidden="true"when they are real elements.
Need more corners? The clip-path generator creates any polygon, from hexagons to stars.