Explain Codes LogoExplain Codes Logo

Shape with a slanted side (responsive)

web-development
responsive-design
css-tricks
svg-shapes
Alex KataevbyAlex Kataev·Jan 14, 2025
TLDR

Effortlessly create a responsive slanted shape with the clip-path property in CSS:

.slanted { background: #3498db; height: 100px; clip-path: polygon(0 0, 100% 0, 100% 75%, 0 100%); }
<div class="slanted"></div>

Simply tweak the polygon points for different slants.

Methods to build slanted shapes

SVGs - Precision and adaptability at your fingertips

Use SVG shapes for exceptionally sharp and responsive slanted shapes. With polygon or path, design any slanted shape to fit your fancy.

Linear gradients - Dynamic shades for depth illusion

Apply linear gradients in your designs to create perceived depth and a slanted look which auto adjusts based on container dimensions.

transform: skew - Your new favourite CSS trick

Effectively create a slanted edge using the transform: skew on pseudo-elements. It offers an uncanny adaptability to alterations in content.

Perspective transforms - Adding the zing to your design

Give depth and realism to your slanted shapes with the magic wand of perspective transform property. It's a showstopper in responsive designs!

Canvas: For that animation wow factor

Craft interactive or animated slant effects with HTML5 canvas. It's time to be the Picasso of dynamic paths and shapes!

Digging deeper into slanted designs

Playing with dimensions - the viewport units

Use vw, vh viewport units to your advantage for dynamic scaling. It's like fitting your design in all screen sizes at once.

Transparent borders - An ingenious slant strategy

A clever trick to create slanted edges is by using a transparent border on one side of a rectangular element.

Wrangling the scrollbar - The overflow way

Handle potential scrollbar appearances in a responsive design using overflow: auto. It's like setting boundaries for your design on the screen.

Precision positioning - The relative-absolute duo

Employ relative and absolute positioning to layer elements and overlay shapes. Let's play the stacking game!