FormatterHQ

CSS Triangle Generator

Create pure CSS triangles for tooltip arrows, carets and ribbons. Pick one of eight directions, set the width, height and color, and copy the CSS.

Loading tool…
Ready.

How to use the CSS Triangle Generator

  1. Pick a Direction: Up, Down, Left, Right or one of the four corners (Top left, Top right, Bottom left, Bottom right).
  2. Set the Width and Height in pixels and choose a Colour.
  3. Check the shape in the live preview, switching the background between Light, Dark and Checker if needed.
  4. Use Copy or Download on the CSS tab, or Copy CSS + HTML and Download HTML demo. Reset restores the defaults.

A CSS triangle generator using the border trick

This CSS triangle generator produces triangles from borders alone, with no images, SVG or clipping. It is the classic technique for tooltip arrows, dropdown carets, speech bubbles and ribbon ends, and it works in every browser. Choose a direction and size, and the tool calculates the four border widths and colors for you.

How the border trick works

An element with width: 0 and height: 0 is drawn entirely from its borders. Where two borders meet, the browser splits the corner diagonally. If you color one border and make its neighbors transparent, only a triangle remains. The colored border's width sets the triangle's height, and the two side borders set its base.

Example output

The default upward triangle, 100px wide and 80px tall:

.triangle {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 50px 80px 50px;
  border-color: transparent transparent #0f766e transparent;
}

Only the bottom border is colored; it is 80px thick, and the left and right borders are each half the width. For left and right arrows the tool splits the height instead: a 12 × 16px right-pointing caret gives border-width: 8px 0 8px 12px. The four corner directions produce right-angled triangles, for example border-width: 80px 100px 0 0 for Top left.

Using a triangle as a tooltip arrow

In practice you rarely add an extra element. Put the triangle on a pseudo-element instead:

.tooltip { position: relative; }
.tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-style: solid;
  border-width: 8px 8px 0 8px;
  border-color: #111827 transparent transparent transparent;
}

Those values are what the generator outputs for a downward triangle 16px wide and 8px tall.

Tips and common mistakes

  • Remember the order. border-width and border-color run top, right, bottom, left. The colored side is the opposite of the direction the arrow points.
  • No gradients or outlines. A border triangle is a single solid color. For a bordered arrow, stack two triangles, one 1px larger behind the other.
  • Anti-aliased edges. Diagonal edges can look slightly jagged at odd sizes; even pixel values usually render more cleanly.
  • Match the box color. For a seamless tooltip, use exactly the same color as the tooltip background.

Border triangle vs clip-path

The border trick is ideal for small, solid arrows. If the triangle needs a gradient, an image fill or a drop shadow that follows its outline, use clip-path: polygon(50% 0%, 100% 100%, 0% 100%) from the CSS clip-path generator instead. Another option for chevrons is a small square with two borders rotated 45 degrees using the CSS transform generator.

Privacy

The triangle is generated in your browser, and nothing is uploaded.

Frequently asked questions

How do I make an equilateral triangle in CSS?
Set the height to about 0.866 times the width, for example 100px wide and 87px tall. With the border trick, that gives three sides of equal length.
Why does my triangle have a visible box or wrong color?
Usually one of the transparent borders was given a color, or the element still has a width, height or padding. The element must be 0 × 0 with only one colored border for a single-direction triangle.
Can I add a border or shadow to a CSS triangle?
Not directly, since the triangle already is a border. Stack a slightly larger triangle in the border color behind it, or apply filter: drop-shadow() to the element for a shadow that follows the triangle shape.
Does the border triangle work in all browsers?
Yes. It only uses basic border properties, which every browser has supported for decades, so no prefixes or fallbacks are needed.

Last updated October 3, 2026

Related tools

CSS Animation Generator Generate CSS @keyframes animations — fade, slide, zoom, bounce, pulse, shake, spin and more — with duration, delay, easing and loop controls. CSS Background Pattern Generator Generate repeating CSS background patterns — stripes, polka dots, checkerboard, grid, zigzag and more — using only gradients, no images. CSS Border Radius Generator Set border-radius per corner in px or %, or shape organic blobs with the 8-value "fancy" border-radius syntax. Live preview and copyable CSS. CSS Box Shadow Generator Design layered CSS box-shadows with sliders for offset, blur, spread, colour and opacity. Supports inset shadows, presets and a Tailwind class. CSS Button Generator Design a CSS button with colours, gradient, padding, radius, border, shadow and hover/focus states, then copy clean HTML and CSS. CSS Clamp Generator (Fluid Typography) Calculate a CSS clamp() value that scales font size or spacing smoothly between two viewport widths, with a table of computed sizes. CSS Cubic Bezier Generator Edit CSS cubic-bezier() easing curves by dragging control points, compare them with standard easings in a live animation and copy the CSS. Glassmorphism CSS Generator Build a frosted-glass (glassmorphism) card with backdrop-filter blur, transparency, saturation and border. Preview it over different backdrops. LESS Compiler Experiment with LESS syntax in an online compiler: live CSS output, highlighted error lines and an optional minified result. LESS Formatter Beautify LESS stylesheets online, including variables, mixins and nested rules. LESS to CSS Converter Convert LESS to CSS online. Compiles variables, mixins and nesting into plain CSS. LESS to SASS Converter Convert LESS to SASS online. Rules sharing a selector are nested automatically.