The future of hexagon shapes
A new and easy way to create hexagon shapes using corner-shape
. As a bonus, you can add a border to it.
It's the only method that works with borders!
.hexagon {
border-radius: 50% / 25%;
corner-shape: bevel;
aspect-ratio: cos(30deg);
border: 8px solid purple; /* the border will follow the shape! */
}
/* OR */
.hexagon {
border-radius: 25% / 50%;
corner-shape: bevel;
aspect-ratio: 1/cos(30deg);
border: 8px solid purple; /* the border will follow the shape! */
}
⚠️ Very limited support (Chrome-only with experimental flag enabled) ⚠️
See the Pen Hexagon shapes (with border!) by Temani Afif (@t_afif) on CodePen.
Until better support use this: A Modern way to create hexagon shapes
More CSS Tips
- How to correctly use if() in CSS Learn how to easily fix an issue you will face when using if().
- How to style a broken image Give a nice visual touch to images that fail to load.