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.
Tips and Best Practices
- → The triangle trick uses borders. CSS triangles work by setting an element's width and height to 0, then using colored and transparent borders. The colored border forms the visible triangle.
- → Use triangles for dropdown arrows. Small CSS triangles make perfect arrow indicators for dropdown menus, accordion toggles, and expand/collapse buttons.
- → Consider clip-path for complex shapes. The border trick only creates right triangles and isosceles triangles. For equilateral, scalene, or irregular triangles, use
clip-path: polygon()instead. - → Use as tooltip arrows. CSS triangles are commonly used as the arrow/caret on tooltip callouts and speech bubble components.
Frequently Asked Questions
📖 Learn More
Related Article How to Create CSS Triangle Shapes →Built by Derek Giordano · Part of Ultimate Design Tools