Cascading style sheet

Create Diagonal Stripes in CSS

We generally encounter striped design in most websites, magazines and flyers. But a diagonal stripe in CSS? How is that even possible?

Yes, it is possible and we are not using a bitmap image or an SVG. We would just rely on CSS’s linear gradient and background-size property.

So let’s begin.

<body style="background: repeating-linear-gradient(45deg,
green 0, green 25%, #58a 0, #58a 50%);
background-size: 42.426406871px 42.426406871px;">
<p>Your text here </p>
</body>

Let’s understand how this worked out.

To understand how we were able to create the diagonal stripe, we need to remember the Pythagorean theorem we learned at school about calculating the lengths of the sides of right triangles.

The theorem states that the hypotenuse (the longest, diagonal side of the triangle) is equal to a2 + b2 where a and b are the lengths of its legs. On a 45° right triangle, both its legs are of the same length, so the formula becomes 2a2 = a 2.

In our diagonal stripes, the background size specifies the length of the hypotenuse, but the stripe width is actually the length of the leg.

This means that to get our original stripe width of 15px, we need to specify a background size of 2 × 15 2 ≈ 42 . 426406871 pixels, which we can safely round off to 42px.

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…

1 hour 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