CSS Layout & Styling Tool

Pure CSS Triangle & Arrow Generator

Create pure CSS directional triangles, tooltip arrows, and popover pointers using zero-overhead CSS border properties without extra images or SVGs.

A CSS triangle generator (or arrow CSS generator) builds directional shapes and tooltip pointers using the CSS box-model border intersection technique. By defining an element with width: 0 and height: 0 and applying solid borders alongside transparent borders, browsers render mathematically crisp, zero-latency vector triangles without images, SVGs, or external fonts.

Generated CSS Code

How Pure CSS Triangles & Arrows Work

In modern web design, micro-elements such as dropdown indicators, tooltip pointers, speech bubble arrows, and breadcrumb carets are universally needed across UI design systems. Instead of loading bitmap images or inflating DOM complexity with embedded SVGs, front-end engineers leverage the geometry of the CSS box model to render pure CSS triangles.

1. The Geometric Mechanics of Zero-Dimension Miter Joints

In the standard W3C CSS box model, adjacent borders do not meet at 90-degree squared corners; they meet at a 45-degree angled miter joint. When a normal container has dimensions (e.g., width: 100px; height: 100px;), the borders frame the perimeter. However, when you reduce both width and height to 0:

  • The internal content box collapses to a single infinitesimal coordinate point.
  • The 4 borders collapse inward, converging directly at the central point.
  • Each border forms a distinct trapezoid whose inner edge has zero length, transforming each border into an exact isosceles triangle.
  • By declaring three of the four borders as solid transparent and assigning a visible color to the fourth, only one triangle remains visible.

2. Complete CSS Triangle & Arrow Formula Matrix

The table below provides the exact CSS border geometry required to render directional triangles and right-angled corner wedges:

Direction Opposite Base Width Apex Altitude Height Solid Color Border Transparent Borders
▲ Triangle Up (North) border-left & border-right: (W/2)px border-bottom: (H)px border-bottom-color: #color border-left, border-right: transparent
▼ Triangle Down (South) border-left & border-right: (W/2)px border-top: (H)px border-top-color: #color border-left, border-right: transparent
◀ Triangle Left (West) border-top & border-bottom: (H/2)px border-right: (W)px border-right-color: #color border-top, border-bottom: transparent
▶ Triangle Right (East) border-top & border-bottom: (H/2)px border-left: (W)px border-left-color: #color border-top, border-bottom: transparent
◤ Corner Top-Left border-right: (W)px border-top: (H)px border-top-color: #color border-right: transparent
◥ Corner Top-Right border-left: (W)px border-top: (H)px border-top-color: #color border-left: transparent
◣ Corner Bottom-Left border-right: (W)px border-bottom: (H)px border-bottom-color: #color border-right: transparent
◢ Corner Bottom-Right border-left: (W)px border-bottom: (H)px border-bottom-color: #color border-left: transparent

3. Architectural Comparison: CSS Borders vs. Clip-Path vs. SVG Arrows

Front-end architects have three primary options for rendering UI pointers and arrows. The table below compares performance, browser compatibility, and styling flexibility across methods:

Evaluation Feature Pure CSS Borders CSS clip-path: polygon() Inline SVG Shapes
Browser Compatibility 100% Universal (Chrome, Safari, Firefox, Edge, IE6+) Modern Browsers (Chrome 55+, Safari 13.1+, Firefox 54+) Modern & Legacy Browsers (All modern platforms)
DOM Overhead Zero extra elements (uses ::after pseudo-element) Zero extra elements (uses pseudo-element or container) Requires inline <svg> element in markup
Gradient / Background Fill Solid colors only (borders cannot receive linear-gradient) Full CSS gradient, image, and backdrop-filter support SVG <linearGradient> defs required
Native Border Outline Requires dual pseudo-elements (outer + inner) Complex (requires layered wrapper or SVG stroke) Native stroke and stroke-width
Box-Shadow Support Requires filter: drop-shadow() (box-shadow creates a square) Requires filter: drop-shadow() Supports filter: drop-shadow()
High-DPI Retina Rendering Ultra crisp; sub-pixel anti-aliasing handled by GPU Crisp polygon rasterization Resolution-independent vector rasterization

4. Implementing Tooltip Arrows with Pseudo-Elements (Step-by-Step Code)

In production design systems, you should avoid adding empty <div class="arrow"></div> tags into HTML templates. Instead, generate the triangle purely inside a ::before or ::after pseudo-element attached to the tooltip container:

/* 1. Parent Tooltip Container */ .tooltip { position: relative; display: inline-block; background-color: #1e293b; color: #ffffff; padding: 8px 16px; border-radius: 6px; font-size: 14px; } /* 2. Top-Pointing CSS Triangle on Bottom Tooltip */ .tooltip::after { content: ""; position: absolute; bottom: 100%; /* Positions arrow right on top edge */ left: 50%; transform: translateX(-50%); /* Centers the arrow horizontally */ width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 6px solid #1e293b; /* Matches tooltip background */ }

5. How to Create an Outlined Tooltip Arrow (Border & Fill)

When your tooltip has a 1px border (e.g., border: 1px solid #38bdf8), a single border triangle will either clip through the outline or look detached. The industry-standard solution is the Dual-Layer Pseudo-Element Pattern:

  • Outer Arrow (::before): Sized with 7px borders and colored with the border outline tone (#38bdf8).
  • Inner Arrow (::after): Sized with 6px borders and colored with the tooltip background tone (#1e293b), offset 1px below ::before.
/* Outer Arrow: Border Stroke */ .tooltip-bordered::before { content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%); width: 0; height: 0; border-left: 8px solid transparent; border-right: 8px solid transparent; border-top: 8px solid #38bdf8; /* Outline color */ z-index: 1; } /* Inner Arrow: Container Fill (1px smaller, sits on top) */ .tooltip-bordered::after { content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%); width: 0; height: 0; border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 7px solid #1e293b; /* Fill color */ z-index: 2; }

6. High-DPI Anti-Aliasing Quirks & Common Pitfalls

  • Faint Gray Fringes on Retina Displays: On WebKit/Blink browsers with high device-pixel-ratios (DPR > 2), transparent borders can occasionally show a faint 1px gray seam due to fractional sub-pixel anti-aliasing. Adding transform: translateZ(0); or backface-visibility: hidden; forces hardware GPU rasterization and eliminates the seam.
  • Accidental Box-Shadow Distortion: Applying standard box-shadow to a CSS triangle element casts a square shadow around the invisible border box. Always use filter: drop-shadow(0 2px 4px rgba(0,0,0,0.25)); on the parent or pseudo-element to trace the actual triangular silhouette.
  • Missing display Declaration: When applying CSS borders to inline elements (like <span>), ensure you declare display: inline-block; or position: absolute;; otherwise, inline geometry may collapse unpredictably across different browsers.

Frequently Asked Questions About CSS Triangles & Arrows

Authoritative technical answers to common questions about CSS border triangles, tooltip positioning, and cross-browser rendering.

Pure CSS triangles exploit the CSS box model's border miter joints. When an element has zero width and zero height, its borders meet directly at the center point at 45-degree angles. By making three borders transparent and giving the opposite border a solid color and thickness, the browser renders an exact, scalable geometric triangle.
Give the parent tooltip container position: relative and attach the CSS triangle properties to an ::after or ::before pseudo-element with content: "", position: absolute, and width: 0; height: 0. Then position the arrow along the tooltip edge using top, bottom, left, or right, and apply transform: translateX(-50%) for perfect centering.
Because border-based triangles cannot accept CSS border properties directly, create an outline using dual stacked pseudo-elements: use ::before for a slightly larger outer triangle colored with the border outline tone, and layer ::after on top with a smaller inner triangle colored with the tooltip surface background, offset by the desired border thickness (e.g., 1px or 2px).
CSS border triangles have 100% universal browser compatibility dating back to Internet Explorer 6 and require zero external paths. In contrast, clip-path: polygon() allows complex multi-point polygons and CSS gradients as fills, but suffers from anti-aliasing seams and cannot easily produce CSS drop shadows without filter: drop-shadow().
Sub-pixel rounding on high-DPI retina displays can cause faint fringe lines on transparent border sides. Fix this by adding transform: translateZ(0) or backface-visibility: hidden to force hardware compositing, or setting border-style: solid with explicit half-pixel adjustments.
Yes. To create a corner badge or diagonal ribbon, set width: 0 and height: 0, choose one horizontal border (e.g., border-right: 40px solid transparent) and one vertical border (e.g., border-top: 40px solid #0099E5), leaving the remaining two borders unset.
Professional Engineering & Consulting

Need a Custom Web App, SaaS Platform, or Automation Tool?

In addition to our free developer utilities, Scenic IT Solutions builds mission-critical web applications, enterprise software systems, and data-driven SEO growth engines for businesses worldwide.

⚡ Web Hosting
Deploy on Hostinger with fast NVMe SSDs & free domain. Up to 75% OFF.
Get 75% Off →
🌊 Cloud VPS
Build scalable apps on DigitalOcean. Free $200 credit.
DigitalOcean Referral Badge
🔍 SEO & Keywords
Find low-competition keywords & track SERP ranks with Mangools.
Try KWFinder Free →

Explore Related Frontend & CSS Tools

Streamline your responsive web design workflow with our suite of modern developer utilities: