The best way to generate a simple CSS triangle is to use a zero-width, zero-height element with two transparent borders for the slopes and one colored border pointing in the required direction.
For a small, solid, straight-edged interface shape, this method is compact and dependency-free because it needs no image file, SVG, canvas, or pseudo-element library. It is not the best choice for curved tips, hollow forms, gradients, strokes, complex shadows, or arbitrary polygons; those requirements are better handled with SVG or clip-path tested in the intended browsers.

When the zero-size border method fits
With the border method, the triangle is painted geometry rather than ordinary box content. The element keeps a zero-size content box, two transparent borders form the sloping sides, and a colored border forms the point. The visible area still occupies space because it is painted by the borders.
Because each border property is written explicitly, the result can be reviewed directly in a stylesheet. MDN's CSS backgrounds and borders guide explains the border properties and transparent colors used by this technique. The CSS Backgrounds and Borders Level 3 specification defines the underlying longhand properties, including border widths, styles, and colors.
How direction and dimensions map to borders
The selected direction determines which border receives the solid color. The other two contributing borders remain transparent.
| Direction | Colored border | Transparent borders |
|---|---|---|
| Up | Bottom | Left and right |
| Down | Top | Left and right |
| Left | Right | Top and bottom |
| Right | Left | Top and bottom |
In the generator, width and height describe the visible shape rather than the content box. For an up or down triangle, the two 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.
Odd totals are divided into adjacent whole-pixel values so browser quantization does not remove a pixel from the requested size. For a 41-pixel base, the calculation is floor(41 ÷ 2) + ceil(41 ÷ 2) = 20 pixels + 21 pixels = 41 pixels. This avoids Chromium reducing two 20.5-pixel borders to 20 pixels each. Rasterization can still vary slightly with zoom level and device pixel ratio.
Generate and copy a CSS triangle
- Open the CSS Triangle Generator and choose whether the triangle should point up, down, left, or right.
- Set the visible width and height to whole values from 10 through 300 pixels. Choose a color using a hash followed by exactly six hexadecimal digits. The generator normalizes the color to lowercase and rejects unsupported directions, malformed colors, decimals, and out-of-range values rather than clamping them or producing partial code.
- Inspect the live result at approximately the size and on the background where it will appear. The preview uses the same derived border declarations that appear in the CSS output, so it provides a direct check of the generated geometry.
- Use the separate Copy CSS and Copy HTML controls to copy both parts of the snippet. Each format requests clipboard permission independently, and a successful status identifies the format copied. If browser policy denies access, both code blocks remain available for manual selection instead of reporting a false success.
- Paste the CSS and HTML into the project as a matching pair. The generated HTML contains one div with the generated class and aria-hidden set to true. If the class lizely-triangle conflicts with an existing stylesheet, rename it in both outputs so the selector and markup continue to match.
- Review the triangle's purpose after copying it. Preserve the decorative accessibility treatment for a purely visual shape, or provide visible text or an accessible label on a surrounding semantic control when the triangle communicates information.
Generation and copying happen entirely in the current browser tab. The tool does not upload files, require an account, render the result on a server, or save a design for later, so keep the copied code in the project's normal source files.
Check dimensions and layout after copying
A CSS border triangle behaves differently from an image or an SVG with an explicit viewBox. Its measurable content box is zero, while its painted borders occupy actual space. That difference can make alignment, overflow, transforms, outlines, hit testing, and surrounding layout less intuitive, especially when the triangle is positioned close to text or inside a button.
The generator preview confirms border geometry, not the complete behavior of the destination component. After pasting the code, check the shape in the actual layout and account for the painted border footprint rather than its empty content box. Make sure a parent does not clip the visible area and that the triangle does not overlap nearby content. Also inspect the result at the intended display size because zoom and device pixel ratio can affect rasterization.
Keep the triangle accessible for its purpose
The generated HTML uses aria-hidden="true", which is appropriate for a decorative arrow or separator that conveys no information on its own. It prevents assistive technology from announcing an element that has no useful accessible name or role.
That treatment is not sufficient when the shape communicates state, direction, validation, navigation, or another meaning. In that case, do not rely on the silent div alone. Add visible text or an accessible label to the surrounding semantic interactive control, and keep the decorative triangle hidden from assistive technology. For a focused decision on this point, see when aria-hidden is correct for a CSS triangle.
Use another technique for complex geometry
A border triangle cannot directly create a rounded tip, curved edge, hollow shape, gradient fill, stroke, complex shadow, or arbitrary polygon. Choose a technique according to the required result rather than forcing every shape into the border model.
| Requirement | More suitable technique |
|---|---|
| Small solid arrow, caret, or separator | Zero-size CSS border triangle |
| Rounded tip, curved edge, or hollow shape | SVG or clip-path |
| Arbitrary polygon | SVG or clip-path |
| Gradient fill, explicit stroke, or complex shadow | SVG or clip-path, with browser support tested |
| Explicit vector sizing through a viewBox | SVG |
The focused generator accepts one opaque six-digit HEX color and does not generate alpha colors, CSS variables, gradients, currentColor, wide-gamut syntax, or theme tokens. After copying the output, replacing the literal color with a trusted design token can improve theming. Verify that the destination supports the token syntax and that the transparent slope borders remain transparent.
Run a final production check
Before shipping the triangle, check the complete component rather than relying on the isolated preview.
- View the result at 200 percent zoom, in high-contrast mode, with forced colors, and at common mobile widths.
- Check light and dark themes instead of assuming the literal color will have suitable contrast in every context.
- Inspect alignment, overflow, transforms, focus outlines, and the surrounding interactive target.
- Keep the generated class unique and update the CSS selector and HTML class together if it must be renamed.
- Consider DOM and paint work when many triangles are present. One triangle has negligible performance cost, but hundreds of decorative elements can add unnecessary work.
Prefer one semantic control with a decorative shape over duplicated hidden controls. This keeps the visual indicator and its accessible purpose in a single, understandable component. Because the generator keeps no saved design state, retain the final CSS and HTML together in your project so the geometry, class name, and markup remain easy to audit and update.
Related reading: What to Review After Generating an SVG Blob for Production.