Build a simple and working contact form with Bootstrap 4
Tags: beginners, bootstrap, webdev, html
Published: 2019-03-09 20:47:48

---
title: Build a simple and working contact form with Bootstrap 4
published: true
description: 
tags: beginners, bootstrap, webdev, html
cover_image: "https://udemy-images.udemy.com/course/750x422/598970_ee10.jpg"
---

<!-- wp:image {"id":626} -->
<figure class="wp-block-image"><img src="https://bugs-bunny.net/wp-content/uploads/2019/03/bootstrap4.jpg" alt="" class="wp-image-626"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>In this post you''ll see how you can build a simple yet working form using only HTML5 and Bootstrap classes. No CSS will be necessary!</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Using Bootstrap 4 you can build custom components quickly and easily by applying the Bootstrap classes.  Did you want to learn how to build modern and responsive components for your projects?  Bootstrap makes it easy and this post will show you how to build a simple contact form. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>At the end, your contact form should look like this:</p>
<!-- /wp:paragraph -->

<!-- wp:embed {"url":"https://codepen.io/BlackNina/pen/MxoVqv?editors=1000","type":"rich","providerNameSlug":"codepen","className":""} -->
<figure class="wp-block-embed is-type-rich is-provider-codepen"><div class="wp-block-embed__wrapper">
https://codepen.io/BlackNina/pen/MxoVqv?editors=1000
</div></figure>
<!-- /wp:embed -->

<p><!--EndFragment--></p>

<p><strong>1. Setup Bootstrap 4</strong></p>

<p>In order for us to start coding in the bootstrap framework, we first need to link the relevant files to our project so that we can make use of all the default bootstrap styles.</p>

<p>For the beginning, open your text editor, I personally prefer VS Code as I love its <a href="https://dev.to/drsavvina/9--1-visual-studio-code-extensions-for-easier-and-faster-development-164n">powerful extensions</a>, and create a new project. Create files index.html and style.css.</p>

<!-- wp:paragraph -->
<p><strong>CSS </strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Include this link in your project between head tags:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>&lt;link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"></code></pre>
<!-- /wp:code -->

<p><strong>2. Building the contact form</strong></p>
<p>Copy and paste the following code in your index.html file</p>

<!-- wp:code -->
<pre class="wp-block-code"><code>&lt;section class="resume-section p-4 p-lg-5 text-center" id="contact">
        &lt;div class="my-auto">
          &lt;h2 class="mb-4">&lt; Contact Information &gt;&lt;/h2>

          &lt;ul class="fa-ul mb-4 ml-0">
            &lt;li id="mail-address">
&lt;!--               Replace with your email address -->
                &lt;i class="fas fa-envelope-open mr-2 contact-icons">&lt;/i
                >youremail@mail.com&lt;/a
              >
            &lt;/li>
            &lt;li>
              &lt;i class="fas fa-mobile-alt mr-2 contact-icons">&lt;/i>+48 888 888
            &lt;/li>
            &lt;li>
              &lt;i class="fas fa-map-marker-alt mr-2 contact-icons">&lt;/i>Athens, GR
            &lt;/li>
          &lt;/ul>

          &lt;p>
            ...or leave your message below and I will be back to you as soon as
            possible.
          &lt;/p>

          &lt;form
            class="contact-form d-flex flex-column align-items-center"
            action="https://formspree.io/youremail@mail.com"
            method="POST"
          >
            &lt;div class="form-group w-75">
              &lt;input
                type="name"
                class="form-control"
                placeholder="Name"
                name="name"
                required
              />
            &lt;/div>
            &lt;div class="form-group w-75">
              &lt;input
                type="email"
                class="form-control"
                placeholder="Email"
                name="name"
                required
              />
            &lt;/div>

            &lt;div class="form-group w-75">
              &lt;textarea
                class="form-control"
                type="text"
                placeholder="Message"
                rows="7"
                name="name"
                required
              >&lt;/textarea>
            &lt;/div>

            &lt;button type="submit" class="btn btn-submit btn-info w-75">Submit&lt;/button>
          &lt;/form>
        &lt;/div>
      &lt;/section></code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Copy and paste the following script right before the &lt;/body> closing tag to use the Font Awesome icons:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>&lt;script
      defer
      src="https://use.fontawesome.com/releases/v5.7.2/js/all.js"
      integrity="sha384-0pzryjIRos8mFBWMzSSZApWtPl/5++eIfzYmTgBBmXYdhvxPc+XcFEk+zJwDgWbP"
      crossorigin="anonymous"
    >&lt;/script></code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>As you can see above, I have used Bootstrap utilities to customize some elements instead of using CSS. For example class w-75 sets the width of the form fields to 75%. Class btn-info is responsible for the petrol blue color of our submit button. In fact, we have really many choices among the Bootstrap utilities to customize our elements. without the use of CSS.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You can read more about Bootstrap classes and utilities on its <a href="https://getbootstrap.com/">official documentation.</a> </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>I used <a href="https://formspree.io/">Formspree</a> to make the contact form to work.  No PHP, JS, or registration needed. You just need to replace youremail@mail.com with your email address to receive the submissions.  </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p> Thanks for reading! I hope this helps. If you have any feedback or suggestions, I would be glad to talk to you in the comments. </p>
<!-- /wp:paragraph -->