Create a Responsive Bootstrap Registration Form (Source Code)

Faraz

By Faraz -

Learn how to create a responsive and customizable registration form using Bootstrap. Follow our step-by-step guide and design a user-friendly form with ease. Source code included!


Responsive Bootstrap Registration Form.jpg

Table of Contents

  1. Project Introduction
  2. HTML Code
  3. CSS Code
  4. JavaScript Code
  5. Conclusion
  6. Preview

Welcome to our comprehensive guide on creating a Bootstrap registration form. In this tutorial, we will walk you through the step-by-step process of designing a responsive and customizable registration form using Bootstrap, HTML, and CSS.

A registration form is a vital component of many websites, allowing users to create accounts and access exclusive features or content. By utilizing Bootstrap, a popular front-end framework, you can streamline the form design process and ensure a seamless user experience across different devices.

Bootstrap offers a wide range of pre-built components and styles that can be easily integrated into your registration form. Whether you are a beginner or an experienced developer, this tutorial will provide you with the knowledge and tools to create a visually appealing and user-friendly registration form.

In the following sections, we will delve into the benefits of using Bootstrap for registration forms and guide you through each step, from setting up the HTML structure to adding form validation and customizing the form's appearance. We will provide detailed explanations, accompanied by code snippets and visual examples, to help you grasp the concepts and implement them effectively.

By the end of this tutorial, you will have the skills to create a responsive and customized Bootstrap registration form that aligns with your website's branding and enhances the user registration process.

Let's start making an amazing responsive Bootstrap registration form using HTML, CSS, and JavaScript step by step.

Join My Telegram Channel to Download the Projects Source Code: Click Here

Prerequisites:

Before starting this tutorial, you should have a basic understanding of HTML, CSS, and JavaScript. Additionally, you will need a code editor such as Visual Studio Code or Sublime Text to write and save your code.

Source Code

Step 1 (HTML Code):

To get started, we will first need to create a basic HTML file. In this file, we will include the main structure for our registration form.

After creating the files just paste the following codes into your file. Make sure to save your HTML document with a .html extension, so that it can be properly viewed in a web browser.

Let's break it down step by step:

<!DOCTYPE html>: This line declares the document type as HTML5.

<html lang="en">: This is the opening tag for the HTML document. The lang attribute specifies the language of the document (English in this case).

<head>: This section contains meta-information about the document and external resources used.

  1. <title>Home</title>: This sets the title of the web page to "Home".
  2. <meta charset="UTF-8" />: This specifies the character encoding for the document as UTF-8, which supports a wide range of characters.
  3. <meta name="viewport" content="width=device-width" />: This meta tag sets the viewport width to the device width, ensuring proper rendering on various screen sizes.
  4. <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css'>: This line links an external CSS stylesheet from the Bootstrap framework CDN (Content Delivery Network). It provides pre-defined styles and layout classes for the web page.
  5. <link rel="stylesheet" href="styles.css" />: This line links a local CSS stylesheet called "styles.css" to further customize the appearance of the web page.

<body>: This is the opening tag for the body section of the HTML document, where the visible content of the web page is placed.

  1. <div class="container">: This creates a container to hold the content of the web page. The "container" class is provided by Bootstrap and helps with responsive layout.
  2. <div class="row">: This creates a row within the container. Rows are used to organize content horizontally.
  3. <div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">: This creates a column within the row. The column width is determined based on the screen size. The "col-xs-12" means the column takes up the full width on extra small screens, "col-sm-8" means it takes 8 out of 12 columns on small screens, "col-md-6" means it takes 6 out of 12 columns on medium screens. The "col-sm-offset-2" and "col-md-offset-3" classes offset the column by 2 and 3 columns, respectively, on small and medium screens.
  4. <form role="form" id="sign_up" method="POST" action="/user/sign_up">: This line starts a form element with the id "sign_up". The form will be submitted using the HTTP POST method to the "/user/sign_up" URL.
  5. <h2>Please Sign Up <small>It's free and always will be.</small></h2>: This displays a heading for the sign-up form, along with a smaller subheading.
  6. <hr class="colorgraph">: This creates a horizontal line with the "colorgraph" class applied.
  7. Several <div> elements with form inputs inside: These divs represent form input fields like text, email, and password. Each input field has a label, an icon, and a placeholder attribute to provide instructions or examples to the user.
  8. <div class="row">: This creates another row within the form.
  9. Checkbox and text: This section displays a checkbox for agreeing to terms and conditions, along with a link to open a modal dialog that contains the detailed terms and conditions.
  10. <hr class="colorgraph">: Another horizontal line to separate the form content.
  11. <div class="row">: This creates a row for two buttons: "Register" and "Sign In".
  12. <div class="modal fade" id="t_and_c_m" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">: This is a modal dialog container that appears when the user clicks on the terms and conditions link. It has an id of "t_and_c_m" and contains the terms and conditions content.
  13. <script> tags: These include references to external JavaScript files, such as the jQuery library and the Bootstrap JavaScript library, which are necessary for certain interactive functionality.

</html> and </body>: These are the closing tags for the HTML document and the body section, respectively.

This is the basic structure of our registration form using HTML, and now we can move on to styling it using CSS.

Step 2 (CSS Code):

Once the basic HTML structure of the website is in place, the next step is to add styling to the registration form using CSS.

Let's go through it step by step:

1. .colorgraph is a class selector that targets elements with the class "colorgraph". It sets the following styles for those elements:

  • height: 5px; sets the height of the element to 5 pixels.
  • border-top: 0; removes the top border of the element.
  • background: #c4e17f; sets the background color of the element to a light green color.
  • border-radius: 5px; rounds the corners of the element with a radius of 5 pixels.
  • background-image: ... sets a gradient background image using different colors. The gradient starts from the left and goes to the right. The different color stops define the transition points of the gradient.

2. #sign_up i.glyphicon is an ID and class selector combination that targets <i> elements with the class "glyphicon" inside an element with the ID "sign_up". It sets the following style for those elements:

  • font-size: 18px; sets the font size of the element to 18 pixels.

3. #check_pass2.valid .input-group-addon is an ID and class selector combination that targets elements with the class "input-group-addon" inside an element with the ID "check_pass2" when it also has the class "valid". It sets the following style for those elements:

  • background: rgb(177, 226, 177); sets the background color of the element to a light green color.

4. #check_pass2.not-valid .input-group-addon is an ID and class selector combination that targets elements with the class "input-group-addon" inside an element with the ID "check_pass2" when it also has the class "not-valid". It sets the following style for those elements:

  • background: rgb(231, 205, 205); sets the background color of the element to a light red color.

This will give our registration form an upgraded presentation. Create a CSS file with the name of styles.css and paste the given codes into your CSS file. Remember that you must create a file with the .css extension.

.colorgraph {
  height: 5px;
  border-top: 0;
  background: #c4e17f;
  border-radius: 5px;
  background-image: -webkit-linear-gradient(left, #c4e17f, #c4e17f 12.5%, #f7fdca 12.5%, #f7fdca 25%, #fecf71 25%, #fecf71 37.5%, #f0776c 37.5%, #f0776c 50%, #db9dbe 50%, #db9dbe 62.5%, #c49cde 62.5%, #c49cde 75%, #669ae1 75%, #669ae1 87.5%, #62c2e4 87.5%, #62c2e4);
  background-image: -moz-linear-gradient(left, #c4e17f, #c4e17f 12.5%, #f7fdca 12.5%, #f7fdca 25%, #fecf71 25%, #fecf71 37.5%, #f0776c 37.5%, #f0776c 50%, #db9dbe 50%, #db9dbe 62.5%, #c49cde 62.5%, #c49cde 75%, #669ae1 75%, #669ae1 87.5%, #62c2e4 87.5%, #62c2e4);
  background-image: -o-linear-gradient(left, #c4e17f, #c4e17f 12.5%, #f7fdca 12.5%, #f7fdca 25%, #fecf71 25%, #fecf71 37.5%, #f0776c 37.5%, #f0776c 50%, #db9dbe 50%, #db9dbe 62.5%, #c49cde 62.5%, #c49cde 75%, #669ae1 75%, #669ae1 87.5%, #62c2e4 87.5%, #62c2e4);
  background-image: linear-gradient(to right, #c4e17f, #c4e17f 12.5%, #f7fdca 12.5%, #f7fdca 25%, #fecf71 25%, #fecf71 37.5%, #f0776c 37.5%, #f0776c 50%, #db9dbe 50%, #db9dbe 62.5%, #c49cde 62.5%, #c49cde 75%, #669ae1 75%, #669ae1 87.5%, #62c2e4 87.5%, #62c2e4);
}

#sign_up i.glyphicon {
  font-size: 18px;
}

#check_pass2.valid .input-group-addon {
  background: rgb(177, 226, 177);
}

#check_pass2.not-valid .input-group-addon {
  background: rgb(231, 205, 205);
} 

Step 3 (JavaScript Code):

Finally, we need to create a function in JavaScript. This JavaScript code is written using the jQuery library and performs certain actions related to a button checkbox interface and password validation. Let's break down the code step by step:

The code begins with a jQuery document ready function: $(function() { ... });. This ensures that the code inside the function will run once the document (HTML) has finished loading.

The $('.button-checkbox').each(function() { ... }); loop iterates over each element with the class "button-checkbox" on the page.

Inside the loop, the code defines various variables and settings. Here are the variables:

  • $widget refers to the current "button-checkbox" element.
  • $button represents the button element within the current "button-checkbox" element.
  • $checkbox represents the checkbox input element within the current "button-checkbox" element.
  • color stores the value of the "color" data attribute on the button element.
  • settings is an object that defines the icon classes for the on and off states of the button.

Next, the code sets up event handlers for the button and checkbox:

  • $button.on('click', function() { ... }); attaches a click event handler to the button. When clicked, it toggles the checked property of the checkbox, triggers a 'change' event on the checkbox, and calls the updateDisplay() function.
  • $checkbox.on('change', function() { ... }); attaches a change event handler to the checkbox. When the checkbox value changes, it calls the updateDisplay() function.

The updateDisplay() function is responsible for updating the visual state of the button based on the checkbox's checked status. It performs the following actions:

  • It checks whether the checkbox is checked using $checkbox.is(':checked') and stores the result in the isChecked variable.
  • It sets the data attribute 'state' of the button to either "on" or "off" based on the checkbox's checked status.
  • It updates the button's icon by adding or removing the appropriate classes based on the button's state.
  • It updates the button's color by adding or removing classes based on the checkbox's checked status.
  • Finally, it sets the value of an element with the ID "t_and_c" to 1 if the checkbox is checked, or 0 if it is unchecked.

The init() function is called to initialize the display of each button-checkbox element. It updates the display and injects an icon if one doesn't exist already.

After the loop, the code sets up another event handler using plain JavaScript:

$("#check_pass2 input").keyup(validate);. It selects an input element within an element with the ID "check_pass2" and attaches a keyup event handler to it. Whenever a key is released within that input, the validate() function is called.

The validate() function is responsible for comparing two password inputs and updating their validation status. It performs the following actions:

  • It retrieves the values of two password inputs, #check_pass1 input and #check_pass2 input, and stores them in the variables pas1 and pas2 respectively.
  • It selects an element with the ID "check_pass2" and an icon within it, and stores them in the variables pas2_on and $("#check_pass2 i") respectively.
  • It checks if the two passwords match. If they do, it updates the icon class to show a checkmark and adds the "valid" class to the "check_pass2" element.
  • If the passwords don't match, it updates the icon class to show a cross and adds the "not-valid" class to the "check_pass2" element.

Create a JavaScript file with the name of script.js and paste the given codes into your JavaScript file and make sure it's linked properly to your HTML document, so that the scripts are executed on the page. Remember, you’ve to create a file with .js extension.

$(function() {
  $('.button-checkbox').each(function() {

    // Settings
    var $widget = $(this),
      $button = $widget.find('button'),
      $checkbox = $widget.find('input:checkbox'),
      color = $button.data('color'),
      settings = {

        on: {
          icon: 'glyphicon glyphicon-check'
        },
        off: {
          icon: 'glyphicon glyphicon-unchecked'
        }
      };

    // Event Handlers
    $button.on('click', function() {
      $checkbox.prop('checked', !$checkbox.is(':checked'));
      $checkbox.triggerHandler('change');
      updateDisplay();
    });

    $checkbox.on('change', function() {
      updateDisplay();
    });

    // Actions
    function updateDisplay() {
      var isChecked = $checkbox.is(':checked');
      // Set the button's state
      $button.data('state', (isChecked) ? "on" : "off");
      // Set the button's icon
      $button.find('.state-icon')
      .removeClass()
      .addClass('state-icon ' + settings[$button.data('state')].icon);
      // Update the button's color
      if (isChecked) {
        $button
          .removeClass('btn-default')
          .addClass('btn-' + color + ' active');
        $("#t_and_c").val(1);
      } else {
        $button
          .removeClass('btn-' + color + ' active')
          .addClass('btn-default');
        $("#t_and_c").val(0);
      }
    }

    // Initialization
    function init() {
      updateDisplay();
      // Inject the icon if applicable
      if ($button.find('.state-icon').length == 0) {
        $button.prepend(' ');
      }
    }
    init();
  });
});

$("#check_pass2 input").keyup(validate);
function validate() {
  var pas1 = $("#check_pass1 input").val(),
      pas2 = $("#check_pass2 input").val(),
      pas2_on = $("#check_pass2 i");
  if (pas1 == pas2) {
    pas2_on.attr('class', 'glyphicon glyphicon-ok');
    $("#check_pass2").removeClass('not-valid').addClass("valid");
  } else {
    if (!pas2_on.hasClass("not_valid")) {
      pas2_on.attr('class', 'glyphicon glyphicon-remove');
      $("#check_pass2").removeClass('valid').addClass("not-valid");
    }
  }
}

Final Output:

Responsive Bootstrap Registration Form.gif

Conclusion:

Congratulations! You have successfully completed our comprehensive guide on creating a Bootstrap registration form. By following the step-by-step instructions and utilizing Bootstrap's powerful features, you have gained the knowledge and skills to design a responsive and customizable registration form for your website.

Throughout this tutorial, we discussed the benefits of using Bootstrap for registration forms, including its mobile-friendly nature and easy customization options. Bootstrap's pre-built components, CSS classes, and styles have allowed you to create a visually appealing form that adapts seamlessly to different screen sizes and devices.

We started by setting up the HTML structure of the registration form, ensuring proper tags and elements are in place. Then, we applied Bootstrap's classes and styles to enhance the form's visual appearance, making it more engaging and user-friendly.

To improve the user experience and data integrity, we added form validation using Bootstrap's built-in validation styles and JavaScript plugins. This helps ensure that users enter valid and complete information while receiving helpful error messages when needed.

Furthermore, we explored customization options to make your registration form unique and aligned with your website's branding. You learned how to modify colors, typography, spacing, and incorporate additional form components to meet your specific requirements.

Remember, this tutorial serves as a foundation for your registration form design. Feel free to experiment, add your creative touch, and further enhance your form based on your website's needs and aesthetics. Bootstrap provides countless possibilities for customization, allowing you to create registration forms that seamlessly integrate into your website's overall design.

By implementing the knowledge gained from this guide, you have empowered yourself to create effective and user-friendly registration forms that provide a smooth onboarding experience for your website visitors. Stay updated with the latest Bootstrap developments to leverage new features and techniques for even more impressive form designs.

Thank you for joining us on this journey to master Bootstrap registration forms. We hope this tutorial has been valuable to you and wish you success in implementing your newly acquired skills. Good luck with your future registration form projects, and happy coding!

That’s a wrap!

I hope you enjoyed this post. Now, with these examples, you can create your own amazing page.

Did you like it? Let me know in the comments below 🔥 and you can support me by buying me a coffee

And don’t forget to sign up to our email newsletter so you can get useful content like this sent right to your inbox!

Thanks!
Faraz 😊

End of the article

Subscribe to my Newsletter

Get the latest posts delivered right to your inbox


Latest Post

Please allow ads on our site🥺