Guide

How to Generate a CSS Triangle with Borders

Use the generator to choose a supported direction and size, then copy its border-based CSS into your stylesheet. Leave fields blank to use up and size 20, while remembering that the supplied color does not affect the emitted border colors.

Tool CSS Triangle Generator

What this CSS triangle generator does

A CSS triangle can be created without an image by combining zero dimensions with borders. This generator produces CSS text for a border-based triangle and lets you provide a direction and size. It can be useful when you need a quick starting point for a badge, pointer, tooltip marker, menu caret, or other small interface shape.

The direction controls the border-width pattern used for the triangle. Supported patterns cover up, down, left, right, top-left, top-right, bottom-left, and bottom-right. Direction and size are optional, so the tool can also provide a default starting point when you do not need custom inputs yet.

How to generate the CSS

  1. Open the CSS Triangle Generator.
  2. Enter a direction if the triangle should point somewhere other than up. Use one of the supported direction values: up, down, left, right, top-left, top-right, bottom-left, or bottom-right.
  3. Enter a size when the default value of 20 does not suit the shape you need. The tool performs arithmetic on this value, including division by two, and places the resulting measurements in pixel units.
  4. Enter a color if your workflow requires that field, then generate the CSS text.
  5. Copy the generated CSS into your stylesheet and adjust the surrounding layout, positioning, or selector usage for your component.

If you leave direction blank, the tool uses up. If you leave size blank, it uses 20. The color field can be filled in, but it does not change the generated border colors in the current behavior, so plan to set the visible color separately if the output needs one.

How to read and check the result

The output uses a zero-width and zero-height element with a solid border style. Its four border widths are expressed in pixels and are calculated from the size value. The triangle’s apparent direction comes from the border-width pattern selected for the supplied direction.

Treat the color input as informational rather than as a way to color the triangle: the generated CSS uses transparent border colors regardless of the supplied color. A separate CSS change may therefore be needed for the visible border that forms the triangle.

An unrecognized direction is not rejected. Instead, its border-width pattern falls back to the upward pattern, while the generated direction-specific selector retains the supplied direction text. Use one of the listed direction values when you want the selector and geometry to correspond predictably. The tool also does not establish a permitted range or positivity check for size values, so review unusual inputs before using the output.

Worked example

You are adding a right-pointing marker beside a settings label and want a 24-unit starting size.

Enter right as the direction, enter 24 as the size, and generate the CSS text for a right-pointing interface marker.

The generated CSS has a selector, zero width and height, a solid border style, pixel-based border widths calculated from the size, and transparent border colors.

Limitations

  • The color input does not control the generated border colors; additional CSS may be needed for a visible triangle color.
  • Unrecognized directions use the upward border-width pattern, and size arithmetic has no reviewed range or positivity check.

Common errors

  • If the triangle remains transparent after you enter a color, the color field is not controlling the emitted border colors. Set the needed border color in the CSS after generating the base shape.

FAQ

Can I generate an upward CSS triangle without entering a direction?

Yes. Leave the direction blank and the generator uses up. Other supported directions include down, left, right, top-left, top-right, bottom-left, and bottom-right.

Does the color input change the triangle color?

The current generated CSS uses transparent border colors, so the supplied color does not control the visible triangle color. Set a border color separately when needed.

What happens when I leave the size blank?

A size of 20 is used when the size input is blank. The resulting border measurements are calculated from the size value and inserted with pixel units.

What happens if I enter an unsupported direction?

An unrecognized direction falls back to the upward border-width pattern, but the selector still reflects the supplied direction text. Use a listed direction value for a corresponding pattern.

Tool

CSS Triangle Generator