Web users log in every day, so imagine how many times log in forms are being used in a single day. Usually, it don’t take too much to fill a form like this, but using a dropdown solution will speed up things for you.
In this article, you will see how to create a good looking dropdown login form using CSS3 and a bit of jQuery.

The concept
The main purpose is to avoid waiting to load a separate page in order to log in. This way you can increase user experience, as the user has the possibility to log in immediately.
Ingredients
Remember the CSS3 buttons we’ve created using HTML entities as icons? In this article we’ll use entities again to show an arrow that indicates the current state for our dropdown log in box: expanded/collapsed.
Comparing to the latest HTML5 & CSS3 login tutorial you’ve seen here, this one uses some jQuery code to animate the box when clicking on the log in button.
Also, HTML5 new form features do not miss here.
HTML
Here’s the markup we’ll use to create our CSS3 dropdown log in:

<nav> <ul> <li id="login"> <a id="login-trigger" href="#"> Log in <span>▼</span> </a> <div id="login-content"> <form> <fieldset id="inputs"> <input id="username" type="email" name="Email" placeholder="Your email address" required> <input id="password" type="password" name="Password" placeholder="Password" required> </fieldset> <fieldset id="actions"> <input type="submit" id="submit" value="Log in"> <label><input type="checkbox" checked="checked"> Keep me signed in</label> </fieldset> </form> </div> </li> <li id="signup"> <a href="">Sign up FREE</a> </li> </ul> </nav>
CSS
There are quite a lot of CSS lines, but I think is worth it:
nav ul {
margin: 0;
padding: 0;
list-style: none;
position: relative;
float: right;
background: #eee;
border-bottom: 1px solid #fff;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
}
nav li {
float: left;
}
nav #login {
border-right: 1px solid #ddd;
-moz-box-shadow: 1px 0 0 #fff;
-webkit-box-shadow: 1px 0 0 #fff;
box-shadow: 1px 0 0 #fff;
}
nav #login-trigger,
nav #signup a {
display: inline-block;
*display: inline;
*zoom: 1;
height: 25px;
line-height: 25px;
font-weight: bold;
padding: 0 8px;
text-decoration: none;
color: #444;
text-shadow: 0 1px 0 #fff;
}
nav #signup a {
-moz-border-radius: 0 3px 3px 0;
-webkit-border-radius: 0 3px 3px 0;
border-radius: 0 3px 3px 0;
}
nav #login-trigger {
-moz-border-radius: 3px 0 0 3px;
-webkit-border-radius: 3px 0 0 3px;
border-radius: 3px 0 0 3px;
}
nav #login-trigger:hover,
nav #login .active,
nav #signup a:hover {
background: #fff;
}
nav #login-content {
display: none;
position: absolute;
top: 24px;
right: 0;
z-index: 999;
background: #fff;
background-image: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#eee));
background-image: -webkit-linear-gradient(top, #fff, #eee);
background-image: -moz-linear-gradient(top, #fff, #eee);
background-image: -ms-linear-gradient(top, #fff, #eee);
background-image: -o-linear-gradient(top, #fff, #eee);
background-image: linear-gradient(top, #fff, #eee);
padding: 15px;
-moz-box-shadow: 0 2px 2px -1px rgba(0,0,0,.9);
-webkit-box-shadow: 0 2px 2px -1px rgba(0,0,0,.9);
box-shadow: 0 2px 2px -1px rgba(0,0,0,.9);
-moz-border-radius: 3px 0 3px 3px;
-webkit-border-radius: 3px 0 3px 3px;
border-radius: 3px 0 3px 3px;
}
nav li #login-content {
right: 0;
width: 250px;
}
/*--------------------*/
#inputs input {
background: #f1f1f1;
padding: 6px 5px;
margin: 0 0 5px 0;
width: 238px;
border: 1px solid #ccc;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
-moz-box-shadow: 0 1px 1px #ccc inset;
-webkit-box-shadow: 0 1px 1px #ccc inset;
box-shadow: 0 1px 1px #ccc inset;
}
#inputs input:focus {
background-color: #fff;
border-color: #e8c291;
outline: none;
-moz-box-shadow: 0 0 0 1px #e8c291 inset;
-webkit-box-shadow: 0 0 0 1px #e8c291 inset;
box-shadow: 0 0 0 1px #e8c291 inset;
}
/*--------------------*/
#login #actions {
margin: 10px 0 0 0;
}
#login #submit {
background-color: #d14545;
background-image: -webkit-gradient(linear, left top, left bottom, from(#e97171), to(#d14545));
background-image: -webkit-linear-gradient(top, #e97171, #d14545);
background-image: -moz-linear-gradient(top, #e97171, #d14545);
background-image: -ms-linear-gradient(top, #e97171, #d14545);
background-image: -o-linear-gradient(top, #e97171, #d14545);
background-image: linear-gradient(top, #e97171, #d14545);
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
text-shadow: 0 1px 0 rgba(0,0,0,.5);
-moz-box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
-webkit-box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 0 rgba(255, 255, 255, 0.3) inset;
border: 1px solid #7e1515;
float: left;
height: 30px;
padding: 0;
width: 100px;
cursor: pointer;
font: bold 14px Arial, Helvetica;
color: #fff;
}
#login #submit:hover,
#login #submit:focus {
background-color: #e97171;
background-image: -webkit-gradient(linear, left top, left bottom, from(#d14545), to(#e97171));
background-image: -webkit-linear-gradient(top, #d14545, #e97171);
background-image: -moz-linear-gradient(top, #d14545, #e97171);
background-image: -ms-linear-gradient(top, #d14545, #e97171);
background-image: -o-linear-gradient(top, #d14545, #e97171);
background-image: linear-gradient(top, #d14545, #e97171);
}
#login #submit:active {
outline: none;
-moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;
}
#login #submit::-moz-focus-inner {
border: none;
}
#login label {
float: right;
line-height: 30px;
}
#login label input {
position: relative;
top: 2px;
right: 2px;
}
jQuery
The following code is quite self-explanatory. The if…else statement helps us indicate the current state for the log in box. It basically toggle the span‘s inner HTML between ▼ and ▲.
$(document).ready(function(){
$('#login-trigger').click(function(){
$(this).next('#login-content').slideToggle();
$(this).toggleClass('active');
if ($(this).hasClass('active')) $(this).find('span').html('▲')
else $(this).find('span').html('▼')
})
});
That’s it!
I hope you enjoyed this tutorial, don’t forget to leave a comment. Thanks for reading!
You always do really cool stuff. I wanted to write this piece myself but viola! You just saved me some really precious time. Really cool and thanks for sharing.
Yuneekguy, thank you. I’m glad to hear that!
Really good job ! I was looking for something of this sort yesterday. My search ends here :) Thanks a lot :)
Gautam, you’re welcome. ;)
Your tutorials are extremely useful. THX!!!
RecRoot, it’s always nice to hear that. Thanks!
Dude, that is fricken sweet! Great job!
Andrew, thanks a lot!
Can You Make a Tut on a Cool Footer Please?
chIDDY, I’m already planning to write an article about that in the future. ;)
You really are tallented dude, coders big or small never get enough credit for the hours that they put into improving the internet. I’m only a teenager coder but you know ;) it’s fun
good job.I like it.
Thanks Airen! ;)
This is wonderful! Your tutorials are great and useful indeed. Thank you!
nice tut’s…thanks^^
btw…nice shadow effect in your fixed top ;)
Thanks Beben.
Regarding the fixed top shadow, check this article to see how is made.
Thanks for posting this. Looks like it would be great on a wordpress site.
Thanks for your comment Scott!
useful code you sharing.
Thanks, I’m glad you found this useful.
Nice post man! Thanks a ton. I used twitter like dropdown, but now i must prefers your cool one. Keep sharing.
Thanks Srinivas, nice to hear you like it!
Nice, but the animation doesn’t look/feel right, it should slide out solidly like a real drawer, see the effect used here – http://eric.muyser.com/work/jquery/drawer/example/
More info/code here – http://eric.muyser.com/blog/post/jquery-plugin-jdrawer
hey bros,
just wondering can you add text in neat css to the of the bar?
cheers cuz!
sorry I meant on the left of the bar
Of course, I don’t see any reason why not. You can tweak this to fit your needs.
do you know how thow?
where does the J Query code goe?
Mike, the jQuery code for this dropdown box is executed after the page loads. So, you can place it where do you wish.
so like the header? or where would u recommend?
Put it in the bottom section (just before closing the
body). It’s a better choice – further you may want to add extra code there.Thanks. I’m new at jquery, so your help is appreciated. You have great work!
Do you have an IE7 and IE8 hack for the CSS?
The above lines help IE7 and below to render the element as
inline-block.Thanks.
Man you saved my three days! This works like a charm!
Piyush, nice to hear that you found it useful! ;)
What if, we would like to implement same box bottom of the page! What I want to know, when client click the button, the sliding panel should open upwards, not downwards. Thanks.
Hey, why not?! Feel free to try it ;)
I found your website 4 or 5 days ago and your works are amazing! every day i come to see the new stuff. Good luck!
PD: what about make a cool registry form?
Juan, from Argentina.
Thanks Juan, I’m glad you like by blog. I’ll keep in mind your suggestion for the future articles. Cheers!
Great post. Looks great and its relatively simple to implement. I have one question. In my website the login div opens to the far right of the webpage and not contained in the li like your example. I am a newbie to html5/css3 but i’m catching on quickly, so any help would be appreciated. Great website!! Keep up the good work.
Hi Sean, I guess you’re missing a
position:relativedeclaration somewhere in the CSS code. Check that and let me know if you fixed it! Good luck and thanks for your comment!Hi your login box looks really nice but how can I implement it in my WordPress site?
Hi Stepag, I’m glad you like the login box. Regarding your question, the implementation should be almost the same, whether is static HTML or a CMS like WordPress.
can we add this to Google free sites ??
Please advise on where to place the jquery. The html I have placed in a text widget, css in the style sheet, lost for the the correct mark up for the jquery. I’m using the latest version of wordpress. Many thanks, it looks great.
The jQuery code actually executes when the page is fully loaded, so you can place it anywhere you like (as long as you link to the jQuery library first).
Hey umm, I’m kind of a beginner , could you tell me where should I place css ,html?
and having problems with jquery , sorry for seperate comments.
Hey, check the demo source page to see how everything is combined. Good luck!
ok thanks but I’m using wordpress and it doesnt log me in. And even if I’m logged in, it doesn’t say you’re logged in or smt like that.
Beautiful form.
Thanks for the tutorial.
Now I only need to learn how to code the “sign up” part of the form.
Hope you will add that part too :)
Stay tuned! Next week you’ll have a surprise :)
really cool stuff. ahm,.can i have that one?the dropdown login?
Feel free to use it in your projects!
Can i download your project?
man this is just great. Nice, easy, usefull
I am searching for this .Nice code .
Red,
Great work, I love coming to this site and running the ideas and designs you have made on my own its great practice to help me better understand code that is too complex for me at this stage.
That being said, Is there a way that you can set up the login box to work like this:
When you click on the login button and the box drops down – can you have the cursor automatically be placed in the box so you can start typing? For my clients, it would be more convenient if they didn’t have to click twice to start typing their information into the first box.
Thanks,
Tusk
Hi Tusk,
You can use the
autofocusboolean attribute for the first input to do that.Red,
Thanks so much!
First this login box is awesome and easily adaptable. I love it!
That being said I am having issues getting it to display properly in IE8, the drop down box is incorrectly sized and is loading open instead of closed.
any thoughts?
Great job on this, it’s beautiful! Having a slight problem though – is there a way to have a contact form on the same page as the drop down? The drop down is working in my Firefox & Safari previews, but not when it’s live. I am guessing because I have a contact form on this page also… Help is appreciated, Thanks.
How would I put this code into wordpress? Would you know?
Great Post!! Red..It will be a Good Learning material for novice prograamers like me.I just worked out on your program & its not displaying the form.& i guess its because ▼ is not getting executed.Instead it appears as ?.I cant guess what the problem is.I need your help.
Thank You!!
Hi, great tutorial, love it.
Only problem I found was it didnt actually log me into the site and the username and password were displayed in the url bar?
Thanks
Hello,
Nice work…
If you have a minute and know, I dont as i am pretty novice with Jquery and Javascript.
I Use your code to have two dropdown… One for a newsletter sign up and one for a search box…
How can i tell jquery to toggle close one dropdown when I am opening the next one?
Thanks
Yanik
Great code, Is there a way to change “Log in” to “Log Out” after a user has logged in?
Is there a way to get the placeholders compatible with IE?
Jeff, you may want to check this! ;)
thanks for this nice work ..
is that possible to make both login and register from in dropdown in the same code ?
i think i am missing something here,,do i have to include any other js library,,because it doesn`t work with me, i did exactly like you said,,,i really want your help ,,because it is the only tutorial i understand about dropdown login
Mike, you need to include the jQuery library. Check the demo page source for an example.
Good luck!
woow it works great,,,thx alot bro :)
nice work …
keep it up man
Exactly what I was looking for, but………….
How would I then add navigation to your bar.
I’ve tried a lot of different things but nothing seems to work.
I’m using the code but I want you to take that right click give some action, I just want the action to send
Awesome, it was useful, thank you :)
Yeah…really nice.
thx
can u learn me how build simple slider ?
i want make it
Hi,
with IE8 the drop-down menu is always open.
Can someone explain how fix it?
please put sors files or send to my email.thankyou
Thanks a lot! :)
thanks a lot
Extremely good tutorial, with gorgeous results! Bu I do have one question:
How do you actually connect this to a login script that connects to a mysql database?
Thanks in advance !
Tobias, that’s backend not frontend. So, you must search MySql connection answer elsewhere. ;)
This guide is outdated… Doesn’t work anymore. I followed the guide but mine just scrolls back up again right away.
Peter, the demo is working.
Belo tutorial, parabens sou do Brasil. sabe me dizer se dá pra fazer isso no WordPress, se sim como deve ser feito?
Abraço
ganho mais um seguidor
SP/Brasil
Hi,
very nice tut, thank you very much!
How can add some links on the left side of the top bar ?
I can’t find class .active in your form?!