Slick login form with HTML5 & CSS3

We already know that CSS3 has the ability to create a lot of new possibilities to design and implement better web forms. Also, HTML5 has its important role when it comes about creating more usable forms, without actually needing any Javascript code.

Knowing that, check out the below preview to see the login form we’re going to create in this article:

View demo

Markup

<form id="login">
    <h1>Log In</h1>
    <fieldset id="inputs">
        <input id="username" type="text" placeholder="Username" autofocus required>   
        <input id="password" type="password" placeholder="Password" required>
    </fieldset>
    <fieldset id="actions">
        <input type="submit" id="submit" value="Log in">
        <a href="">Forgot your password?</a><a href="">Register</a>
    </fieldset>
</form>

The HTML5 stuff

New HTML5 attributes descriptions, according to latest specifications:

  • placeholder – A short hint (one word or a short phrase) intended to aid the user when entering data into the control represented by its element.
  • required – Specifies that the element is a required part of form submission.
  • autofocus – Specifies that the element represents a control to which a UA is meant to give focus as soon as the document is loaded.
  • type=”password” – Specifies that its input element is a one-line plain-text edit control for entering a password. (not HTML5 specific)

The CSS

For this article, I will not paste the whole lines here. Instead, I’ll just add the ones who help creating some cool effects.

Paper stack effect

Box-shadow will help us creating this nice effect by defining multiple shadows that actually overlap.

#login
{
    box-shadow:
          0 0 2px rgba(0, 0, 0, 0.2),  
          0 1px 1px rgba(0, 0, 0, .2),
          0 3px 0 #fff,
          0 4px 0 rgba(0, 0, 0, .2),
          0 6px 0 #fff,  
          0 7px 0 rgba(0, 0, 0, .2);
}

Stitch effect

This effect is added using pseudo-elements. Using pseudo-elements helps you avoid extra markup and this is a perfect example: keep the markup clean and let the CSS do the magic.

#login
{
    position: absolute;
    z-index: 0;
}

#login:before
{
    content: '';
    position: absolute;
    z-index: -1;
    border: 1px dashed #ccc;
    top: 5px;
    bottom: 5px;
    left: 5px;
    right: 5px;
    -moz-box-shadow: 0 0 0 1px #fff;
    -webkit-box-shadow: 0 0 0 1px #fff;
    box-shadow: 0 0 0 1px #fff;
}

Styles excerpt.

Subtle gradient lines

I’ve first seen this effect on Gene Locklin‘s page and I thought this is pretty cool. So, I decided to use it for highlighting the “Log in” heading. Using pseudo-elements (again) and CSS3 gradients some cool lines are added to simulate a strikeout effect.

h1
{
    text-shadow: 0 1px 0 rgba(255, 255, 255, .7), 0px 2px 0 rgba(0, 0, 0, .5);
    text-transform: uppercase;
    text-align: center;
    color: #666;
    margin: 0 0 30px 0;
    letter-spacing: 4px;
    font: normal 26px/1 Verdana, Helvetica;
    position: relative;
}

h1:after, h1:before
{
    background-color: #777;
    content: "";
    height: 1px;
    position: absolute;
    top: 15px;
    width: 120px;   
}

h1:after
{ 
    background-image: -webkit-gradient(linear, left top, right top, from(#777), to(#fff));
    background-image: -webkit-linear-gradient(left, #777, #fff);
    background-image: -moz-linear-gradient(left, #777, #fff);
    background-image: -ms-linear-gradient(left, #777, #fff);
    background-image: -o-linear-gradient(left, #777, #fff);
    background-image: linear-gradient(left, #777, #fff);      
    right: 0;
}

h1:before
{
    background-image: -webkit-gradient(linear, right top, left top, from(#777), to(#fff));
    background-image: -webkit-linear-gradient(right, #777, #fff);
    background-image: -moz-linear-gradient(right, #777, #fff);
    background-image: -ms-linear-gradient(right, #777, #fff);
    background-image: -o-linear-gradient(right, #777, #fff);
    background-image: linear-gradient(right, #777, #fff);
    left: 0;
}

The final result

Using the above techniques, here’s the final result:

View demo

Conclusion

This login form looks very well also on older browsers, as you can see below:


Internet Explorer 8 screenshot.

As a future improvement, you can add also HTML5 placeholder fallback as you have seen in one of my previous articles.

66 thoughts on “Slick login form with HTML5 & CSS3

    • HI Im new with programing and would like to make a login page with password and also button for them to create a user name if they dont have one can u send the code to my email,btw im using html5

  1. Hello I want to use your page effect in my website but I used a grid framework. Can we use this css3 style without position:absolute ? Because when I delete this I don’t have the style.

    Thanks

      • thnx for replying, why the placeholder is not working properly in google chrome & it is working perfectly in mozilla firefox. And the problem is that when I clck into the field the label is dissapeared from the field in mozilla perfectly but the placeholder is not working in google chrome as in mozilla firefox. tell me the solution ?

  2. I want to use this kind of forms in asp.net 3.5. But the properties are not present like box shadow. Pls suggest me

  3. hey i really like your design
    i wanted to add it to my current project and it only show the login as in the picture but the rest is messed up
    the register link is too close to the forget pass link and the boxes come up bad :/
    what should i do?
    i don’t really have experience in this and have no time to learn html-css3 :/ cuz gotta turn my project in within 3 weeks :s

    • Send me a link and I’ll take a look, but I also think you need to invest some time in learning basics in order to play with CSS.

  4. Mehn you are the bomb of bombs i love your work! Its amazing! Pls i would love you send me the full css code with any latest improvements thanks let me show some of my friends {eichieabdul@yahoo.com}

  5. Hey Red; First of all every article you post is revolutionary and amazing! This login form is amazing and I am using it with all my web projects! I have one issue though… In IE 8 you lose some of the CSS 3 but the form is still sleek however in IE 9 which unfortunately most of my users have the form gets deformed and may make it hard for the user. Any way to fix it?

    Screenshot: http://i.imgur.com/gZOXj.png

    • Hey Stephen, thanks for your kind words.

      Regarding your issue, it’s kinda strange as your screenshot doesn’t look as it should be. I guess some other CSS rules apply there. Please check your CSS inheritances…

      The demo you found in this article degrade gracefully also for IE6-IE8. However, IE9 support most of CSS3 properties and that’s why this demo looks really well on IE9…

  6. Te urmaresc de ceva timp si nu-mi vine sa cred ca abia acum am gasit acest tutorial. Apropo, mie imi place mai mult cum arata versiunea de ie8. Super culori. Am sa o folosesc cu o singura modificare si anume fading-ul de la strikeout-ul h1.

  7. Salut. E bestial ce aveti aici. Tot respectul. Am o intrebare. Login sprite-ul e facut de voi sau as putea gasi ceva imagine mai complexa cu mai multe modele (ceva pentru email, adresa, telefon etc..)
    Ms mult.

  8. Hie Catalin,

    Thanx for the tutorial. This helped when i was creating my first wordpress theme which I named silver blue. Just as a token of gratitude I also created the same version of the theme with a ‘red styling flavour’ or ‘ruso styling flavour’. You have a very useful blog here, keep up the good work. Here is a link to see the theme http://www.alappin.com/wordpress-themes/.

    again thanx.

  9. très belle formulaire.
    si c’est possible me donner le code complet de cette formulaire HTML et CSS
    c’est urgent
    merci :)

      • thank you for your answer,

        j’ai fait que ce que tu dit mais j’ai obtient un formulaire pas totalement équivalente à celui-ci : exemple le bouton chez moi et trés simple et aussi les champs texte.

        j’espère que tu m’aider pour résoudre ce problème :)
        mercii

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>