Categories
CSS Web development

CSS Bubbles

CSS Bubble

I’ve got a lot of emails regarding my tutorial “How to create Bubbles in Photoshop” and I would like to thank you all for warm words! I am really happy to hear that this tutorial helped you with your work! It keeps me motivated. Some of you asked me to prepare the tutorial on how to create Bubbles in CSS, so here we are today! Ta-daaaah! CSS Bubbles tutorial is ready! Please follow the steps below and create awesome bubbles on your web page.

*animation opened in the Firefox browser.
To see the live output of the animation click here.
  1. Add HTML
  2. Add CSS
  3. Add CSS Animation

Step1.

Add HTML

Create the container and add some bubbles:

<div class="container">
  <div class="bubbles">
    <div class="bubble1"></div>
    <div class="bubble2"></div>
    <div class="bubble3"></div>
    <div class="bubble4"></div>
    <div class="bubble5"></div>
    <div class="bubble6"></div>
    <div class="bubble7"></div>
    <div class="bubble8"></div>
    <div class="bubble9"></div>
    <div class="bubble10"></div>
  </div>
</div>

Step2.

Add CSS

Set the position and the colour of the background, and the container:

body {
  background-color: #00b4d8; 
  overflow-x: hidden;
  height: 100vh;
  
}
.container {
  position: relative;
  z-index: -10;
  top:0;
  
}

Style the bubbles:

.bubbles {
  position: fixed;
  opacity:0.9;
}

.bubble1 {
  position: absolute; 
  width: 100px;
  height: 100px;
  background-color: rgba(255,255,255,0.2);
  border-radius: 50%;
  box-shadow:  inset -7px -7px 15px rgba(255, 255, 255, 0.3), 5px 5px 3px rgba(0,0,0,0.07);
  overflow:hidden;
  animation: up 18s linear infinite;
  top:600px;
  left:1000px;
  
}

.bubble1:after {
  content:"";
  position: absolute;
  background-color: rgba(255,255,255,0.4);
  border-radius:50%;
  width:25px;
  height:50px;
  left:15px;
  top:12px;
  transform: rotate(25deg);
  filter: blur(8px);
}

.bubble2 {
  position: absolute; 
  width: 50px;
  height: 50px;
  background-color: rgba(255,255,255,0.2);
  border-radius: 50%;
  box-shadow:  inset -7px -7px 15px rgba(255, 255, 255, 0.3), 5px 5px 3px rgba(0,0,0,0.07);
  overflow:hidden;
  left:800px;
  top: 700px;
  animation: up 20s linear infinite;
}

.bubble2:after {
  content:"";
  position: absolute;
  background-color: rgba(255,255,255,0.6);
  border-radius:50%;
  width:12.5px;
  height:25px;
  left:15px;
  top:7px;
  transform: rotate(25deg);
  filter: blur(8px);
}

.bubble3 {
  position: absolute; 
  width: 80px;
  height: 80px;
  background-color: rgba(255,255,255,0.2);
  border-radius: 50%;
  box-shadow:  inset -7px -7px 15px rgba(255, 255, 255, 0.3), 5px 5px 3px rgba(0,0,0,0.07);
  overflow:hidden;
  left:1200px;
  top:800px;
  animation: up 25s linear infinite;
}

.bubble3:after {
  content:"";
  position: absolute;
  background-color: rgba(255,255,255,0.4);
  border-radius:50%;
  width:20px;
  height:40px;
  left:15px;
  top:10px;
  transform: rotate(25deg);
  filter: blur(7px);
}

.bubble4 {
  position: absolute; 
  width: 30px;
  height: 30px;
  background-color: rgba(255,255,255,0.2);
  border-radius: 50%;
  box-shadow:  inset -5px -5px 8px rgba(255, 255, 255, 0.3), 5px 5px 3px rgba(0,0,0,0.07);
  overflow:hidden;
  animation: up 27s linear infinite;
  left:800px;
  top: 700px;
}

.bubble4:after {
  content:"";
  position: absolute;
  background-color: rgba(255,255,255,0.8);
  border-radius:50%;
  width:10px;
  height:8px;
  left:7px;
  top:5px;
  transform: rotate(25deg);
  filter: blur(5px);
}

.bubble5 {
  position: absolute; 
  width: 90px;
  height: 90px;
  background-color: rgba(255,255,255,0.2);
  border-radius: 50%;
  box-shadow:  inset -7px -7px 15px rgba(255, 255, 255, 0.3), 5px 5px 3px rgba(0,0,0,0.07);
  overflow:hidden;
  left:350px;
  top:700px;
  animation: up 23s linear infinite;
}

.bubble5:after {
  content:"";
  position: absolute;
  background-color: rgba(255,255,255,0.4);
  border-radius:50%;
  width:22px;
  height:48px;
  left:15px;
  top:12px;
  transform: rotate(25deg);
  filter: blur(7px);
}

.bubble6 {
  position: absolute; 
  width: 70px;
  height: 70px;
  background-color: rgba(255,255,255,0.2);
  border-radius: 50%;
  box-shadow:  inset -7px -7px 15px rgba(255, 255, 255, 0.3), 5px 5px 3px rgba(0,0,0,0.07);
  overflow:hidden;
  left:750px;
  top:700px;
  animation: up 15s linear infinite;
}

.bubble6:after {
  content:"";
  position: absolute;
  background-color: rgba(255,255,255,0.4);
  border-radius:50%;
  width:22px;
  height:48px;
  left:15px;
  top:12px;
  transform: rotate(25deg);
  filter: blur(7px);
}

.bubble7 {
  position: absolute; 
  width: 50px;
  height: 50px;
  background-color: rgba(255,255,255,0.2);
  border-radius: 50%;
  box-shadow:  inset -7px -7px 15px rgba(255, 255, 255, 0.3), 5px 5px 3px rgba(0,0,0,0.07);
  overflow:hidden;
  left:-400px;
  top: 700px;
  animation: up 20s linear infinite;
}

.bubble7:after {
  content:"";
  position: absolute;
  background-color: rgba(255,255,255,0.6);
  border-radius:50%;
  width:12.5px;
  height:25px;
  left:15px;
  top:7px;
  transform: rotate(25deg);
  filter: blur(8px);
}

.bubble8 {
  position: absolute; 
  width: 80px;
  height: 80px;
  background-color: rgba(255,255,255,0.2);
  border-radius: 50%;
  box-shadow:  inset -7px -7px 15px rgba(255, 255, 255, 0.3), 5px 5px 3px rgba(0,0,0,0.07);
  overflow:hidden;
  left:-600px;
  top:800px;
  animation: up 8s linear infinite;
}

.bubble8:after {
  content:"";
  position: absolute;
  background-color: rgba(255,255,255,0.4);
  border-radius:50%;
  width:20px;
  height:40px;
  left:15px;
  top:10px;
  transform: rotate(25deg);
  filter: blur(7px);
}

.bubble9 {
  position: absolute; 
  width: 30px;
  height: 30px;
  background-color: rgba(255,255,255,0.2);
  border-radius: 50%;
  box-shadow:  inset -5px -5px 8px rgba(255, 255, 255, 0.3), 5px 5px 3px rgba(0,0,0,0.07);
  overflow:hidden;
  animation: up 27s linear infinite;
  left:600px;
  top: 700px;
}

.bubble9:after {
  content:"";
  position: absolute;
  background-color: rgba(255,255,255,0.8);
  border-radius:50%;
  width:10px;
  height:8px;
  left:7px;
  top:5px;
  transform: rotate(25deg);
  filter: blur(5px);
}

.bubble10 {
  position: absolute; 
  width: 90px;
  height: 90px;
  background-color: rgba(255,255,255,0.2);
  border-radius: 50%;
  box-shadow:  inset -7px -7px 15px rgba(255, 255, 255, 0.3), 5px 5px 3px rgba(0,0,0,0.07);
  overflow:hidden;
  left:-350px;
  top:700px;
  animation: up 13s linear infinite;
}

.bubble10:after {
  content:"";
  position: absolute;
  background-color: rgba(255,255,255,0.4);
  border-radius:50%;
  width:22px;
  height:48px;
  left:15px;
  top:12px;
  transform: rotate(25deg);
  filter: blur(7px);
}

Step3.

Add CSS Animation

@keyframes up {
  100% { transform: translateY(-1000px);} 
}

To see the live output go to lenastanley.com.

Enjoy coding!