1001Ferramentas
Dev

CSS Triangle Generator

Create pure CSS triangles using the border trick. Choose direction (up, down, left, right), size and color. Useful for tooltips, arrows and pointers. Everything in your browser.

Como funciona?

O truque das bordas aproveita um detalhe da renderização: quando um elemento tem largura e altura zero, suas bordas se encontram em diagonais. Tornando três das quatro bordas transparentes e a quarta colorida, restam apenas dois triângulos retângulos formando uma seta.

Útil para tooltips, balões de fala, indicadores de seleção e setas de carrosséis sem precisar de SVG ou imagens. Tudo no navegador.

Arrows and pointers with no SVG or images

The tiny arrow on a tooltip, the pointer on a speech bubble, the caret on a dropdown: cases too small to justify an SVG, yet annoying to hand-write. A pure CSS triangle handles them in half a dozen lines, but nobody remembers which border gets the color and which ones go transparent for each direction. Here you click one of eight directions, set width, height and color, check the preview and copy the ready block.

The trick exploits how browsers draw borders: on an element with zero width and height, the four borders meet along diagonals. Paint one and leave its neighbors transparent, and what remains is a triangle. For the four straight directions, the generator uses two side borders at half the width each, and the triangle's height becomes the thickness of the colored border; for the four corner diagonals the construction changes and it combines two full-size borders into a right triangle.

To attach it to a tooltip, paste the code into an ::after pseudo-element with position: absolute and place it against the bubble's edge, so you keep the HTML free of extra divs. The technique has clear limits: borders only take solid colors, so no gradients, no outline around the triangle, no background image inside the shape; for those, switch to clip-path or SVG. The generator accepts 20 to 400 px per side and runs entirely in your browser.

Frequently asked questions

How do I attach the arrow to a real tooltip?
Apply the generated code to a ::before or ::after of the bubble, with position: absolute, and adjust top and left until the arrow touches the edge. It is the same pattern most tooltip libraries use.
Can I make the triangle with a gradient or an outline?
Not with this technique: border-color only accepts solid colors and the triangle is made of the border itself. For gradients or outlines, use clip-path with polygon() or a small SVG.
Why does the generated CSS have zero width and height?
Because the drawing does not use the element's content, only its borders. With the box collapsed to zero, the borders meet at the center along clean diagonals, and that meeting is what forms the triangle.

Related Tools