Cascading style sheet

Create a Diamond-shaped Image in CSS

It is very common to see cropped images in diamond shapes in visual design. But is it possible to create a diamond-shaped image in CSS?

In fact, one might think it is impossible, so that when web designers want to follow this style, they more often than not pre-crop their images via an image editor.

But this is really not a maintainable way to apply any effect and ends up being a mess if one wants to change the image styling in the future.

So, we are going to create a diamond-shaped image in CSS

Using CSS transform to Create a Diamond-based Image in CSS

we need to wrap our image with a <div>, then apply opposite rotate() transforms to them:

<div class="picture">
<img src="images/image.png" alt="" />
</div>

Then we apply style as follows:

 .picture{
            display: block;
            margin: 0 auto;
            margin-top: 100px;
            width: 400px;
            transform: rotate(45deg);
            overflow: hidden;
        }
        .picture img{
            max-width: 100%;
            transform: rotate(-45deg) scale(1.42);
        }

The main issue is the max-width: 100% declaration. 100% refers to the side of our .picture container.

However, we want our image to be as wide as its diagonal, not its side. You might have guessed that yes, we need the Pythagorean theorem again as we did when we used Diagonal stripes. As the theorem tells us, the diagonal of a square is equal to its side multiplied by

2 ≈ 1 . 414213562. Therefore, it makes sense to set max-width to

2 × 100 % ≈ 141 . 4213562 %, or round it up to 142%, as we don’t want it to be smaller under any circumstances (but slightly larger is OK, as we’re cropping our image anyway).

Actually, it makes even more sense to enlarge the image through a scale() transform, for a couple of reasons:

We want the size of the image to remain 100% if CSS transforms are not supported.

Enlarging an image through a scale() transform will scale it from the center (unless a different transform-origin is specified). Enlarging it via its width property will scale it from the top-left corner, so we will end up having to use negative margins to move it.

Putting it all together, our final code looks like this:

This is how to create a diamond-shaped image in CSS.

Recent Posts

Google Announces that AI-developed Drug will be in Trials by the End of the Year

Isomorphic Labs, a drug discovery start-up launched four years ago and owned by Google’s parent…

4 hours ago

Instagram Extends Reels Duration to 3 Minutes

Regardless of whether TikTok faces a U.S. ban, Instagram is wasting no time positioning itself…

2 days ago

AWS Expands Payment Options for Nigerian Customers, Introducing Naira (NGN) for Local Transactions

Amazon Web Services (AWS) continues to enhance its customer experience by offering more flexible payment…

6 days ago

Why JavaScript Remains Dominant in 2025

JavaScript, often hailed as the "language of the web," continues to dominate the programming landscape…

1 week ago

Amazon Moves to Upgrade Alexa with Generative AI Technology

Amazon is accelerating efforts to reinvent Alexa as a generative AI-powered “agent” capable of performing…

1 week ago

Smuggled Starlink Devices Allegedly Used to Bypass India’s Internet Shutdown

SpaceX's satellite-based Starlink, which is currently unlicensed for use in India, is reportedly being utilized…

1 week ago