Design Shack showcases inspiring web design, alongside resources and tutorials for you to succeed in the same way. It is brought to you by David Appleyard, a freelance designer who is available for work.
Contact forms are an indispensable part of every website. They are mostly implemented on a separate page and they rarely display creativity, even though there are many ways to improve their visual style. In this tutorial you will see how to create a dynamic, slide-in contact form using jQuery.
Let’s see what we’re trying to achieve with this tutorial. The image below shows the layout of our goal. In the upper right corner of the content is “Contact us” link. When the user clicks on it, the contact form will slide down. When the user submits the form they will get a message that their message has been sent successfully and within two seconds, the entire form will slide up.

Note: You can make this form fully functional by adding validation and some real code that sends the email.
Check out the demo and download full source code here.
Let’s explain the structure first.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <div class=”box”> <div id=”contactFormContainer”> <div id=”contactForm”> <fieldset> <label for=”Name”>Name *</label> <input id=”name” type=”text” /> <label for=”Email”>Email address *</label> <input id=”Email” type=”text” /> <label for=”Message”>Your message *</label> <textarea id=”Message” rows=”3″ cols=”20″></textarea> <input id=”sendMail” type=”submit” name=”submit” onclick=”closeForm()” /> <span id=”messageSent”>Your message has been sent successfully!</span> </fieldset> </div> <div id=”contactLink”></div> </div> <div class=”header”> <h1> Company logo</h1> </div> … </div> </div> |
We have “contactForm” and “contactLink” divs inside the “contactFormContainer” which is positioned absolutely. ContactForm contains form elements, and contactLink will toggle our contact form on click. Simple enough, right? The CSS code will make this clearer:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #contactFormContainer { position:absolute; left:600px; float:right; } #contactForm { height:277px; width:351px; background-image:url(’bkg.jpg’); display:none; } #contactForm fieldset { padding:30px; border:none; } #contactForm label { display:block; color:#ffc400; } #contactForm input[type=text] { display:block; border:solid 1px #4d3a24; width:100%; margin-bottom:10px; height:24px; } #contactForm textarea { display:block; border:solid 1px #4d3a24; width:100%; margin-bottom:10px; } #contactForm input[type=submit] { background-color:#4d3a24; border:solid 1px #23150c; color:#fecd28; padding:5px; } #contactLink { height:40px; width:351px; background-image:url(’slidein_button.png’); display:block; cursor:pointer; } #messageSent { color:#ff9933; display:none; } |
And to make this work, we have to add a touch of jQuery.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | $(document).ready(function(){ $(”#contactLink”).click(function(){ if ($(”#contactForm”).is(”:hidden”)){ $(”#contactForm”).slideDown(”slow”); } else{ $(”#contactForm”).slideUp(”slow”); } }); }); function closeForm(){ $(”#messageSent”).show(”slow”); setTimeout(’$(”#messageSent”).hide();$(”#contactForm”).slideUp(”slow”)’, 2000); } |
Let me briefly explain the code above. Clicking on #contactLink div will toggle contact form visibility. Once user submits the form, a message “Your message has been sent successfully!” will appear and the entire form will slide up to its original state.
Check out the demo and download full source code here.
This is just a sample of how you can improve user experience by adding dynamic content to your pages. Besides a contact form, you can create a slide-in login form, search form or anything that you think will improve the user experience.
Is there anything that could be done better? Do you know any other way of doing this? Share some examples!
Hey guys, thanks for the comments. To answer the question many of you asked - Why there is no validation or mail sending logic - the idea behind this article was to create an interactive, visually enhanced web form, not to implement any logic. There are tons of tutorials on how to do validation/sending emails in different technologies like PHP, ASP.NET and so on, and I suggest you to check out some of tutorials that explain these techniques.