A reliable CSS triangle depends on four core settings: direction, visible width, visible height, and one six-digit HEX color. The CSS Triangle Generator turns those choices into a zero-size element whose visible shape is painted by borders. Two transparent borders form the slopes, and one colored border points in the selected direction. The generated CSS and HTML remain synchronized, so the preview reflects the declarations copied into a project. Direction determines which border carries the color, while width and height define the shape's painted extent. The tool accepts whole pixel dimensions from 10 through 300 and requires a hash plus six hexadecimal color characters. It creates an opaque solid triangle without SVG, canvas, an image file, or a pseudo-element library. Before shipping, inspect the preview at the approximate size and background where it will appear, then copy both code blocks. The supplied HTML uses aria-hidden="true", which suits a decorative shape but not one that independently communicates state or direction. For a meaningful triangle, give the surrounding control visible text or an accessible label. The preview verifies border geometry, not the finished component's full layout and accessibility behavior.

The Four Settings Behind the Shape
Direction controls which border receives the visible color. Width and height describe the triangle's painted extent rather than a conventional content area: the element itself stays at zero width and height while its borders create the shape. For an up or down triangle, the left and right border widths add to the selected width, while the colored border equals the selected height. For a left or right triangle, the top and bottom border heights add to the selected height, while the colored border equals the selected width.
| Direction | Colored pointing border | Transparent slope borders |
|---|---|---|
| Up | Bottom | Left and right |
| Down | Top | Left and right |
| Left | Right | Top and bottom |
| Right | Left | Top and bottom |
The generator writes each border longhand explicitly, keeping the geometry visible and auditable. This follows the standard CSS border model: MDN's CSS backgrounds and borders guide documents border properties and transparent colors, while CSS Backgrounds and Borders Level 3 defines the longhand widths, styles, and colors involved.
Generate the CSS and HTML
- Open the CSS Triangle Generator and choose the required direction: up, down, left, or right.
- Set the visible width and height using whole pixel values from 10 through 300. These values describe the triangle's overall painted proportions.
- Enter the color as a hash followed by exactly six hexadecimal digits. Valid values are normalized to lowercase, and malformed colors are rejected rather than converted into an unexpected color.
- Inspect the live result at approximately the size and on a similar background to the place where the triangle will appear. Check the pointing direction, proportions, and visible color rather than relying on the input values alone.
- Use the separate Copy CSS and Copy HTML controls. Each requests clipboard permission independently, and a successful status identifies the format that was copied.
- If browser policy denies clipboard access, keep both code blocks visible and select the required code manually. The page will not report a copy that did not occur.
- Integrate both outputs together, then rename the generated class if necessary and apply the appropriate accessibility treatment for the surrounding component.
Generation and copying happen entirely in the current browser tab. There is no upload, account, server rendering, or saved design state. Ordinary browser controls constrain normal input, while the underlying generator independently rejects unsupported directions, malformed colors, decimals, and values outside the allowed range. It does not quietly clamp invalid programmatic input or emit partial code.
Read the Border Geometry
The live preview uses the same derived border declarations shown in the CSS output. That makes it useful for checking direction, overall proportions, and color, but it does not recreate the spacing, surrounding content, or interaction behavior of the final page component.
Preserve an Odd Base Dimension
An even perpendicular base is divided equally between its two transparent borders. For an odd base total B, the generator uses floor(B / 2) and ceil(B / 2). With B = 41, floor(41 / 2) = 20 and ceil(41 / 2) = 21, so 20px + 21px = 41px. This deliberate one-pixel asymmetry prevents Chromium from quantizing two 20.5px borders down to 20px each and silently losing a pixel. Rasterization can still vary with browser zoom and device pixel ratio, so the destination page should be checked at its actual display scale.
Match Color to the Destination
The selected HEX color becomes an opaque border color. The focused generator does not produce alpha colors, CSS variables, gradients, currentColor, wide-gamut color syntax, or theme tokens. If you still need help comparing options, How to Choose Color When Using a CSS Triangle Generator provides a focused selection checklist.
After copying, replacing the literal color with a trusted design token can improve theme support. Verify that the destination supports the token's syntax and confirm that the transparent slope borders remain transparent. A triangle placed next to text should be reviewed in both light and dark themes rather than assumed to inherit enough contrast. The preview is useful for checking the selected color, but the final surrounding background and text styling determine what users actually see.
Keep the Markup and Meaning in Sync
The HTML snippet contains one div with the generated class and aria-hidden="true". That treatment is appropriate for a decorative arrow or separator that conveys no information. If the triangle communicates state, direction, validation, navigation, or another meaning, do not rely on the silent snippet alone. Add visible text or an accessible label to the surrounding interactive control, while keeping the decorative shape hidden from assistive technology.
The generated class is lizely-triangle. If that name conflicts with an existing stylesheet, rename it in the CSS and HTML together. The snippet contains no script, event handler, inline image, remote request, or dependency, which keeps the copied element focused on presentation. Its accessibility suitability still depends on the purpose assigned to the shape in the surrounding interface.
Match the Technique to the Shape
A border triangle is best suited to a simple, solid, straight-edged shape. More demanding geometry needs another approach rather than extra border declarations.
| Requirement | Border-triangle result | Alternative |
|---|---|---|
| Rounded tip or curved edge | Not generated | SVG or clip-path |
| Hollow shape or stroke | Not generated | SVG |
| Gradient fill or complex shadow | Not generated | SVG or clip-path |
| Arbitrary polygon | Not generated | SVG or clip-path |
For requirements outside a solid border triangle, use SVG or clip-path and test browser support in the intended environment. Even for a simple triangle, the measurable content box is zero while the painted borders occupy space. Layout, transforms, hit testing, outlines, overflow, and alignment can therefore be less intuitive than with an SVG that has an explicit viewBox. The performance cost of one decorative triangle is negligible, but hundreds of decorative elements can increase DOM and paint work. Prefer one semantic control with a decorative shape over duplicated hidden controls.
Run a Final Page-Level Check
- Confirm that the triangle points in the intended direction and that its visible width and height suit the destination.
- Inspect it at the approximate final size and on the actual background or theme.
- Rename the generated class in both outputs if it could conflict with an existing rule.
- Keep aria-hidden only when the shape is decorative; otherwise provide accessible text or labeling on the surrounding control.
- Check the final result at 200 percent zoom, in high-contrast and forced-colors modes, and at common mobile widths.
- Use SVG or clip-path instead when the design needs curves, strokes, gradients, a hollow form, or arbitrary polygon geometry.
The preview confirms the generated border geometry, not the complete accessibility or layout behavior of the destination component. Treat it as the final shape check, then verify the integrated result in the page where it will actually be used.
For a deeper look, see Convert Hex to RGB for CSS: Exact Values for Stylesheets.