Here’s a step-by-step explanation of the HTML and CSS code you provided:
Step 1: HTML Structure
The HTML code begins with the <!DOCTYPE html> declaration, which specifies the document type. The document’s root element is <html>, and it contains two main sections: <head> and <body>.
Step 2: Head Section
The <head> section contains metadata about the document and external resources used. In this case, it includes the following elements:
<meta charset="utf-8">: Specifies the character encoding for the document.<meta name="viewport" content="width=device-width, initial-scale=1">: Sets the viewport properties for responsive design.<title>Background Animation</title>: Sets the title of the web page, which appears in the browser’s title bar.
Step 3: CSS Styling
The CSS styles are defined within <style> tags. The CSS code sets various styles for different elements in the document. Here’s a breakdown of the main styles used:
*: Applies the styles to all elements, setting padding and margin to 0 and using the border-box sizing model.body: Sets the background color to black and the text color to white, with a minimum height of 100vh (viewport height)..container: Positions the container element relatively and sets its width and height to 100% and 100vh, respectively. It also hides any overflow.h1: Centers the heading text, gives it a margin, sets its position to relative, and adjusts the font size..bubbles: Positions the bubbles container relatively and sets its display to flex, allowing the bubbles to be arranged horizontally..bubbles span: Styles the individual bubbles. It sets their position to relative, width and height to 30px, and applies a background color and box shadow. It also sets an animation for the bubbles to create the background animation effect. The--icustom property is used to control the animation duration for each bubble, and its value is set using thestyleattribute in the HTML.
Step 4: Body Section
The <body> section contains the actual content of the web page. It starts with a <div> element with a class of “container” that wraps the heading and the bubbles.
- Inside the container, there’s an
<h1>heading element with the text “Background Animation”. - After the heading, there’s a
<div>element with a class of “bubbles”. Inside this div, there are multiple<span>elements, each representing a bubble. Thestyleattribute of each<span>sets the--icustom property to control the animation duration for that specific bubble.
That’s it! This HTML and CSS code creates a web page with a background animation effect using bubbles. The bubbles move from the bottom to the top of the page, creating a visually appealing animation.
Source codes:


