In my previous article, we tackled ribbons in CSS. The root changed into as soon as to have a basic ribbon pattern the use of a single component and values that enable it to adapt to nonetheless noteworthy convey material it comprises. We established a form with repeating CSS gradients and tailor-lower the ribbon’s ends with clip-path() to total the pattern, then outmoded it and worry up with two ribbon variations: particular person who stacks vertically with straight strands of ribbons and any other that tweaks the form by introducing pseudo-parts.
Look the Pen [Responsive multi-line ribbon shapes](https://codepen.io/t_afif/pen/LYMjNoo) by Temani Afif.
Willing to step issues up a piece? This time, we will have ribbons out of extra advanced shapes in conserving with ones found in my collection of single-component CSS ribbons. We’re making modifications to the predominant form we made earlier than. In preference to completely straight strands of ribbon, we’re making angled cuts out of the form.
Look the Pen [Responsive multi-line ribbon shapes](https://codepen.io/t_afif/pen/NWeYwBK) by Temani Afif.
The Classic Setup
All over as soon as more, all we’re working with is a single component in the HTML:
Your content here
We’re also going to rely on gradients to have the repetition, nonetheless the newcomer, this time, will probably be a CSS conceal. Using masks is the main to increasing such advanced designs.
Let’s no longer omit the utilization of the lh unit. It affords us the pause of 1 line, which is an predominant metric. We are able to already commence by defining our first gradient, which is a equivalent to the one we outmoded in the previous article:
h1 {
--c: #d81a14;
background: linear-gradient(var(--c) 80%, #0000 0) 0 .1lh / 100% 1lh;
}
You’ll take into legend accurate now that this gradient is varied from the one we established in the closing article. That’s because of we’re defending 80% (quite than 70%) of the space earlier than making a tantalizing coloration pause to fleshy transparency for the final 20% of space. That’s why we’re offsetting the gradient by .1lh on the background.

If you happen to are questioning why I am the use of 80%, then there is rarely forever a yelp common sense to my manner. It’s because of I discovered that defending extra space with the coloration and leaving much less space between strains produces a better outcome for my respect. I will be able to occupy assigned variables to govern the space with out touching the core code, nonetheless there’s already extra than adequate complexity happening. So, that’s the reasoning at the aid of the tantalizing-coded price.
Styling The First Ribbon
We’ll commence with the red ribbon from the demo. Here’s what we’re making an are attempting to have:

It’ll honest peep advanced, nonetheless we will spoil it down into a mix of general shapes.
Stacking Gradients
Let’s commence with the gradient configuration, and below is the final outcome we’re aiming for. I am adding a tiny transparency to better scrutinize both gradients.

h1 {
--c: #d81a14;
padding-inline: .8lh;
background:
/* Gradient 1 */
linear-gradient(var(--c) 80%, #0000 0)
0 .1lh / 100% 1lh,
/* Gradient 2 */
linear-gradient(90deg, color-mix(in srgb, var(--c), #000 35%) 1.6lh, #0000 0)
-.8lh 50% / 100% calc(100% - .3lh) repeat-x;
}
We already know all concerning the first gradient because of we region it up in the closing piece. The 2d gradient, nonetheless, is positioned at the aid of the first one to simulate the folded piece. It uses the the same coloration variable as the first gradient, nonetheless it’s blended with black (#000) in the color-mix() characteristic to darken it a smidge and have depth in the folds.
The component with the 2d gradient is that we enact no longer need it to reach the pause and bottom of the component, which is why its top is equal to calc(100% - .3lh).
Expose the use of padding in the inline route, which is required to lend a hand far from text working into the ribbon’s folds.
Covering The Folded Aspects
Now, it’s time to introduce a CSS conceal. If you happen to peep carefully at the have of the ribbon, you’ll take into legend that we’re cutting triangular shapes from the perimeters.

Now we occupy applied a triangular form on the left and factual aspects of the ribbon. No longer like the backgrounds, they repeat every two strains, giving us the advanced repetition we need.
Imagine for a 2d that these parts are transparent.

That will give us the closing form! We are able to enact it with masks, nonetheless this time, let’s strive the use of conic-gradient(), which is ideal because of it lets in us to have triangular shapes. And since there’s one form on all aspects, we’ll use two conical gradients — one for the left and one for the factual — and repeat them in the vertical route.
mask:
conic-gradient(from 225deg at .9lh, #0000 25%, #000 0)
0 1lh / 50% 2lh repeat-y,
conic-gradient(from 45deg at calc(100% - .9lh), #0000 25%, #000 0)
100% 0 / 50% 2lh repeat-y;
Each and every gradient covers half the width (50%) and takes up two strains of text (2lh). Additionally, show cloak the 1lh offset of the first gradient, which is what lets in us to alternate between the two as the ribbon adapts in dimension. It’s involving noteworthy a zig-zag pattern and, guess what, I if truth be told occupy an editorial that covers have zig-zag shapes with CSS masks. I extremely imply reading that for additional context and apply making use of masks with conical gradients.
Covering The Ribbon’s Ends
We’re nearly finished! All we’re lacking are the ribbon’s lower edges. Here’s what now we occupy got up to now:
Look the Pen [First ribbon shape](https://codepen.io/t_afif/pen/XWOrNaa) by Temani Afif.
Seek that the cutout parts of the ribbon are hidden by the conceal. Now we occupy so that that you must well add extra gradients to the conceal to peep them. Let’s commence with the one at the pause of the ribbon, as illustrated below.

We are able to occupy that in by adding a third gradient to the conceal:
mask:
/* New gradient */
linear-gradient(45deg, #000 50%, #0000 0) 100% .1lh / .8lh .8lh no-repeat,
conic-gradient(from 225deg at .9lh, #0000 25%, #000 0)
0 1lh / 50% 2lh repeat-y,
conic-gradient(from 45deg at calc(100% - .9lh), #0000 25%, #000 0)
100% 0 / 50% 2lh repeat-y;
That linear gradient will give us the lacking piece at the pause, nonetheless we quiet want to enact the the same at the bottom, and right here, it’s a piece tricky because of, unlike the pause piece, the bottom is no longer static. The cutout can also be either on the left or the factual in conserving with the collection of strains of text we’re working with:

We are able to occupy in these lacking parts with two extra gradients. Below is a demo the set I use varied colours for the newly added gradients to peep precisely what’s taking place. Utilize the resize handle to peep how the ribbon adjusts when the collection of strains modifications.
Look the Pen [Illustrating the full mask configuration](https://codepen.io/t_afif/pen/RwvboJO) by Temani Afif.
Look that? The bottom piece of the ribbon is positioned in this type of technique that it is miles obscured by the fold on the left aspect when there is a ideal collection of strains and revealed when there is an peculiar collection of strains. The reverse is factual of the factual aspect, permitting us to hide one aspect or the opposite as the collection of strains modifications.
If we invent the general colours the the same, the look is ideal!
Look the Pen [Illustrating the full mask configuration](https://codepen.io/t_afif/pen/eYxBZdv) by Temani Afif.
We are able to optimize the code a tiny and change the two bottom gradients with most entertaining one conical gradient, nonetheless that can lead to spacing system defects, so I received’t use it. Here is a demo for instance the premise, while you are outlandish:
Look the Pen [Illustrating the full mask configuration](https://codepen.io/t_afif/pen/mdvbpYK) by Temani Afif.
Placing It All Collectively
Here is all the pieces we worked on in the first ribbon assign collectively. It’s a kind of gradients, nonetheless now you know the cause of each and every.
h1 {
--c: #d81a14;
padding-inline: 1lh;
mask:
linear-gradient(45deg, #0000 50%, #000 0)
0% calc(100% - .1lh) / .8lh .8lh no-repeat,
linear-gradient(-45deg, #0000 50%, #000 0)
100% calc(100% - .1lh) / .8lh .8lh no-repeat,
linear-gradient(45deg, #000 50%, #0000 0)
100% .1lh / .8lh .8lh no-repeat,
conic-gradient(from 225deg at .9lh, #0000 25%, #000 0)
0 1lh / 51% 2lh repeat-y,
conic-gradient(from 45deg at calc(100% - .9lh), #0000 25%, #000 0)
100% 0 / 51% 2lh repeat-y;
background:
linear-gradient(var(--c) 80%, #0000 0)
0 .1lh / 100% 1lh,
linear-gradient(90deg, color-mix(in srgb, var(--c),#000 35%) 1.6lh, #0000 0)
-.8lh 50% / 100% calc(100% - .3lh) repeat-x;
}
Sooner than we plod to the 2d ribbon, I if truth be told occupy a problem for you: Are you able to area which values that you must well possibly possibly switch to region the ribbon in the reverse form? This could well possibly well possibly be your homework. You should well possibly well possibly continually earn the resolution over at my ribbon collection, nonetheless give it a strive the use of the closing code above.

Styling The Second Ribbon
The 2d ribbon from the demo — the golf green one — is a variation of the first ribbon.

I’m going a tiny bit faster this time spherical. We’re working with most of the the same solutions and solutions, nonetheless you’ll scrutinize how quite easy it is miles to have variations with this manner.
The main component to enact is so that that you must well add some space on the pause and bottom for the cutout piece. I’m making use of a transparent border for this. The thickness needs to be equal to half the pause of 1 line (.5lh).
h1 {
--c: #d81a14;
border-block: .5lh solid #0000;
padding-inline: 1lh;
background: linear-gradient(var(--c) 80%, #0000 0) 0 .1lh / 100% 1lh padding-box;
}

Expose how the background gradient is made up our minds to duvet most entertaining the padding space the use of padding-box.
Now, unlike the first ribbon, we’re going so that that you must well add two extra gradients for the vertical items that have the folded darker areas.
h1 {
--c: #d81a14;
border-block: .5lh solid #0000;
padding-inline: 1lh;
background:
/* Gradient 1 */
linear-gradient(var(--c) 80%, #0000 0) 0 .1lh / 100% 1lh padding-box,
/* Gradient 2 */
linear-gradient(#0000 50%, color-mix(in srgb, var(--c), #000 35%) 0)
0 0 / .8lh 2lh repeat-y border-box,
/* Gradient 3 */
linear-gradient(color-mix(in srgb, var(--c), #000 35%) 50%, #0000 0)
100% 0 / .8lh 2lh repeat-y border-box;
}

Seek how the closing two gradients are region to duvet the general space with a border-box. The pause of each and every gradient needs to equal two strains of text (2lh), while the width could possibly well honest quiet be in conserving with the pause of each and every horizontal gradient. With this, we assign the folded parts of the ribbon and likewise prepare the code for increasing the triangular cuts in the foundation and stop of the ribbon.
Here is an interactive demo the set you shall be ready to resize the container to peep how the gradient responds to the collection of strains of text.
Look the Pen [CodePen Home
Gradient configuration of the second ribbon](https://codepen.io/t_afif/pen/JjxPEdw) by Temani Afif.
Gradient configuration of the 2d ribbon by Temani Afif.
The following step is to conceal the left and factual aspects of the ribbon the use of the the same conical gradients that we region up for the red ribbons. We’ve already figured it out!

Making use of most entertaining the conic gradients will even conceal the cutout piece, so I if truth be told occupy to introduce a third gradient to be obvious they remain considered:
mask:
/* New Gradient */
linear-gradient(#000 1lh, #0000 0) 0 -.5lh,
/* Left Side */
conic-gradient(from 225deg at .9lh, #0000 25%, #000 0)
0 1lh / 51% 2lh repeat-y padding-box,
/* Right Side */
conic-gradient(from 45deg at calc(100% - .9lh), #0000 25%, #000 0)
100% 0 / 51% 2lh repeat-y padding-box;
And the closing contact is to use clip-path for the cutouts at the ends of the ribbon.

Seek how the clip-path is cutting two triangular parts from the bottom to be obvious the cutout is continually considered whether now we occupy got an peculiar and even collection of strains.
Here’s how the closing code looks after we assign all the pieces collectively:
h1 {
--c: #d81a14;
padding-inline: 1lh;
border-block: .5lh solid #0000;
background:
linear-gradient(var(--c) 80%, #0000 0)
0 .1lh / 100% 1lh padding-box,
linear-gradient(#0000 50%, color-mix(in srgb,var(--c), #000 35%) 0)
0 0 / .8lh 2lh repeat-y border-box,
linear-gradient(color-mix(in srgb, var(--c), #000 35%) 50%, #0000 0)
100% 0 / .8lh 2lh repeat-y border-box;
mask:
linear-gradient(#000 1lh, #0000 0) 0 -.5lh,
conic-gradient(from 225deg at .9lh,#0000 25%,#000 0)
0 1lh/51% 2lh repeat-y padding-box,
conic-gradient(from 45deg at calc(100% - .9lh), #0000 25%, #000 0)
100% 0 / 51% 2lh repeat-y padding-box;
clip-path: polygon(0 0, calc(100% - .8lh) 0,
calc(100% - .4lh) .3lh,
100% 0, 100% 100%,
calc(100% - .4lh) calc(100% - .3lh),
calc(100% - .8lh) 100%, .8lh 100%, .4lh calc(100% - .3lh), 0 100%);
}
I challenged you to earn a technique to reverse the route of the first ribbon by adjusting the gradient values. Strive to enact the the same component right here!

It’ll honest sound tantalizing. If you happen to would admire a lifeline, you shall be ready to accept the code from my on-line collection, nonetheless it’s the correct dispute to achieve what we’re doing. Explaining issues is staunch, nonetheless nothing beats practising.
The Final Demo
Here is the demo all as soon as more to peep how all the pieces comes collectively.
Look the Pen [Responsive multi-line ribbon shapes](https://codepen.io/t_afif/pen/NWeYwBK) by Temani Afif.
Wrapping Up
There we plod, two extra ribbons that have off of these we created collectively in the first article of this transient two-piece collection. If there’s most entertaining one component you’re taking far from these articles, I hope it’s that contemporary CSS affords us with extremely effective instruments that supply varied, extra sturdy approaches to issues we outmoded to enact a truly very lengthy time ago. Ribbons are an shapely example of a lengthy-living have pattern that’s been spherical lengthy adequate to expose how increasing them has evolved over time as new CSS facets are released.
I will be able to expose you that the two ribbons we created listed right here are possibly basically the most tantalizing shapes in my collection of ribbon shapes. But while you shall be ready to wrap your head sooner or later of the utilization of gradients — no longer most entertaining for backgrounds nonetheless masks and clipping paths as nicely — you’ll earn that you shall be ready to have every other ribbon in the collection with out my code. It’s getting over that preliminary hurdle that makes this have of component anxious.
You now occupy the instruments to invent your have faith ribbon patterns, too, so why no longer give it a strive? If you happen to enact, please part them in the feedback so I will be able to scrutinize your work!
Extra Reading On 4ndsMag
- “Abolish Responsive Image Effects With CSS Gradients And factor-ratio,” Stephanie Eckles
- “Impressed Blueprint Choices With Alexey Brodovitch,” Andrew Clarke
- “Gradients, Blend Modes, And A For sure Chilly Wing End,” Preethi Sam
- “A Deep CSS Dive Into Radial And Conic Gradients,” Ahmad Shadeed
(gg, yk)