How to Easily Create Arrows in CSS
You can tweak around with the border property and transform in CSS to create chevrons:
Copied to clipboard! Playground
.arrow {
display: inline-block;
border: solid #FCA101;
border-width: 0 3px 3px 0;
padding: 3px;
}
.arrow--up { transform: rotate(-135deg); }
.arrow--down { transform: rotate(45deg); }
.arrow--left { transform: rotate(135deg); }
.arrow--right { transform: rotate(-45deg); }
You can also turn the above example into triangles by changing the border property around a bit:
Copied to clipboard! Playground
.triangle-up {
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid #FCA101;
}
.triangle-down {
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #FCA101;
}
.triangle-left {
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-right: 5px solid #FCA101;
}
.triangle-right {
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 5px solid #FCA101;
}
By also combining the above examples with some transforms, you can achieve diagonal triangles:
Copied to clipboard! Playground
.diagonal-triangle {
/* Make sure your element is block level. Otherwise you can't transform it. */
display: inline-block;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid #FCA101;
transform: rotate(45deg);
}
Resource
π More Webtips
Rocket Launch Your Career
Speed up your learning progress with our mentorship program. Join as a mentee to unlock the full potential of Webtips and get a personalized learning experience by experts to master the following frontend technologies:
Courses
CSS - The Complete Guide (including Flexbox, Grid and Sass)
Including Flexbox, Grid, and Sass
Whether you're learning CSS for the first time or brushing up on your CSS skills and diving even deeper, this course is for you. Every web developer has to know CSS.
The HTML & CSS Bootcamp
From Zero to Expert!
This course covers flexbox, CSS grid, animations, responsive design, and much more! You will find tons of exercises & projects inside this course.
The Creative HTML5 & CSS3 Course
Build Awesome Websites
Learn HTML5 and CSS3 by creating three amazing, well-designed and animated websites from scratch.