CSS Triangle Generator

Generate lightweight, pixel-perfect CSS triangles and arrow pointers using the classic zero-pixel border box technique. Interactively adjust directions (top, bottom, left, right, diagonals), custom dimensions, and hex colors with ready-to-use tooltip pseudo-element code snippets.

100% Free & Client-Side8 Direction AnglesZero Image DependenciesTooltip ::after CodeSCSS Mixin Export
HiFi ToolKit Logo
Visual Triangle Preview
0px Box Model Hack
Quick Preset Sizes
Triangle Direction
Generated CSS
/* Pure CSS Triangle */
.triangle-top {
  width: 0;
  height: 0;
  border-left: 15px solid transparent;
  border-right: 15px solid transparent;
  border-bottom: 30px solid #10b981;
}

The Complete Technical Guide to Pure CSS Triangles & Pointers

Learn the underlying mechanics of border-box geometry, how to construct responsive tooltip carats, and how eliminating bitmap icons accelerates page load speed and Core Web Vitals.

The Physics of the CSS 0px Border-Box Technique

To the uninitiated developer, creating geometric triangles without SVG or images sounds impossible. However, the CSS border triangle technique is one of the most ingenious and elegant hacks in web development history. To understand how it works, examine how browsers render borders on rectangular boxes.

When a standard HTML element has a width and height, its four borders meet at 45-degree mitered angles at the corners. Now, imagine collapsing both the width and height of that element down to exactly 0px. With no content box remaining, the four borders collide at the exact center point. If you assign equal widths to all four borders and give each a different color, you will see four distinct triangles fitting together like a pyramid seen from above.

By turning three of the four borders transparent (border-color: transparent) and leaving only one border with a solid color, the other three disappear, leaving behind a razor-sharp, perfectly rendered geometric triangle.

Calculating Triangle Geometries: Directional Blueprint

Depending on the desired direction of the arrow tip, you configure the opposite border with your desired height and the adjacent perpendicular borders with half the width:

Arrow Pointing Up (Top)

To point the arrow upward, the colored border must be placed on the bottom. The left and right borders are set to transparent and each takes half of the total width:

/* 30px Wide, 20px High Up Arrow */
.arrow-up {
  width: 0;
  height: 0;
  border-left: 15px solid transparent;
  border-right: 15px solid transparent;
  border-bottom: 20px solid #10b981;
}

Arrow Pointing Down (Bottom)

Conversely, an arrow pointing downward places its colored border on the top, with equal transparent flanks on the left and right:

/* 30px Wide, 20px High Down Arrow */
.arrow-down {
  width: 0;
  height: 0;
  border-left: 15px solid transparent;
  border-right: 15px solid transparent;
  border-top: 20px solid #10b981;
}

Arrow Pointing Left

For horizontal arrows pointing left, the colored border sits on the right, while the top and bottom borders split the height evenly:

/* 20px Wide, 30px High Left Arrow */
.arrow-left {
  width: 0;
  height: 0;
  border-top: 15px solid transparent;
  border-bottom: 15px solid transparent;
  border-right: 20px solid #10b981;
}

Diagonal Corner Slice (Right-Angled)

Diagonal ribbons and corner badges require only two borders (one colored, one transparent) without the third:

/* Top-Left Diagonal Corner */
.corner-badge {
  width: 0;
  height: 0;
  border-top: 40px solid #10b981;
  border-right: 40px solid transparent;
}

Production Blueprint: Creating Tooltips with ::after

In real-world web applications, CSS triangles are most commonly used to attach directional pointers to floating tooltips, popovers, and chat speech bubbles without cluttering the HTML markup with unnecessary <span> tags.

Complete Tooltip CSS Architecture
/* Parent Tooltip Container */
.tooltip-container {
  position: relative;
  display: inline-block;
  background-color: #1e293b;
  color: #ffffff;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
}

/* Tooltip Bottom Pointer */
.tooltip-container::after {
  content: '';
  position: absolute;
  top: 100%; /* Sits immediately below tooltip */
  left: 50%;
  transform: translateX(-50%); /* Centers pointer */
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid #1e293b; /* Matches tooltip background */
}

By binding the triangle's border-top-color to match the tooltip's background-color, the triangle seamlessly appears as a physical extrusion of the popover box.

Comparison: CSS Border Triangles vs SVG vs Icon Fonts

Why do top engineering teams at GitHub, Bootstrap, and Tailwind continue to recommend CSS border triangles? The performance comparison below tells the story:

MetricPure CSS Border TriangleInline SVG VectorFont Awesome / Icon Font
HTTP Requests0 (Inlined in stylesheet)0 (If inlined) or 1 (If external file)1-2 (External WOFF2 font files)
DOM OverheadZero (Uses ::after)Requires <svg><polygon/> nodesRequires <i> element
Flash of Unstyled Text (FOUT)None (Renders immediately)NoneHigh (Flashes until font loads)
Dynamic ThemingNative CSS custom propertiesCSS fill propertyCSS color property
Legacy Compatibility100% (All browsers since IE6)Modern browsers (IE9+)Modern browsers

Frequently Asked Questions (FAQs)

When an element has width: 0 and height: 0, the borders meet at a single central point. Where adjacent borders meet, CSS miters the edges at a 45-degree angle. By making three of the borders transparent and giving one border a solid color and width, a crisp, scalable triangle shape is formed purely via browser border rendering.

CSS triangles require zero external HTTP requests, zero extra DOM nodes, and zero image assets. They are defined in pure CSS, scale crisply to high-DPI retina displays, and their colors can be altered instantly using CSS variables or hover states without requiring image file modifications.

The industry-standard pattern is to attach the triangle using a ::before or ::after pseudo-element on the tooltip container. Set position: relative on the container, and position: absolute, content: '', width: 0, height: 0 on the pseudo-element, positioning it along the outer border with top/bottom/left/right offsets.

Because the triangle is formed using borders, you cannot add a standard border: 1px solid property to it. To create an outlined triangle, developers stack two pseudo-elements (::before for the outer border triangle and ::after for the inner background triangle, shifted 1px inward), or use filter: drop-shadow() on the parent.

A right-angled corner triangle uses only two adjacent borders rather than three. For example, a top-left corner triangle uses border-top: 40px solid #color and border-right: 40px solid transparent. This creates a diagonal slice across a rectangular corner.

In modern browsers, border miters are rendered with sub-pixel anti-aliasing. However, on non-retina displays, diagonal borders may occasionally exhibit slight jaggedness. Applying transform: rotate(0.01deg) or will-change: transform triggers GPU layer rasterization that smooths diagonal edges.

Yes, you can animate border-width and border-color transitions, or apply transform: rotate(), scale(), and translate() for smooth 60fps accordion arrow rotations (e.g., rotating 180 degrees when an accordion panel expands).

Border triangles work by collapsing an element to 0px and coloring one border, which is universally supported even back to IE6. Clip-path triangles use clip-path: polygon(50% 0%, 0% 100%, 100% 100%) on an actual container with real dimensions, allowing the triangle to clip background images, gradients, and child text.