Creating a cloud in CSS is one of those classic exercises that, besides looking great visually, helps you understand key concepts like pseudo-elements, positioning, and organic shapes with border-radius.
In this tutorial, I will teach you how to create a simple CSS cloud using only HTML and CSS, without images, without SVG, and without external libraries.
The idea is clear: a decorative cloud, easy to reuse, and perfect for practicing CSS shapes and using pseudo-elements.
The HTML structure we are going to use is minimal: a div with id="cloud" that acts as the main body of the cloud, and inside it a span with the class shadow to simulate the shadow cast on the ground:

<div id = "cloud"><span class='shadow'></span></div>What exactly we are going to build
Before starting, I want to clarify something important. When I tried different techniques to make clouds in CSS, I realized that it doesn't always make sense to use SVG or complex animations. If you just need a decorative cloud, pure CSS is more than enough.
In this case, we are going to create:
- A cloud made with a single
div - Volume using
::beforeand::after - Shadow with
box-shadow - A slight gradient with
linear-gradientto give it depth
How to achieve the characteristic bumps of a CSS cloud with ::before and ::after?
The pseudo-elements ::before and ::after are the key to getting those rounded swellings that characterize clouds, without adding more elements to the HTML. For this, we apply different dimensions and border-radius to each, giving us two circles of different sizes that protrude from the top of the cloud body:
#cloud:after {
width: 100px; height: 100px;
top: -50px; left: 50px;
border-radius: 100px;
}
#cloud:before {
width: 200px; height: 200px;
top: -90px; right: 50px;
border-radius: 200px;
}We create a couple of round bumps of different sizes; but for the top and right properties to take effect, it is necessary for the pseudo-element to have defined positioning. Without it, the browser completely ignores those coordinates. The shared rules between both pseudo-elements look like this:
#cloud:after, #cloud:before {
content: '';
position: absolute;
background: #FFF;
z-index: -1
}We position them with position: absolute and assign a z-index of -1 so they stay behind the main body of the cloud. Without this value, the internal borders of the circles would be visible and the cloud would look like this:

The CSS for the main body of the cloud is very simple:
#cloud {
width: 350px; height: 120px;
background: #BFF;
background: linear-gradient(top, #BFF 5%, #DFF 100%);
top: 50px; left: 50px;
border-radius: 100px;
position: absolute;
margin: 120px auto 20px;
}Here are several important details:
- The large
border-radiusis what gives us the base oval shape - The
linear-gradientprovides a subtle volume effect - The
positionis mandatory, and this is something I learned through trial and error: if you do not position the container, the pseudo-elements do not align correctly with it
This flaw is one of the most common when someone tries to create a cloud in CSS for the first time.
Why position is so important in a CSS cloud
This point deserves emphasis. For top, left, or right to work on a child pseudo-element, the container element must have defined positioning. Valid options are:
position: relativeposition: absoluteposition: fixed
If you don't do this, the pseudo-elements will be placed relative to the document and not the container, and the cloud will completely fall apart. It is a very typical mistake when starting to work with ::before and ::after.
Applying the gradient to the CSS cloud
We apply the gradient with linear-gradient. To ensure compatibility with older browsers, the background is declared first with a flat fallback color and then overwritten with the gradient. Thus, if the browser does not support gradients, it will simply display the solid color defined earlier.
Finally, the cast shadow, which is the part handled by span.shadow:
.shadow {
width: 350px;
position: absolute; bottom: -10px;
background: #000;
z-index: -1;
box-shadow: 0 0 25px 8px rgba(0, 0, 0, 0.4);
border-radius: 50%;
}Here box-shadow does almost all the work. The combination of a dark background, the blur of the shadow, and border-radius: 50% generates a blurred ellipse that simulates the shadow of a cloud on the ground very well. There's no need to complicate things further if you are just looking for a simple CSS cloud.
Final result and recommendations
With all this, you already have a CSS cloud created entirely in pure CSS, without images or SVG. It is a lightweight solution, easy to adapt, and perfect for small projects or as a learning exercise for CSS shapes.
When I started practicing this type of shapes, it helped me a lot to experiment later with small variations:
- Change colors to simulate storm clouds or sunset clouds
- Adjust sizes to create large and small clouds within the same scene
- Create multiple clouds reusing the same CSS class with different modifiers
- Combine it with CSS animations like
@keyframesto move the clouds automatically
Frequently asked questions about creating clouds in CSS
- Can you create a cloud in CSS without images?
- Yes, perfectly. With a
div,border-radius,::before/::afterpseudo-elements, andbox-shadowyou can create great-looking clouds without a single image.
- Yes, perfectly. With a
- Is it better to use CSS or SVG for a cloud?
- It depends on the case. For something decorative and simple, CSS is faster to implement and easier to maintain. SVG makes sense when you are looking for realistic clouds, complex animations, or fully customized shapes.
- What are
::beforeand::afterused for in this example?- They are used to create the top bumps of the cloud without adding more elements to the HTML. They are virtual nodes generated by CSS that behave like independent elements.
- Why does my CSS cloud look bad?
- It is normally due to one of these three reasons:
- Not using
positionon the parent container - Not adjusting the
z-indexof the pseudo-elements correctly - Too small values in
border-radiusthat break the rounded shape
Conclusion
Creating a cloud in CSS is a perfect exercise to improve your understanding of positioning, pseudo-elements, and shadows. With a minimal HTML structure and a few well-understood rules, you can achieve highly visual results without relying on external images or libraries.
If you keep practicing this type of examples, creating more complex CSS shapes will become increasingly natural and intuitive.
Next step, keep practicing creating shapes with CSS and HTML: circles, squares, trapezoids, and other geometric figures.