Toolstia / CSS triangle generator

CSS triangle generator

Choose a direction, width, height and colour and get the few lines of CSS that draw a triangle with no image. It is the classic border trick used for tooltip arrows, dropdown carets and speech bubbles.

This is the classic border trick: an element with no size and thick borders, where three of the four borders are transparent. It works in every browser. For rounded or more complex shapes, clip-path is the modern alternative.

How it works

  1. Pick the direction the triangle points.
  2. Set the width, height and colour.
  3. Copy the CSS.

How it works

An element with zero width and height and thick borders meets at diagonal joins. Making some borders transparent leaves a triangle.

Eight directions

Up, down, left, right and the four corner directions are supported.

Tooltip arrows

Place the triangle in a ::after pseudo-element positioned against the edge of the tooltip.

Alternatives

clip-path and inline SVG give more control, but the border trick works in every browser, including very old ones.

Questions

Does it work in all browsers?

Yes. It uses only borders. Everything happens in your browser, and nothing you enter is sent anywhere.

Can I add a border to the triangle?

Not directly. Layer a slightly larger triangle behind it in a different colour.

Can I use a gradient?

No, since the colour comes from borders. Use clip-path for a gradient triangle.