CSS Triangle Generator

Generate pure CSS triangles and tooltip arrows using transparent border tricks or modern clip-path polygons with 8 directions, custom dimensions, and live preview.

Triangle Preview
Triangle Dimensions
Width (px) 50px
Height (px) 50px
Fill Color

How to Generate CSS Triangles Online

1

Choose Direction

Select from 8 directional orientations (Top, Right, Bottom, Left, or diagonal corners).

2

Adjust Width & Height

Drag the dimension sliders to form equilateral, isosceles, or scalene triangles.

3

Copy CSS Method

Choose between the zero-size border hack or the modern polygon clip-path technique.

Tool Options

8 Cardinal & Diagonal Directions

Generate upward popover arrows, downward dropdown indicators, and corner badges.

Dual CSS Engines

Outputs both traditional transparent border tricks and modern GPU-accelerated clip-path polygons.

Tooltip & Popover Ready

Includes zero-dimension pseudo-element boilerplate for drop-in speech bubble styling.

Your Data Privacy

Web Tool
Privacy-First Architecture
Most of our web tools process your data entirely in-browser. Where server processing is technically required, payloads are evaluated statelessly in-memory and are never stored, saved, or logged.
REST API
Stateless In-Memory Processing
When you use our API endpoints, your requests are processed strictly in-memory without persistent database storage, disk logging, or data retention.
Want to learn more about how we safeguard your information and infrastructure?
Read our full Privacy Policy for detailed security standards, data retention principles, and compliance guarantees.

What does the CSS Triangle Generator do?

The CSS Triangle Generator creates pure CSS directional arrows and geometric triangles for tooltips, speech bubbles, dropdown menus, and navigational indicators. It features 8 direction orientations (Top, Right, Bottom, Left, Top-Left, Top-Right, Bottom-Left, Bottom-Right), custom width/height dimension sliders, live shape rendering, and instant zero-click auto-conversion to both the classic zero-size border trick and modern CSS clip-path: polygon(...) declarations.

Core Concepts

Understanding the two CSS triangle techniques:

  • Transparent Border Trick: An element with width: 0 and height: 0 generates diagonal miter joints when adjacent borders have different colors. Setting 3 sides to transparent and 1 side to a solid color renders a crisp vector triangle compatible with all browsers down to IE6.
  • Modern clip-path: polygon(...): Modern CSS polygon clipping clips standard rectangular boxes (width: 50px; height: 50px;) into precise angular triangles, which supports standard background colors, linear gradients, and box shadows.
  • Tooltip Pseudo-Elements: Positioning triangles absolutely on ::after or ::before pseudo-elements allows seamless popover arrow attachments without adding extra HTML DOM nodes.

How to use the tool?

  1. Select Direction: Click any of the 8 direction buttons (Top, Right, Bottom, Left, etc.).
  2. Adjust Dimensions & Color: Scale the width and height sliders or pick your theme color.
  3. Copy Code: Grab the border hack or clip-path declaration with a single click.

Related Developer Utilities

If you work with CSS design tokens, web styling, and UI components, explore these complementary tools:

REST API Integration

Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/css/triangle-generator) to programmatically calculate CSS border dimensions, clip-path polygons, and tooltip pseudo-element snippets.

API Request Parameters

Name Type Description Example
direction String (Optional) Triangle direction ("top", "right", "bottom", "left", "top-left", "top-right", "bottom-left", "bottom-right"). Default "top". "top"
width Number (Optional) Width in pixels. Default 30. 40
height Number (Optional) Height in pixels. Default 30. 40
color String (Optional) Triangle fill color hex code. Default "#3b82f6". "#3b82f6"

API Request Payload Examples

cURL

curl -X POST https://blueutils.com/api/css/triangle-generator \
  -H "Content-Type: application/json" \
  -d '{
    "direction": "top",
    "width": 40,
    "height": 40,
    "color": "#3b82f6"
  }'

Python

import requests

url = "https://blueutils.com/api/css/triangle-generator"
payload = {
    "direction": "top",
    "width": 40,
    "height": 40,
    "color": "#3b82f6"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String jsonPayload = """
            {
                "direction": "top",
                "width": 40,
                "height": 40,
                "color": "#3b82f6"
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://blueutils.com/api/css/triangle-generator"))
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

API Response Parameters

Name Type Description Example
isValid Boolean Indicates whether triangle calculation succeeded. true
direction String Direction orientation. "top"
borderTriangle Object Border-hack CSS property object (borderWidth, borderColor, cssDeclaration). { ... }
clipPathTriangle Object Modern clip-path CSS object (polygon, cssDeclaration). { ... }
tooltipSnippet String Complete drop-in .tooltip::after pseudo-element boilerplate. ".tooltip::after { ... }"

API Response Payload Examples

Success Response (HTTP 200 OK)

{
  "isValid": true,
  "direction": "top",
  "width": 40,
  "height": 40,
  "color": "#3b82f6",
  "borderTriangle": {
    "borderWidth": "0 20px 40px 20px",
    "borderColor": "transparent transparent #3b82f6 transparent",
    "cssDeclaration": "width: 0;\nheight: 0;\nborder-style: solid;\nborder-width: 0 20px 40px 20px;\nborder-color: transparent transparent #3b82f6 transparent;"
  },
  "clipPathTriangle": {
    "polygon": "polygon(50% 0%, 0% 100%, 100% 100%)",
    "cssDeclaration": "width: 40px;\nheight: 40px;\nbackground-color: #3b82f6;\nclip-path: polygon(50% 0%, 0% 100%, 100% 100%);"
  },
  "tooltipSnippet": ".tooltip::after {\n  content: \"\";\n  position: absolute;\n  width: 0;\n  height: 0;\n  border-style: solid;\n  border-width: 0 20px 40px 20px;\n  border-color: transparent transparent #3b82f6 transparent;\n}"
}

Validation Failure Response (HTTP 400 Bad Request)

{
  "isValid": false,
  "error": "Invalid triangle configuration: direction or dimensions missing."
}

Rate Limit Exceeded Response (HTTP 429 Too Many Requests)

{
  "error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}

Why use an API to generate CSS Triangles?

Integrating the Triangle API into headless UI libraries, component design systems, or AI agents provides key benefits:

  • Automated Tooltip Arrow Calculations: Generates mathematically exact border widths and positioning offsets for popover tails during component build steps.
  • AI Agent Styling & UI Generation: Enables AI frontend agents to construct zero-dimension border hacks or clip-path polygon vectors dynamically without manual trigonometry.
  • Consistent Directional Indicators: Ensures accordion carats, speech bubble tails, and badge ribbons maintain exact aspect ratios across design tokens.

Native Usage

How to compute CSS triangle border rules programmatically across programming environments:

Node.js (JavaScript)

// Calculate CSS border-triangle rules in Node.js
function getCssTriangle(dir, w, h, color) {
  let bw = '', bc = '';
  if (dir === 'top') {
    bw = `0 ${w / 2}px ${h}px ${w / 2}px`;
    bc = `transparent transparent ${color} transparent`;
  } else if (dir === 'bottom') {
    bw = `${h}px ${w / 2}px 0 ${w / 2}px`;
    bc = `${color} transparent transparent transparent`;
  }
  return `width: 0;\nheight: 0;\nborder-style: solid;\nborder-width: ${bw};\nborder-color: ${bc};`;
}

console.log(getCssTriangle('top', 40, 40, '#3b82f6'));

Windows (PowerShell Script)

# Programmatically calculate CSS border triangle
$w = 40; $h = 40; $color = "#3b82f6"
$halfW = $w / 2
$css = "width: 0; height: 0; border-style: solid; border-width: 0 ${halfW}px ${h}px ${halfW}px; border-color: transparent transparent $color transparent;"
Write-Host $css

Python

def create_css_triangle(direction, width, height, color="#3b82f6"):
    half_w = width / 2
    if direction == "top":
        bw = f"0 {half_w}px {height}px {half_w}px"
        bc = f"transparent transparent {color} transparent"
    return f"width: 0;\nheight: 0;\nborder-style: solid;\nborder-width: {bw};\nborder-color: {bc};"

print(create_css_triangle("top", 40, 40))

Java

public class TriangleGenerator {
    public static String createTriangle(String dir, int w, int h, String color) {
        int halfW = w / 2;
        String bw = "0 " + halfW + "px " + h + "px " + halfW + "px";
        String bc = "transparent transparent " + color + " transparent";
        return "width: 0;\nheight: 0;\nborder-style: solid;\nborder-width: " + bw + ";\nborder-color: " + bc + ";";
    }

    public static void main(String[] args) {
        System.out.println(createTriangle("top", 40, 40, "#3b82f6"));
    }
}

Frequently Asked Questions (FAQ)

How do I generate a CSS triangle online?

Select your desired direction (Top, Right, Bottom, Left, or Corners), adjust width and height sliders, and pick your fill color to output border or clip-path CSS.

How does the transparent border triangle trick work?

Setting width and height to 0 and applying solid colored borders against transparent adjacent borders forms diagonal miter vector edges.

Does it support clip-path polygon triangles?

Yes. The tool generates modern clip-path: polygon(...) declarations that support gradient fills and standard CSS box models.

Rate Limits

UI Limits
100 uses per 15 minutes
Max payload size: 5 MB
API Limits
5 requests per 60 minutes
Max payload size: 256 KB
Need higher API rate limits, increased payload sizes, or custom developer solutions?
Contact our engineering team at support@blueutils.com for custom rate limit increases, higher quota allocations, or tailored enterprise integrations.