Simple and effective dropdown login box

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.


View demo

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('&#x25B2;')
			else $(this).find('span').html('&#x25BC;')
		})
});

View demo

That’s it!

I hope you enjoyed this tutorial, don’t forget to leave a comment. Thanks for reading!

92 thoughts on “Simple and effective dropdown login box

  1. 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.

  2. 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.

  3. 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:relative declaration somewhere in the CSS code. Check that and let me know if you fixed it! Good luck and thanks for your comment!

    • 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.

  4. 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).

  5. 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 :)

  6. 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

  7. 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?

  8. 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.

  9. 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!!

  10. 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

  11. 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

  12. 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

  13. 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.

  14. 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 !

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>