Back To Tutorials
Page Loader Animation
Intermediatechallenge
In this challenge, you will create a page loader animation using HTML and CSS. The loader should be a visually engaging animation that displays while the page is loading. Common loader designs include spinning circles, bouncing dots, or pulsating elements. Your task is to create a loader that effectively grabs user attention while being stylish and non-intrusive.
Objective:
- Learn how to create smooth and engaging animations using CSS.
- Understand how to use CSS properties and animations to create a visually appealing loader.
Requirements:
- Use HTML and CSS only (no JavaScript).
- Create a loader animation that can be displayed while the page is loading.
- The animation should be smooth, visually appealing, and non-intrusive.
- Ensure the loader is centered on the page and does not affect the page layout.
Steps:
-
HTML Structure:
- Create a
div
element for the loader. - Inside the loader
div
, add any necessary elements for the animation (e.g., additionaldiv
s for different parts of the loader).
- Create a
-
CSS Styling:
- Use CSS properties such as
animation
,keyframes
,border-radius
, andtransform
to create the animation effect. - Style the loader to be visually appealing and ensure it is centered on the page.
- Use CSS properties such as
-
Animation:
- Define CSS keyframes to create the animation effect (e.g., spinning, bouncing, pulsating).
- Apply the animation to the loader element.
-
Testing:
- Ensure the loader animation works correctly and looks good on various screen sizes and devices.
- Make sure the loader does not interfere with the page content or layout.
Resources:
Solution:
Your solution should include:
- A complete HTML and CSS file.
- A page loader animation that is smooth and visually appealing.
- A design that is centered and does not affect the page layout.
<!-- HTML structure -->
<div class="loader"></div>
css
/* CSS for page loader animation */
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f4f4f4;
}
.loader {
width: 80px;
height: 80px;
border: 8px solid #e0e0e0;
border-top: 8px solid #4db8ff;
border-radius: 50%;
animation: spin 1.5s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
Explanation:
- HTML Structure: A single
div
element with the class.loader
represents the loader. - CSS Styling:
.loader
: Sets up the size, border, and border-radius to create a circular loader. Theborder-top
property is used to create the visible spinning effect.@keyframes spin
: Defines the animation to rotate the loader continuously.
- Animation: The
spin
animation smoothly rotates the loader, creating a spinning effect. Thelinear
timing function ensures a consistent rotation speed.
Feel free to adjust the size, colors, and animation speed to fit your design needs.