Simple Loading Screen using HTML and CSS

Simple Loading Screen using HTML and CSS

CSS Animation property, Position property of CSS and Keyframes are used to make the simple loading screen.

HTML Code for Loading Screen

Two Divs are made in HTML file. A main div and a spinner div. Look at the HTML code below.

<!DOCTYPE html>
<div id="main-div">
 <div id="spinner">

CSS Code for Loading Screen

The CSS Code of simple loading screen is explained below.

Main Div CSS

The main div position property is set to fixed so that loading screen is always over the main content of the page, even if user scrolls the page. It's width and height both are set to 100% to cover the whole page. Background color is also set to black with opacity of 0.5.

position: fixed;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);

Spinner Div CSS

The spinner div is displayed in the center of the main div both vertically and horizontally using position property. It's width and height, both are set to 75px and border radius is set to 50% to make it a circle.

5pxborder is given to spinner div but the top border color is set to transparent which will make it look like a loading icon.

The spinner div is then animated using animation property of CSS. Time Duration is set to 2s, Iteration count is set to infinite to keep rotating it again and again while timing function is set to linear to keep the speed constant through out the process.

position: absolute;
top: 0; bottom: 0; left: 0; right: 0;
margin: auto;
width: 75px;
height: 75px;
border: 5px solid #fff;
border-radius: 50%;
border-top-color: transparent;
animation: spin 2s infinite linear;

KeyFrames for Loading Screen Spinner

After this, keyframes are defined for the animation, keyframes gradually change the style of element from current CSS style to new CSS style.

In our example the spinner div will start it's rotation from 0 degree angle and after 2 seconds it will complete its rotation at 360 degree angle.

@keyframes spin
transform: rotate(0deg);
transform: rotate(360deg);


Video Tutorial

Watch video tutorial below to understand it better.

Pure CSS Custom Radio Buttons Custom Emoji Radio Buttons with CSS Custom Radio Buttons with CSS Engraved HTML Buttons With CSS Neumorphic Buttons Design with CSS Cool Profile Card Design with HTML CSS Neumorphic Search Bar Design with HTML and CSS Simple Login Form with Placeholder Animation Pure CSS Button with Folded Corner Background Color Change Slider with HTML CSS and JavaScript 404 Page Not Found Template Design with HTML and CSS Movies Blog Card Design with HTML and CSS Simple CSS Border Animation with before and after Selector Custom Social Select Dropdown Menu with CSS and JavaScript Facebook Offline and Online Notification with CSS and JS New Year 2022 Text Animation with CSS and JS Change Placeholder Color using CSS Custom Select Tag DropDown with CSS and JavaScript Profile Card With Hover Effect using HTML and CSS Simple Price Range Slider With HTML CSS and JavaScript Circle With Two Colors using CSS Card With Ribbon using HTML and CSS Simple Loading Screen using HTML and CSS Disable Textarea Resizable Property using CSS Button like Links using CSS Simple Dropdown Menu Using HTML and CSS Background Color Transition using CSS Highlight Required Input Fields using CSS Disable HTML Link using CSS Difference Between Descendant Selector and Child Selector How To Change Color and Size of Hr Tag Using CSS How To Center Align HTML Table Convert Checkbox To Toggle Button Using CSS Drawing Stars using HTML and CSS Button Bounce Effect using CSS Image as Text Background using CSS background-clip Property Vertically Rotate HTML Element using CSS Vertical Align Middle using CSS Text Over Image Hover Effect - Css Hover Simple CSS Button Hover Effect using Before Selector