To create a CSS triangle, set an element’s content width and height to zero, make two borders transparent, and give the third border a solid color. The visible shape is painted entirely by the borders, so no image file, SVG, canvas, or pseudo-element library is required.

The CSS Triangle Generator applies this border technique. You can choose a direction, visible width and height, and six-digit HEX color, then copy synchronized CSS and HTML. Generation and copying happen in the current browser tab, with no upload, account, server rendering, or saved design state.

css create triangle
CSS Create Triangle: Direction, Dimensions, and Code

Choose the right border for each direction

The direction depends on which border receives the solid color. The other two borders remain transparent and create the sloping sides.

Direction Solid border Transparent borders
Up Bottom Left and right
Down Top Left and right
Left Right Top and bottom
Right Left Top and bottom

For example, an upward triangle uses a colored bottom border with transparent left and right borders. The generator writes the relevant border longhands explicitly, making the geometry visible and easier to audit than a compressed shorthand rule. Its live preview uses the same derived declarations exposed in the CSS output.

Match width and height to the painted shape

The selected dimensions describe the triangle’s visible painted size, not the zero-size content box. For an up or down triangle, the transparent side borders add up to the selected width, while the colored border equals the selected height. For a left or right triangle, the transparent top and bottom borders add up to the selected height, while the colored border equals the selected width.

Even dimensions divide equally between the two transparent borders. Odd dimensions use adjacent floor and ceiling values to preserve the requested total. For example, a requested 41px base becomes 20px + 21px = 41px instead of two half-pixel borders that Chromium may quantize downward.

Enter whole values from 10 through 300 pixels and a color in strict #RRGGBB form. The generator normalizes accepted colors to lowercase. Unsupported directions, malformed colors, decimals, and out-of-range dimensions are rejected rather than clamped or turned into partial code.

Generate, preview, and copy the code

  1. Open the CSS Triangle Generator and select up, down, left, or right.
  2. Set the visible width and height, then enter a six-digit HEX color such as #336699.
  3. Inspect the live result at approximately the size and on the background where it will appear. The preview confirms the border geometry, but it does not verify the accessibility or complete layout behavior of the destination component.
  4. Review both output blocks. The CSS describes the zero-size element and its border geometry, while the HTML contains one div with the generated class and aria-hidden="true". Preserve or replace that decorative accessibility treatment according to the triangle’s purpose.
  5. Use the separate Copy CSS and Copy HTML controls. Each requests clipboard permission independently, and a successful status identifies the copied format. If browser policy denies clipboard access, both code blocks remain visible for manual selection without a false success message.
  6. Paste the CSS into your stylesheet and the HTML into the document. If the lizely-triangle class conflicts with an existing rule, rename it and update the CSS and HTML together.
  7. Test the finished component at 200 percent zoom, in high-contrast and forced-colors modes, and at common mobile widths. Check the triangle in both light and dark themes before publishing it.

Integrate the snippet without losing meaning

The generated HTML follows this structure: <div class="lizely-triangle" aria-hidden="true"></div>. Hiding that decorative shape from assistive technology is appropriate for an arrow, divider, or ornament that conveys no information. The snippet contains no script, event handler, inline image, remote request, or dependency.

If the triangle communicates state, direction, validation, navigation, or another meaning, do not rely on the silent snippet alone. Put visible text or an accessible label on the surrounding semantic control and keep the decorative triangle hidden from assistive technology. Prefer one labeled semantic control over duplicating hidden interactive elements.

The chosen HEX value is painted as an opaque border. The generator does not create alpha colors, CSS variables, gradients, currentColor, wide-gamut syntax, or theme tokens. After copying, replacing the literal color with a trusted design token can improve theming, but verify that the target syntax is supported and that the side borders remain transparent.

Compare border triangles with SVG and clip-path

Border triangles are compact for simple straight-edged shapes, but they are not general-purpose polygon tools.

Requirement CSS border triangle Alternative
Simple solid triangle Directly supported CSS borders
Rounded tip or curved edge Not supported SVG or clip-path
Hollow shape or visible stroke Not supported SVG or clip-path
Gradient fill Not generated clip-path or SVG
Complex shadow or arbitrary polygon Not supported directly SVG or clip-path

Use SVG or clip-path when the shape needs curves, strokes, gradients, complex shadows, or more than three vertices. Test the chosen technique in the browsers and devices where the page will be used. An SVG can also provide an explicit viewBox, which is useful when the shape must scale predictably within a larger graphic.

Review the finished shape in real conditions

A border triangle has a measurable content box of zero, while its painted borders still occupy space. That distinction can make layout, transforms, hit testing, outlines, overflow, and alignment less intuitive than expected. Inspect those behaviors in the surrounding component rather than judging the isolated preview.

Rasterization can also vary with zoom and device pixel ratio. Confirm the final appearance at 200 percent zoom, in high-contrast and forced-colors modes, and on common mobile widths. One triangle has negligible performance cost, but hundreds of decorative elements can increase DOM and paint work. Keep the number of separate elements reasonable.

Because the tool does not save a design state, retain the copied CSS and HTML or record your chosen direction, dimensions, and color if you need to reproduce the result. MDN’s CSS backgrounds and borders guide documents the relevant border properties and transparent color behavior, while the CSS Backgrounds and Borders Level 3 specification defines the longhand border widths, styles, and colors used by this technique.

Related reading: HTML and CSS Color Names Chart: Filter Rules and Copying.