If you want to make a hexagon in CSS first set up your div. We are going to give our div an id of hexagon.
<div id="hexagon"></div>
Next we will style the div with css.
<style>
#hexagon {
width: 100px;
height: 55px;
background: brown;
position: relative;
}
#hexagon:before {
content: "";
position: absolute;
top: -25px;
left: 0;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 25px solid brown;
}
#hexagon:after {
content: "";
position: absolute;
bottom: -25px;
left: 0;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 25px solid brown;
}
</style>

Make a Hexagon in CSS

When we see the code in action we can start taking away from the code to see how each part works. This is a good way to learn how to edit and Make a Hexagon in CSS!

Sign Up To Comment