Create Indian Flag using HTML and CSS
Last Updated :
24 Oct, 2021
In this article, we will design an animated flag of India using HTML and CSS. As we know that our Indian flag has three colors saffron, white and green and there is also a wheel at the center of the white part. So let’s build the Indian flag. Here we will also create a stick of the flag. So first create a wrapper div (class named wrapper) that holds two divs class named stick and flag.
HTML
< div class = "wrapper" >
< div class = "stick" ></ div >
< div class = "flag" ></ div >
</ div >
|
The stick and the flag should be inline so we make the wrapper div’s display property to flex. And add some height, width, background-color, border styles to the stick, and in the flag, add height, width, box-shadow, background-color, and position properties.
CSS
.wrapper {
display : flex;
}
.stick {
height : 450px ;
width : 10px ;
background : black ;
border-top-left-radius: 10px ;
border-bottom-left-radius: 5px ;
border-bottom-right-radius: 5px ;
}
.flag {
width : 270px ;
height : 180px ;
box-shadow: 0px 0px 90px 1px #989 ;
background-color : transparent ;
position : relative ;
}
|
Till now it look like this:

Now design the flag part. The flag part is made of three parts, So make three div’s and classes named top, middle, and bottom.
HTML
< div class = "wrapper" >
< div class = "stick" ></ div >
< div class = "flag" >
< div class = "top" ></ div >
< div class = "middle" ></ div >
< div class = "bottom" ></ div >
</ div >
</ div >
|
Now add height and background-color property to the top, middle, and bottom divs.
CSS
. top {
height : 60px ;
background-color : #ff9933
}
. middle {
height : 60px ;
background-color : white
}
. bottom {
height : 60px ;
background-color : green
}
|
Now our flag looks like this:

Now it’s time to create a wheel so, the wheel is nothing but a div inside the div, class named middle. In the wheel, we create 12 span elements class named ‘line’.
HTML
< div class = "flag" >
< div class = "top" ></ div >
< div class = "middle" >
< div class = "wheel" >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
</ div >
</ div >
< div class = "bottom" ></ div >
</ div >
|
For styling the wheel, firstly we have to perfectly center the wheel inside the middle div by using flex properties. And design the wheel div by adding height, width, border, border-radius, position. And also design the span elements by adding the height width, position, ‘left’, background, etc properties. And rotate every line item by using :nth-child(n) selector and transform: rotate(angle) property, every rotation should be at the difference of 15 degrees.
CSS
.wheel {
height : 43px ;
width : 43px ;
border : 1px solid darkblue;
border-radius: 45px ;
position : relative ;
margin : 0 auto
}
.wheel .line {
height : 100% ;
width : 1px ;
display : inline- block ;
position : absolute ;
left : 50% ;
background : darkblue;
}
.line:nth-child( 1 ) {
transform: rotate( 15 deg)
}
.line:nth-child( 2 ) {
transform: rotate( 30 deg)
}
.line:nth-child( 3 ) {
transform: rotate( 45 deg)
}
.line:nth-child( 4 ) {
transform: rotate( 60 deg)
}
.line:nth-child( 5 ) {
transform: rotate( 75 deg)
}
.line:nth-child( 6 ) {
transform: rotate( 90 deg)
}
.line:nth-child( 7 ) {
transform: rotate( 105 deg)
}
.line:nth-child( 8 ) {
transform: rotate( 120 deg)
}
.line:nth-child( 9 ) {
transform: rotate( 135 deg)
}
.line:nth-child( 10 ) {
transform: rotate( 150 deg)
}
.line:nth-child( 11 ) {
transform: rotate( 165 deg)
}
.line:nth-child( 12 ) {
transform: rotate( 180 deg)
}
|
Now our complete Indian flag looks like this:

Add some animations: Till now we have created a complete but static flag, now it’s time to create some animations. Here we will add two animations, the first ss wheel rotation animation and the second is wave animation.
Adding wheel rotation animation: To add wheel rotation, we use the transform: rotate(angle) property, making the animation duration 10 seconds, animation timing function linear, and running the animation infinite times.
CSS
.wheel {
animation-name: wheel;
animation-iteration-count: infinite;
animation-duration: 5 s;
animation-timing-function: linear;
}
@keyframes wheel {
0% {
transform: rotate( 0 deg);
}
100% {
transform: rotate( 360 deg);
}
}
|
Now our Indian flag looks like this:

Adding wave animation: Now add the wave animation. For this animation, we create a separate div and add it into the flag div (because we overlay this div inside the flag div only, not in ‘stick’). Add position: absolute, height, and width set to 100%, and add a gradient background-image and change the background positions to animate.
CSS
.wave {
position : absolute ;
height : 100% ;
width : 100% ;
background-image : linear-gradient(
128 deg, rgba( 89 , 72 , 21 , 0 ) 39% ,
rgba( 250 , 245 , 245 , 0.8474025974025974 )
46% , rgba( 89 , 72 , 21 , 0 ) 53% );
animation-name: wavy;
animation-duration: 10 s;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
@keyframes wavy {
0% {
background-position : -400px 0px ,
-400px 0px , -400px 0px , -400px 0px ;
}
100% {
background-position : 800px 0px ,
800px 0px , 800px 0px , 800px 0px ;
}
}
|
Complete code: The complete code of HTML and CSS to design Indian National Flag.
HTML
<!DOCTYPE html>
< html >
< head >
< link rel = "stylesheet" href = "style.css" >
</ head >
< body >
< div class = "wrapper" >
< div class = "stick" ></ div >
< div class = "flag" >
< div class = "wave" ></ div >
< div class = "top" ></ div >
< div class = "middle" >
< div class = "wheel" >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
< span class = "line" ></ span >
</ div >
</ div >
< div class = "bottom" ></ div >
</ div >
</ div >
</ body >
</ html >
|
CSS
.wrapper {
display : flex;
}
.stick {
height : 450px ;
width : 10px ;
background : black ;
border-top-left-radius: 10px ;
border-bottom-left-radius: 5px ;
border-bottom-right-radius: 5px ;
}
.flag {
width : 270px ;
height : 180px ;
box-shadow: 0px 0px 90px 1px #989 ;
background-color : transparent ;
position : relative ;
}
. top {
height : 60px ;
background-color : #ff9933
}
. middle {
height : 60px ;
display : flex;
justify- content : center ;
align-items: center ;
}
. bottom {
height : 60px ;
background-color : green
}
.wheel {
height : 43px ;
width : 43px ;
border : 1px solid darkblue;
border-radius: 45px ;
position : relative ;
margin : 0 auto ;
animation-name: wheel;
animation-iteration-count: infinite;
animation-duration: 5 s;
animation-timing-function: linear;
}
.wheel .line {
height : 100% ;
width : 1px ;
display : inline- block ;
position : absolute ;
left : 50% ;
background : darkblue;
}
.line:nth-child( 1 ) {
transform: rotate( 15 deg)
}
.line:nth-child( 2 ) {
transform: rotate( 30 deg)
}
.line:nth-child( 3 ) {
transform: rotate( 45 deg)
}
.line:nth-child( 4 ) {
transform: rotate( 60 deg)
}
.line:nth-child( 5 ) {
transform: rotate( 75 deg)
}
.line:nth-child( 6 ) {
transform: rotate( 90 deg)
}
.line:nth-child( 7 ) {
transform: rotate( 105 deg)
}
.line:nth-child( 8 ) {
transform: rotate( 120 deg)
}
.line:nth-child( 9 ) {
transform: rotate( 135 deg)
}
.line:nth-child( 10 ) {
transform: rotate( 150 deg)
}
.line:nth-child( 11 ) {
transform: rotate( 165 deg)
}
.line:nth-child( 12 ) {
transform: rotate( 180 deg)
}
@keyframes wheel {
0% {
transform: rotate( 0 deg);
}
100% {
transform: rotate( 360 deg);
}
}
.wave{
position : absolute ;
height : 100% ;
width : 100% ;
background-image : linear-gradient(
128 deg, rgba( 89 , 72 , 21 , 0 ) 39% ,
rgba( 250 , 245 , 245 , 0.8474025974025974 )
46% , rgba( 89 , 72 , 21 , 0 ) 53% );
animation-name: wavy;
animation-duration: 10 s;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
@keyframes wavy {
0% {
background-position :
-400px 0px , -400px 0px ,
-400px 0px , -400px 0px ;
}
100% {
background-position : 800px 0px ,
800px 0px , 800px 0px , 800px 0px ;
}
}
|
Output:

Similar Reads
Create an Icon Bar using HTML and CSS
This article provides a complete idea of how to create an Icon Bar using HTML and CSS. HTML is used to design the structure, and CSS applies styles to the elements to make the user interface (UI) attractive. To add the Icons, we use the Font Awesome icons CDN link in the head section, and add the ic
2 min read
Create a Curtain Menu using HTML and CSS
This article will show you how to create a Curtain menu navbar effect with the help of HTML and CSS. The curtain menu means revealing or pulling down the menu items like a curtain. HTML is used to create the structure of the curtain menu and applies styles on that element to make like curtain menu e
3 min read
Create a Testimonial Card Using HTML and CSS
In this tutorial, we're going to create a testimonial card that can be used on websites to display feedback from clients or customers. Testimonials are an excellent way to add social proof to your site, enhancing credibility and trust among visitors. Weâll create a testimonial card with: A speech bu
4 min read
Create GeeksforGeeks logo using HTML and CSS
Creating a logo using HTML and CSS involves designing graphical elements with HTML tags, styling them using CSS properties such as colors, sizes, and positions, and possibly incorporating SVG graphics or images. This approach allows for custom, scalable, and interactive logo designs on web pages. Ge
2 min read
Create a Galaxy Background using HTML/CSS
In this article, we will see how to create the galaxy background using the HTML & CSS, along with knowing the basic CSS properties used & will understand it through the example. A galaxy background means a small bunch of circles having different sizes with different shades and a dark backgro
3 min read
How to create a mega menu using HTML and CSS ?
HTML is a markup language used to create web pages and CSS is a stylesheet language used to design a document written in a markup language such as HTML. In this article, we are going to know how can we create a mega menu on our web page with the help of only HTML and CSS. Mega menus are a type of ex
4 min read
How to Create Pricing Table using HTML and CSS ?
Nowadays, every website contains pricing tables, such as e-commerce, e-tech, and even tourism websites also have pricing tables as they contain their plans, cost of plans, and information about plans to buy new facilities. So the pricing table is one of the most important parts of websites that sell
3 min read
How to Create Badges using HTML and CSS ?
This article will show you how to create a badge using HTML and CSS. Badges are simple and basic components that are used to display an indicator or count a number. This is quite useful for mail count and alerting purposes, among other things. Badges are identical to labels, with the exception that
2 min read
How to create a Hero Image using HTML and CSS ?
A Hero Image is a large image with text, often placed at the top of a webpage. Hero images can be designed using HTML and CSS. This article contains two sections. The first section attaches the image and designs the basic structure. The second section designs the images and texts on the images. The
2 min read
How to create a shinny button using HTML and CSS ?
Buttons are undoubtedly one of the most important components of any website or app. A button should be designed in such a way that it stands out of the other component so that it is becoming clear to the user where to click and what is the button used for. There are infinite ways in which a button c
3 min read