Boneyard Tools

CSS Triangle Generator

Generate a pure CSS triangle using the classic border trick. Choose one of eight directions, set the size and fill color, watch the live preview, then copy the border-based CSS straight into your stylesheet.

How to generate a CSS triangle

  1. Pick which way the triangle should point from the eight direction buttons.
  2. Set the size with the slider and choose a fill color.
  3. Check the live preview, then copy the generated CSS into your stylesheet.

Examples

Upward triangle (tooltip caret)

direction up, size 40, color #3b82f6
width: 0; height: 0; border-left: 40px solid transparent; border-right: 40px solid transparent; border-bottom: 40px solid #3b82f6;

Downward triangle (dropdown arrow)

direction down, size 12, color #111827
width: 0; height: 0; border-left: 12px solid transparent; border-right: 12px solid transparent; border-top: 12px solid #111827;

Top-left corner triangle (ribbon)

direction top-left, size 50, color #ef4444
width: 0; height: 0; border-top: 50px solid #ef4444; border-right: 50px solid transparent;

Frequently asked questions

How does the CSS border triangle trick work?

An element with width and height of zero has no content box, so its four borders meet at 45 degree diagonals in the center. If you color one border and make the two next to it transparent, the colored border collapses into a triangular wedge. That wedge is your triangle, drawn with no images, SVG or extra markup.

Why is the colored border opposite the direction the triangle points?

Each border grows inward from its own edge. The bottom border, for example, is a wedge whose flat base sits along the bottom and whose point reaches up, so coloring the bottom border makes a triangle that points up. That is why an up triangle colors border-bottom, a down triangle colors border-top, and so on.

How do the diagonal corner triangles work?

Corner triangles like top-left use only two borders instead of three. One adjacent border is colored and the other is transparent, which produces a right-angle triangle that fills a corner. These are handy for ribbons, badge corners and folded-page effects.

Does the size value change anything besides the triangle's scale?

The size is just the border width in pixels, so it sets both how wide and how tall the triangle is. A larger size makes a bigger triangle; the shape and direction stay the same. Edit the copied CSS if you want an asymmetric triangle with different border widths per side.

Can I use this triangle as a tooltip arrow or dropdown caret?

Yes. Position the generated element with absolute or relative positioning next to your tooltip, menu or speech bubble. Because the triangle is plain CSS it inherits transforms, transitions and color changes, so it animates and themes cleanly with the rest of your UI.

Is my design sent to a server?

No. The preview and the generated CSS are computed entirely in your browser, so nothing about your triangle or its settings ever leaves your device.

Related tools