How to create a triangle in CSS
Triangles are commonly drawn with the border property. Let’s see the process of coming up with a basic triangle.
Steps to create a basic triangle
- Draw a simple square with a big border.
- Reduce the square size to zero, leaving only the border behind.
-
Now divide the border into 4 segments:
- border-top
- border-bottom
- border-left
- border-right
-
Let’s give them different colors for now.
-
To extract a single triangle out of it:
- Delete the opposite triangle.
- Set the adjacent triangles to transparent.
For example, to retrieve the bottom triangle, delete the top triangle, and set the left and right triangles to transparent.
- Note that you can directly get 4 different right-angled triangles by picking up 2 triangles, rather than just 1, from the original 4.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved