What Is the CSS Triangle Trick?
CSS triangles use a clever border technique — when an element has zero width and height, its borders form triangles that meet at the center. By making three borders transparent and one colored, you get a clean triangle without any images or SVG. This technique has been a CSS staple for over a decade and remains the simplest way to add arrows and pointers to tooltips, dropdowns, and navigation.
How It Works
Set width: 0; height: 0; on the element. Then apply borders: the colored border determines the triangle's base, and the transparent side borders control its width. The triangle points opposite to the colored border — a colored bottom border creates an upward-pointing triangle.
How to Use This CSS Triangle Generator
- Choose the triangle direction — Select which direction the triangle points — up, down, left, right, or diagonal.
- Set the size — Adjust the width and height of the triangle independently to control its proportions.
- Pick a color — Choose the fill color for the triangle.
- Copy the CSS — Grab the CSS border-trick code that creates the triangle using transparent borders.
Worked example: what "Width 60, Height 80" really gives
The two sliders feed different borders depending on the direction. On October 12, 2026 we rendered the copied CSS for each direction at the defaults (width 60, height 80) in Chromium and measured the box.
| Direction | Rendered size | Why |
|---|---|---|
| Up, Down | 120 × 80 px | Width is used for both the left and right borders, so it is half the base |
| Left, Right | 60 × 160 px | Height is used for both the top and bottom borders, so it is half the base |
| Top-Left, Top-Right, Bottom-Left, Bottom-Right | 60 × 80 px | Each slider is one border, so the numbers are the real size |
- For an exact size, halve the base. An Up arrow that must be 16 px wide and 8 px tall needs width 8, height 8. For Left and Right, the height slider is half the triangle's height.
- Equal-sided triangles: for an equilateral Up triangle, the height should be about 0.866 × the base, so with width w (half the base) set height to 1.732 × w (for example width 30, height 52).
- Border triangles have no outline or real shadow. box-shadow draws around the empty 0 × 0 box, and a border on the triangle is impossible because the borders are the triangle. Use filter: drop-shadow(), which follows the visible shape, or switch to clip-path: polygon() on a sized element if you need a background image, gradient or hover area that matches the shape.
- The click area is the whole border box, transparent parts included (120 × 80 px for the default Up arrow). For a clickable arrow, put the triangle on a ::before or ::after of a properly sized button instead.
- Uses today: tooltip and speech-bubble arrows (as in the CSS Tooltip Generator), dropdown carets and breadcrumb chevrons; for icons, an inline SVG scales and recolours more cleanly.
Sources
Checked on .
Frequently Asked Questions
📖 Learn More
Related Article How to Create CSS Triangle Shapes →Built by Derek Giordano · Part of Ultimate Design Tools