How does the CSS triangle border trick work?▾
An element with zero width and height has no visible surface, but its borders still render. When three borders are set to transparent and one is set to a solid color, the rendering engine draws the colored border as a triangle — the transparent borders form the angled sides.
Why do I set width and height to zero for triangles?▾
If the element has any positive width or height, the colored border renders as a rectangle with angled corners, not a pure triangle. Zero dimensions force all the visual space into the borders themselves, making the border the entire rendered shape.
Can I make a triangle with rounded corners?▾
The border-trick triangle cannot be rounded since border-radius does not apply to zero-dimension elements in a usable way. For rounded triangles, use clip-path: polygon() with a separate CSS filter for rounded corners, or use an SVG with a path and stroke-linejoin: round.
Should I use clip-path or border for triangles?▾
clip-path is more flexible, scales better, supports animation, and avoids the zero-dimension quirk. border-trick triangles have broader legacy browser support and no layout implications. For modern projects, clip-path is preferred; for maximum compatibility or simple tooltip carets, the border method is still appropriate.
How do I attach a triangle to a tooltip?▾
Use position: absolute on a ::before or ::after pseudo-element of the tooltip container. Set the pseudo-element's zero-dimension borders, then position it with top/bottom/left/right to place the caret at the desired edge and match its color to the tooltip background.
Can the triangle have a border or outline?▾
The border-trick triangle cannot have a separate border or outline applied to it because the triangle is itself composed of borders. For an outlined triangle, stack two triangles — a slightly larger one in the outline color behind the main colored one — using ::before and ::after.
How do I create a diagonal arrow shape?▾
Diagonal triangles use two adjacent borders set to transparent and two to the desired color — or set one to transparent and one thick, one thin, differently. The generator handles all eight directional variants including the four diagonals with correct border combinations.
Why does my triangle render as a square?▾
If you see a rectangle instead of a triangle, the element's width or height is not zero, or only one border is set rather than the required three. Check that both width: 0 and height: 0 are applied, and that the two adjacent borders (not opposite) are set to transparent.