top of page
  • Writer's pictureDark CSS

Creating a Stunning Registration Form with Background Image

Introduction

In today's digital age, crafting visually appealing and user-friendly registration forms is crucial for websites and applications. In this tutorial, we'll walk through the process of creating a captivating registration form with a background image using HTML and CSS. From setting up the project to explaining the code intricacies, this guide will help you understand every step involved in the development process.



Registration Form with Background Image


Setting Up Your Project

To begin, let's create two files: index.html and style.css. The index.html file will contain the structure of our registration form, while style.css will handle the visual styling.


HTML Code

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Registration Form with Background Image</title>
  <link rel="stylesheet" href="style.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
</head>
<body>
   <div class="wrapper">
     <div class="form">
       <header>Registration</header>
       <form action="">
         <div class="field fname">
           <div class="input-area">
             <input type="text" placeholder="First Name">
             <i class="icon fas fa-user"></i>
           </div>
         </div>
         <!-- More input fields for last name, email, password -->
         <div class="radio_btn">
           <input type="radio" name="r1" id="male" checked>
           <label for="male">Male</label>
           <input type="radio" name="r1" id="female">
           <label for="female">Female</label>
         </div>
         <div class="select-btn">
           <select name="Countries">
             <option value="">Select Country</option>
             <!-- List of countries -->
           </select>
         </div>
         <input type="submit" value="Signup">
       </form>
     </div>
   </div>
</body>
</html>

Html Code Explanation

The provided HTML code outlines the structure of a registration form within a standard HTML document. It begins with the document declaration and language specification, followed by linking external stylesheets and setting the title. The form itself is encapsulated within a wrapper `<div>` and a form-specific `<div>` for styling purposes. Each input field, including first name, last name, email, and password, is wrapped within a designated `<div>` with corresponding classes. Font Awesome icons are integrated alongside input fields for aesthetic appeal. Gender selection via radio buttons and country selection through a dropdown menu are also included. The form concludes with a submit button labeled "Signup". This concise structure provides a foundation for creating visually appealing and functional registration forms for web applications.





CSS Code

  /* Reset default styling for all elements */
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

/* Set background image for the body */
body {
  background-image: url("images/bg1.jpg");
  width: 100%;
  height: 100%;
  background-size: cover; /* Ensure the background image covers the entire viewport */
}

/* Style the registration form container */
.form {
  position: 
  top: 50%; 
  left: 25%;
  transform: translate(-50%, -50%); 
  width: 380px;
  height: 470px;
  background: #fff;
  border-radius: 5px;
  text-align: center; 
  font-family: sans-serif;
  padding: 20px 30px 5px 30px;
  box-shadow: 0px 5px 20px 10px rgba(0, 0, 0, 0.2); 
}

/* Style the header within the form */
.form header {
  font-size: 25px; 
  font-weight: 600;
}

/* Style the form element */
.form form {
  margin: 15px 0;
}

/* Style the input field containers */
form .field {
  width: 100%;
  margin-bottom: 20px;
}

/* Style the input area within the field */
form .field .input-area {
  position: relative;
}

/* Style the input fields */
form input {
  height: 40px;
  width: 100%;
  outline: none;
  padding: 0 15px;
  padding-left: 40px; 
  font-size: 15px; 
  border-radius: 5px;
  border: 1px solid #34495e;
  border-bottom-width: 2px;
}

/* Style the placeholder text within input fields */
form input::placeholder {
  color: #bfbfbf;
  font-size: 14px;
}

/* Style the icon within the input field */
form .field i {
  position: absolute;
  top: 50%;
  font-size: 15px;
  pointer-events: none; 
  transform: translateY(-50%);
}

/* Style the icon itself */
form .field .icon {
  left: 15px;
  color: #34495e;
}

/* Style the radio button container */
form .radio_btn {
  display: flex;
  flex-direction: row; /* Arrange items horizontally */
  font-size: 15px;
  font-weight: 600; 
}

/* Style the radio buttons */
form input[type="radio"] {
  width: 14px;
  height: 14px; 
  margin: 2px 7px; 
}

/* Style the dropdown menu container */
form .select-btn {
  margin-top: 20px;
}

/* Style the dropdown menu */
form select {
  height: 40px;
  width: 100%; 
  outline: none; /* Remove outline */
  padding: 0 15px;
  border-radius: 5px; 
  border: 1px solid #34495e;
  border-bottom-width: 2px; 
  font-size: 13px; 
}

/* Style the submit button */
form input[type="submit"] {
  margin-top: 20px;
  border: none;
  background: #34495e;
  color: #fff; 
  font-size: 14px; 
  cursor: pointer;
  letter-spacing: 1px;
  font-weight: 500;
  transition: background 0.2s ease;
}

/* Style the submit button on hover */
form input[type="submit"]:hover {
  background: #333867;
}

CSS Code Explanation


The CSS code provided styles the registration form defined in the HTML document. It utilizes various properties to achieve a visually appealing and user-friendly layout. Key properties used include:

*: Resets default padding, margin, and box-sizing for all elements to ensure consistent styling throughout the document. body: Sets a background image for the body, covering the entire viewport. .form: Styles the registration form container, positioning it absolutely in the center of the viewport with specific dimensions, background color, border radius, and shadow effect.

.form header: Defines styles for the form header, such as font size and weight.

.form form: Styles the form element itself, adding margin to separate it from other elements.

form .field: Styles the input field container, ensuring it spans the entire width of its parent and adds bottom margin for spacing between fields.

form input: Defines styles for input fields, including height, width, padding, font size, border radius, and border color.

form input::placeholder: Styles the placeholder text within input fields, setting color and font size.

form .field i: Styles the icon container within input fields, positioning it absolutely and vertically aligning it in the middle.

form .field .icon: Styles the icon itself, setting its position and color.

form .radio_btn: Styles the container for radio buttons, setting display to flex for alignment and defining font properties.

form input[type="radio"]: Styles radio buttons, setting width, height, and margins for proper spacing.

form .select-btn: Styles the container for the country dropdown menu, adding margin for spacing.

form select: Styles the dropdown menu, setting height, width, padding, border radius, and border color.

form input[type="submit"]: Styles the submit button, setting margins, background color, text color, font properties, cursor, and transition effect.

form input[type="submit"]:hover: Styles the submit button on hover, changing the background color for a visual effect.

These CSS rules collectively define the layout, appearance, and behavior of the registration form, ensuring a consistent and visually appealing user experience.


Conclusion

In this tutorial, we've learned how to create a registration form with a background image using HTML and CSS. By following the step-by-step guide and understanding the code explanations, you can enhance your web development skills and create stunning user interfaces for your projects. Experiment with different styles and elements to personalize your forms and make them stand out!



Registration Form
.zip
Download ZIP • 367KB

Related Posts

See All

Dark CSS

bottom of page