惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
小众软件
小众软件
Engineering at Meta
Engineering at Meta
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
V2EX
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Google DeepMind News
Google DeepMind News
Security Archives - TechRepublic
Security Archives - TechRepublic
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
酷 壳 – CoolShell
酷 壳 – CoolShell
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Help Net Security
Martin Fowler
Martin Fowler
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
V
Vulnerabilities – Threatpost
云风的 BLOG
云风的 BLOG
博客园_首页
C
Cybersecurity and Infrastructure Security Agency CISA
量子位
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
I
Intezer
Scott Helme
Scott Helme
A
About on SuperTechFans
博客园 - 司徒正美
Hacker News: Ask HN
Hacker News: Ask HN
The GitHub Blog
The GitHub Blog
Forbes - Security
Forbes - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 聂微东
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Spread Privacy
Spread Privacy
T
Tailwind CSS Blog
S
Security Affairs
宝玉的分享
宝玉的分享

CSS Articles by Temani Afif

Get Ready For the Powerful CSS border-shape Property! | CSS-Tricks Let’s Play With Gap Decorations! How to Control Infinite CSS Animations (Part 2 of 2) How to Control Infinite CSS Animations (Part 1 of 2) Two Circles, One Arrow, and Anchor Positioning Making a Responsive Pyramidal Grid With Modern CSS | CSS-Tricks How to Create a CSS-only Elastic Text Effect Making Complex CSS Shapes Using shape() | CSS-Tricks Responsive Hexagon Grid Using Modern CSS | CSS-Tricks Responsive List of Avatars Using Modern CSS (Part 2) | CSS-Tricks Responsive List of Avatars Using Modern CSS (Part 1) | CSS-Tricks Perfectly Pointed Tooltips: To The Corners Perfectly Pointed Tooltips: All Four Sides Perfectly Pointed Tooltips: A Foundation Sequential linear() Animation With N Elements | CSS-Tricks Infinite Marquee Animation using Modern CSS Better CSS Shapes Using shape() — Part 4: Close and Move | CSS-Tricks Drawing CSS Shapes using corner-shape Better CSS Shapes Using shape() — Part 3: Curves | CSS-Tricks Better CSS Shapes Using shape() — Part 2: More on Arcs | CSS-Tricks Better CSS Shapes Using shape() — Part 1: Lines and Arcs | CSS-Tricks Creating Blob Shapes using clip-path: shape() Creating Flower Shapes using clip-path: shape() Custom progress element using the attr() function A CSS-Only Star Rating Component and More! (Part 2) | CSS-Tricks A CSS-Only Star Rating Component and More! (Part 1) | CSS-Tricks Full-Bleed Layout with Modern CSS Fancy Menu Navigation Using Anchor Positioning | CSS-Tricks How to Create a Zig-Zag Box Using CSS How to Create Zig-Zag CSS Loaders Using One Element Custom Progress Element Using Anchor Positioning & Scroll-Driven Animations How to Create Filling CSS Loaders Using One Element How to Create Curved-Edge and Rounded-Edge Shapes Using CSS CSS Tricks That Use Only One Gradient | CSS-Tricks How to create Shapes with Inner Curves using CSS Mask Custom Range Slider Using Anchor Positioning & Scroll-Driven Animations How to Get the Width/Height of Any Element in Only CSS How Keyboard Navigation Works in a CSS Game How To Create Cut-Out Shapes using The clip-path property The Modern Guide For Making CSS Shapes — Smashing Magazine css-shape.com: The Ultimate Collection of CSS-only Shapes ⚡️ Sliding 3D Image Frames In CSS — Smashing Magazine CSS Tricks To Master The clip-path Property Creating Wavy Circles with Fancy Animations in CSS Modern CSS Tooltips And Speech Bubbles (Part 2) — Smashing Magazine Do you need a Tooltip or a Speech Bubble? I have created 100 using CSS 😲 Modern CSS Tooltips And Speech Bubbles (Part 1) — Smashing Magazine Creating Flower Shapes using CSS Mask & Trigonometric Functions CSS Shapes: The Triangle The Complex But Awesome CSS border-image Property — Smashing Magazine CSS Tricks to add 3D Effects to your Text CSS Responsive Multi-Line Ribbon Shapes (Part 2) — Smashing Magazine CSS Responsive Multi-Line Ribbon Shapes (Part 1) — Smashing Magazine I have made 100+ CSS-only Ribbon Shapes | The Perfect Collection 🎀 How to create a CSS-only infinite scroll animation Re-Creating The Pop-Out Hover Effect With Modern CSS (Part 2) — Smashing Magazine Re-Creating The Pop-Out Hover Effect With Modern CSS (Part 1) — Smashing Magazine How to Create CSS Ribbon Shapes with a Single Element CSS Shapes: The Ribbon Revealing Images With CSS Mask Animations — Smashing Magazine css-loaders.com: The Biggest Collection of Loading Animations (more than 500 🤯) How To Define An Array Of Colors With CSS — Smashing Magazine CSS effects on images II Shines, Perspective, And Rotations: Fancy CSS 3D Effects For Images — Smashing Magazine What's your Lucky CSS Pattern? Check It Now! How to Add a CSS Reveal Animation to Your Images Modern Layouts using CSS Grid I created 100+ unique CSS patterns | The best collection 🤩 How to Create a Custom Range Slider Using CSS CSS Shapes: The Heart CSS Shapes: Polygon & Starburst A Text Reveal Animation using CSS CSS Tip: learn CSS the easy way! How to build a CSS-only accordion How to create Breadcrumb Navigation with CSS Different Ways to Get CSS Gradient Shadows | CSS-Tricks A CSS-only responsive Stepper component A Fancy Hover Effect For Your Avatar | CSS-Tricks How to make a zoom effect using CSS Creating a Custom Cursor using CSS CSS Infinite 3D Sliders | CSS-Tricks CSS Infinite Slider Flipping Through Polaroid Images | CSS-Tricks How to create a responsive sidebar menu using CSS CSS Infinite and Circular Rotating Image Slider | CSS-Tricks Making Static Noise From a Weird CSS Gradient Bug | CSS-Tricks CSS Grid and Custom Shapes, Part 3 | CSS-Tricks Fancy Image Decorations: Outlines and Complex Animations | CSS-Tricks Fancy Image Decorations: Masks and Advanced Hover Effects | CSS-Tricks Fancy Image Decorations: Single Element Magic | CSS-Tricks How to create an infinite image slider using CSS How to Create Wavy Shapes & Patterns in CSS | CSS-Tricks How I Made a Pure CSS Puzzle Game | CSS-Tricks How to create a Tooltip/Speech Bubble using CSS CSS Grid and Custom Shapes, Part 2 | CSS-Tricks CSS Grid and Custom Shapes, Part 1 | CSS-Tricks Zooming Images in a Grid Layout | CSS-Tricks How to create a CSS-only loader with one element Exploring CSS Grid’s Implicit Grid and Auto-Placement Powers | CSS-Tricks How to create background pattern using CSS & conic-gradient Single Element Loaders: The Bars | CSS-Tricks
How to Create Wavy Boxes Using CSS
2025-02-06 · via CSS Articles by Temani Afif

Wavy box

Written on by Temani AfifWeb Developer

Estimated read time 5 minutes

After the Zig-Zag boxes, it’s time to create wavy boxes! More cool shapes that you can use to decorate your images or any content. We will study two types of shapes illustrated below:

Wavy boxes using CSS

As usual, you can find the codes for the different shapes within my online collection but follow along to understand the logic behind creating them.

As for the HTML, it’s a single element like most of the CSS shapes I create. It’s either an image:

<img src="" alt="">

Or any element with text content (or any kind of content):

<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi quam sem, tincidunt a enim sed, suscipit feugiat diam. Cras mollis ligula orci, a rhoncus dolor volutpat eget.</div>

wavy boxes with text content

Creating the First Wavy box

I will start with the shape on the right which I also call a Wiggly box. We will be using CSS mask and gradients. I think it’s no more a surprise if it comes to CSS shapes. It’s either clip-path or a mask with gradients.

The result is obtained with only three simple gradients and let’s start with the first one:

Overview of the first gradient

It’s a basic radial-gradient clipped to the padding area to leave the border area empty.

.wiggly-box {
  --s: 30px;  /* control the size of the wave */
  --w: 400px; /* preferred image width */
  
  width: round(var(--w),4*var(--s));
  aspect-ratio: 1;
  border: calc(2*var(--s)) solid #0000;
  box-sizing: border-box;
  mask: 
    radial-gradient(var(--s),#0000 100%,#000) padding-box
     var(--s) var(--s)/calc(2*var(--s)) calc(2*var(--s));
}

Nothing complex so far. We are using a variable --s to easily control the shape by adjusting one value. It controls the size/dimension of this first gradient (and the others as well) and also the width that needs to be a multiplier of 4*S.

Then we add a second gradient that will fill the inner area. We fill the inside circles while leaving the outside curves to get the following.

Overview of the second gradient

We define a single-color gradient placed at the center with a dimension that leaves a space equal to 3*S around it.

.wiggly-box {
  /* same as before */
  mask: 
    conic-gradient(#000 0 0) no-repeat
     50%/calc(100% - 6*var(--s)) calc(100% - 6*var(--s)),
    radial-gradient(var(--s),#0000 100%,#000) padding-box
     var(--s) var(--s)/calc(2*var(--s)) calc(2*var(--s));
}

The final gradient is another radial-gradient that will complete the puzzle!

Overview of the third gradient

.wiggly-box {
  /* same as before */
  mask: 
    radial-gradient(var(--s),#000 100%,#0000) 
     0 0/calc(4*var(--s)) calc(4*var(--s)),
    conic-gradient(#000 0 0) no-repeat
     50%/calc(100% - 6*var(--s)) calc(100% - 6*var(--s)),
    radial-gradient(var(--s),#0000 100%,#000) padding-box
     var(--s) var(--s)/calc(2*var(--s)) calc(2*var(--s));
}

Now, you apply this to your images and you get a fancy decoration:

overview  of the intersect composition

Note how I am able to easily use a gradient coloration. I am also adding some padding (in addition to the existing border) to make sure the waves don’t overlap the image. There is no particular logic with the padding. It simply needs to be bigger than 1*S to avoid the overlap.

We can also consider a slightly different implementation if we want to have rounded corners on the images like below:

overview  of the intersect composition

The first implementation won’t work with rounded corners because the radius will affect the first gradient layer (the one clipped to the padding area). To overcome this, I replace it with two layers that give the same result.

Overview of all the gradients

Instead of clipping the area of the gradient using padding or border, I consider another gradient and I perform an intersect composition between them. In other words, we take only the visible part of both of them.

img {
  mask: 
    radial-gradient(var(--s),#000 100%,#0000) 
     0 0/calc(4*var(--s)) calc(4*var(--s)),
    conic-gradient(#000 0 0) no-repeat 
     50%/calc(100% - 6*var(--s)) calc(100% - 6*var(--s)),
    /* the new gradient layer */
    conic-gradient(#000 0 0) no-repeat 
     50%/calc(100% - 4*var(--s)) calc(100% - 4*var(--s)) intersect,
    /* will intersect with the below layer*/
    radial-gradient(var(--s),#0000 100%,#000) 
     var(--s) var(--s)/calc(2*var(--s)) calc(2*var(--s));
}

Now, we have two radial gradients and two conic gradients. The conic gradients are almost identical so we can simplify the code by adding a variable to avoid repetition:

img {
  --_g:conic-gradient(#000 0 0) no-repeat 50%/;
  mask: 
    radial-gradient(var(--s),#000 100%,#0000 calc(100% + 1px)) 
     0 0/calc(4*var(--s)) calc(4*var(--s)),
    var(--_g) calc(100% - 6*var(--s)) calc(100% - 6*var(--s)),
    var(--_g) calc(100% - 4*var(--s)) calc(100% - 4*var(--s)) intersect,
    radial-gradient(var(--s),#0000 calc(100% - 1px),#000) 
     var(--s) var(--s)/calc(2*var(--s)) calc(2*var(--s));
}

overview  of the intersect composition

Creating the Second Wavy box

The second wavy box relies on the same gradient configuration: two radial gradients and one conic gradient. Here is a figure to illustrate all of them.

Overview of all the gradients

A first radial gradient will create the outside curves but will also have those inner circles that we hide with the second gradient (a conic gradient). Then, the third gradient will complete the puzzle.

The three gradients above each other

The code will be as follows:

.wavy-box {
  --s: 30px;  /* control the size of the wave */
  --w: 400px; /* preferred  width */
  
  width: round(var(--w),4*var(--s)); 
  aspect-ratio: 1;
  padding: var(--s);
  border: var(--s) solid #0000;
  box-sizing: border-box;
  mask: 
    radial-gradient(calc(sqrt(2)*var(--s)),#000 100%,#0000),
    conic-gradient(#0000 0 0) content-box,
    radial-gradient(calc(sqrt(2)*var(--s)),#0000 100%,#000) 
     var(--s) var(--s) padding-box;
  mask-size: calc(var(--s)*4) calc(var(--s)*4);
}

This time, two gradients are clipped. The radial-gradient is clipped to the padding area like the previous shape and the conic-gradient is clipped to the content area.

With this implementation, we can also have rounded corners for images:

overview  of the intersect composition

But if you want the shape to apply to the whole image, we have to rely on a different implementation where we can remove the padding and border.

overview  of the intersect composition

See the Pen by Temani Afif () on .

We introduce a fourth gradient and we perform the same intersect composition we did with the previous shape. I let you dissect the code alone as a small exercise.

Conclusion

As I did with the Zig-Zag boxes, I will end with a last demo showing an image gallery of wavy images!

overview  of the intersect composition

Temani Afif

Temani Afif is an expert web developer, a content creator, and a CSS addict. He is the mastermind behind CSS Loaders, CSS Generators, CSS Tip and many other CSS-related websites.

View more posts by Temani Afif