In this tutorial, I’ll show you how to create a login form with pure CSS. First, look the video above to see how I make the login form. Then after the video, there’s a preview and the code of the result.
Video Videos are disabled. Click here to watch
The HTML < form action = " #! " id = " main " >
< h2 > Login to your account </ h2 >
< div class = " input-parent " >
< label for = " username " > Username or Email </ label >
< input type = " text " id = " username " />
</ div >
< div class = " input-parent " >
< label for = " password " > Password </ label >
< input type = " password " id = " password " />
</ div >
< button type = " submit " > Login </ button >
</ form >
The CSS * ,
* : before ,
* : after {
margin : 0 ;
padding : 0 ;
font-family : inherit ;
box-sizing : border-box ;
}
# main {
width : max-content ;
margin : 40 px auto ;
font-family : ' Segoe UI ' , sans-serif ;
padding : 25 px 28 px ;
background : #151414 ;
border-radius : 4 px ;
border : 1 px solid #302d2d ;
animation : popup 0.4 s cubic-bezier ( 0.68 , -0.55 , 0.27 , 1.55 ) ;
}
@ keyframes popup {
0% {
transform : scale ( 0.2 ) ;
opacity : 0 ;
}
100% {
transform : scale ( 1 ) ;
opacity : 1 ;
}
}
h2 {
text-align : center ;
font-size : 28 px ;
margin-bottom : 20 px ;
font-weight : 400 ;
color : #e7e7e7 ;
}
. input-parent {
display : block ;
margin-bottom : 20 px ;
}
label {
display : block ;
font-size : 16 px ;
margin-bottom : 8 px ;
color : #a4a4a4 ;
}
. input-parent input {
padding : 10 px 8 px ;
width : 100 % ;
font-size : 16 px ;
background : #323131 ;
border : none ;
color : #c7c7c7 ;
border-radius : 4 px ;
outline : none ;
transition : all 0.2 s ease ;
}
. input-parent input : hover {
background : #404040 ;
}
. input-parent input : focus {
box-shadow : 0 px 0 px 0 px 1 px #0087ff ;
}
button {
padding : 10 px 18 px ;
font-size : 15 px ;
background : #1a3969 ;
width : 100 % ;
border : none ;
border-radius : 4 px ;
color : #f4f4f4 ;
transition : all 0.2 s ease ;
}
button : hover {
opacity : 0.9 ;
}
button : focus {
box-shadow : 0 px 0 px 0 px 3 px black ;
}
body {
background : #1c1b1b ;
}