Create a Contact Us Form in 10 Minutes Using HTML and CSS | Quick Tutorial

Learn how to build a stylish and functional 'Contact Us' form in just 10 minutes with HTML and CSS. Perfect for web developers and beginners alike. Follow this quick tutorial to add a contact form to your website.

Monday, August 19, 2024
Create a Contact Us Form in 10 Minutes Using HTML and CSS | Quick Tutorial

Create a Contact Us Form in 10 Minutes Using HTML and CSS | Quick Tutorial

Want to add a simple yet effective 'Contact Us' form to your website? Whether you're a seasoned web developer or just starting out, this tutorial is designed to help you create a fully functional and stylish contact form in just 10 minutes using HTML and CSS.




What You’ll Learn:

In this step-by-step guide, you'll discover:

  • Basic HTML Structure: How to set up the basic structure of the contact form using HTML.
  • Styling with CSS: Techniques to style your form, making it visually appealing and easy to use.
  • Form Functionality: How to ensure that your contact form collects and sends the necessary information from visitors.

Why Create a Contact Us Form?

A 'Contact Us' form is essential for any website, allowing visitors to reach out directly to you. It’s a vital tool for communication, whether you’re running a business, blog, or personal website. Plus, designing and coding your own form is a great way to practice and enhance your web development skills.

Quick and Easy Setup

This tutorial is designed to be quick and straightforward. In just 10 minutes, you’ll have a professional-looking contact form that you can:

  • Integrate into Your Website: Add the form to any page on your site.
  • Customize and Expand: Use the code as a foundation to build more advanced forms or features.

How to Get Started:

  1. Set Up the HTML: Follow the tutorial to create the structure of the form.
  2. Apply CSS Styling: Learn how to style your form for a polished, professional look.
  3. Test and Integrate: Ensure the form works correctly and integrate it into your website.

By the end of this tutorial, you’ll have a fully operational 'Contact Us' form ready to go live on your website, or you can use it as a template for future projects.

HTML Code

<pre class="a-b-r-La" style="user-select: text; font-family: &quot;Courier New&quot;, Courier, monospace, arial, sans-serif; margin-bottom: 0px; text-wrap: wrap; background-color: rgb(255, 255, 255); color: rgb(0, 0, 0); font-size: 14px;">&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
    &lt;title&gt;Login and Signup Form&lt;/title&gt;
    &lt;link rel="stylesheet" href="style.css"&gt;
    &lt;link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;section class="container forms"&gt;
        &lt;div class="form login"&gt;
           &lt;div class="form-content"&gt;
            &lt;header&gt;Login&lt;/header&gt;

            &lt;form action="#"&gt;
                &lt;div class="field input-field"&gt;
                    &lt;input type="email" placeholder="Email" class="input"&gt;
                &lt;/div&gt;

                &lt;div class="field input-field"&gt;
                    &lt;input type="password" placeholder="password" class="password"&gt;
                    &lt;i class='bx bxs-hide eye-icon'&gt;&lt;/i&gt;    
                &lt;/div&gt;

                &lt;div class="form-link"&gt;
                    &lt;a href="#" class="forgot-pass"&gt;Forgot password?&lt;/a&gt;
                &lt;/div&gt;

                &lt;div class="field input-field"&gt;
                    &lt;button&gt;Login&lt;/button&gt;
                &lt;/div&gt;

                &lt;div class="field input-field"&gt;
                   &lt;span&gt;Already have an account? &lt;a href="#" class="link signup-link"&gt;Signup&lt;/a&gt;&lt;/span&gt;
                &lt;/div&gt;
            &lt;/form&gt;
           &lt;/div&gt;
           &lt;div class="line"&gt;&lt;/div&gt;
           &lt;div class="media-options"&gt;
            &lt;a href="#" class="field facebook"&gt;
                &lt;i class='bx bxl-facebook-circle facebook-icon' &gt;&lt;/i&gt;
                &lt;span&gt;Login with Facebook&lt;/span&gt;
            &lt;/a&gt;
           &lt;/div&gt;

           &lt;div class="media-options"&gt;
            &lt;a href="#" class="field google"&gt;
                &lt;img src="download.png" alt="" class="google-img"&gt;
                &lt;span&gt;Login with Google&lt;/span&gt;
            &lt;/a&gt;
           &lt;/div&gt;
        &lt;/div&gt;
         

        &lt;!--signup form--&gt;


        &lt;div class="form signup"&gt;
            &lt;div class="form-content"&gt;
             &lt;header&gt;Signup&lt;/header&gt;
 
             &lt;form action="#"&gt;
                 &lt;div class="field input-field"&gt;
                     &lt;input type="email" placeholder="Email" class="input"&gt;
                 &lt;/div&gt;
 
                 &lt;div class="field input-field"&gt;
                     &lt;input type="password" placeholder="password" class="password"&gt;
                       
                 &lt;/div&gt;
                 &lt;div class="field input-field"&gt;
                    &lt;input type="password" placeholder="password" class="password"&gt;
                    &lt;i class='bx bxs-hide eye-icon'&gt;&lt;/i&gt;    
                &lt;/div&gt;
 
               
                
 
                 &lt;div class="field input-field"&gt;
                     &lt;button&gt;Signup&lt;/button&gt;
                 &lt;/div&gt;
 
                 &lt;div class="field input-field"&gt;
                    &lt;span&gt;Already have an account? &lt;a href="#" class="link login-link"&gt;Login&lt;/a&gt;&lt;/span&gt;
                 &lt;/div&gt;
             &lt;/form&gt;
            &lt;/div&gt;
            &lt;div class="line"&gt;&lt;/div&gt;
            &lt;div class="media-options"&gt;
             &lt;a href="#" class="field facebook"&gt;
                 &lt;i class='bx bxl-facebook-circle facebook-icon' &gt;&lt;/i&gt;
                 &lt;span&gt;Login with Facebook&lt;/span&gt;
             &lt;/a&gt;
            &lt;/div&gt;
 
            &lt;div class="media-options"&gt;
             &lt;a href="#" class="field google"&gt;
                 &lt;img src="download.png" alt="" class="google-img"&gt;
                 &lt;span&gt;Login with Google&lt;/span&gt;
             &lt;/a&gt;
            &lt;/div&gt;
         &lt;/div&gt;
    &lt;/section&gt;

    &lt;!--javascript--&gt;
    &lt;script src="script.js"&gt;&lt;/script&gt;
    
&lt;/body&gt;
&lt;/html&gt;</pre>

CSS Code

<pre class="a-b-r-La" style="user-select: text; font-family: &quot;Courier New&quot;, Courier, monospace, arial, sans-serif; margin-bottom: 0px; text-wrap: wrap; background-color: rgb(255, 255, 255); color: rgb(0, 0, 0); font-size: 14px;">  @import url('https://fonts.googleapis.com/css2?family=Josefin+Sans&amp;family=Montserrat:wght@400;500;600;700&amp;family=Poppins:wght@300;400;500;600&amp;family=Ubuntu&amp;display=swap');

*{
    font-family: 'Poppins', sans-serif;
}

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'poppins', sans-serif;
}
.container{
    height: 100vh;
    width:100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: blue;
    column-gap: 30px;
}
.form{
    position: absolute;
    max-width: 430px;
    width: 100%;
    padding: 30px;
    border-radius: 6px;
    background: #827d7d;
}
.form.signup{
    opacity: 0;
    pointer-events: none;
}
.forms.show-signup .form.signup{
    opacity: 1;
    pointer-events: auto;
}
.forms.show-signup .form.login{
    opacity: 1;
    pointer-events: none;
}
header{
    font-size: 28px;
    font-weight: 600;
    color: #232836;
    text-align: center;
}
form{
    margin-top: 30px;
}
.form .field{
    border-radius: 6px;
    position: relative;
    height: 50px;
    width: 100%;
    margin-top: 20px;
}
.field input,
 .field button{
    height: 100%;
    width: 100%;
    border: none;
    font-size: 16px;
    font-weight: 400;
    border-radius: 6px;
}
.field input{
    outline: none;
    padding: 0 15px;
    border: 1px solid #cacaca;
}
.field input:focus{
    border-bottom-width:2px;

}
.eye-icon{
    position: absolute;
    top: 50%;
    color: #8b8bb8;
    right: 10px;
    transform: translateY(-50%);
    font-size: 18px;
    cursor: pointer;
    padding: 5px;

}
.field button{
    color: #b1a9a9;
    background: white;
    transition: all 0.3s ease;
    cursor: pointer;
}
.field button:hover{
    background-color: #016dcb;
}
.form-link{

    text-align: center;
    margin-top: 10px;
}
.form-link span,
.form-link a{
    font-size: 14px;
    font-weight: 400;
    color: #232836;
}
.form a{
    color: #0171d3;
    text-decoration: none;
}
.form-content a:hover{
    text-decoration: underline;
}
.line{
    position: relative;
    height: 1px;
    width:100%;
    background-color:#323030;
}
.line::before{
    content: 'Or';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #FFF;
    color: #232836;
    padding: 0 15px;
}
.media-options a{
    display: flex;
    align-items: center;
    justify-content: center;
   
}
a.facebook{
    background-color: #4267b2;
    color: #ffff;
}
a.facebook .facebook-icon{
    height: 28px;
    width: 28px;
    color: #0171d3;
    font-size: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #fff;
}

.facebook-icon,
img.google-img{
    position: absolute;
    top:50%;
    left: 15px;
    transform: translateY(-50%);
}
img.google-img{
    height: 20px;
    width: 20px;
    object-fit: cover;
}
a.google{
    border: 1px solid #cacaca;
}
a.google span{
    font-weight: 500;
    opacity:0.6;
    color: #232836;
}

@media  screen and (max-width: 400px) {
    .form{
        padding: 15px 10px;
    }
}</pre>

JavaScript Code

<pre class="a-b-r-La" style="user-select: text; font-family: &quot;Courier New&quot;, Courier, monospace, arial, sans-serif; margin-bottom: 0px; text-wrap: wrap; background-color: rgb(255, 255, 255); color: rgb(0, 0, 0); font-size: 14px;">const forms=document.querySelector(".forms"),
     pwShowHide = document.querySelectorAll(".eye-icon"),
     links = document.querySelectorAll(".link");

     pwShowHide.forEach(eyeIcon =&gt; {
        eyeIcon.addEventListener("click", () =&gt; {
            let pwFields = eyeIcon.parentElement.parentElement.querySelectorAll(".password");

            pwFields.forEach(password =&gt; {
                if(password.type === "password"){
                    password.type = "text";
                    eyeIcon.classList.replace("bx-hide", "bx-show");
                    return;
                }
                password.type = "password";
                eyeIcon.classList.replace("bx-show", "bx-hide");

            })
        })
     })
     
     links.forEach(link =&gt; {
        link.addEventListener("click", e =&gt; {
            e.preventDefault(); //preventing form submit
            forms.classList.toggle("show-signup");
        })
     })</pre>

PHP Code

NO Need

Ready to Build?

Let’s get started and create a contact form that will enhance your website's communication with visitors. Follow the steps in this guide, and you’ll be done in no time!






Leave a Comment: 👇