How To Make a Responsive Form using HTML, Css and JavaScript?

TechLoons
2 min readApr 10, 2024

Here is the solution or code to create a responsive form using HTML, CSS and JavaScript: Projects for beginner’s using HTMl, CSS and JavaScript

Simply you need to copy both codes and paste it in your vs code and you can use it freely.

1. index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Form UI Design</title>

<!-- custom css file linked -->
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<div class="container">
<!-- form -->
<form action="#">

<h2 class="form-heading">Registration Form</h3>
<!-- name input fields -->
<div class="name-input">
<input
type="text"
class="name-input-field"
placeholder="First Name"
required
/>
<input type="text" class="name-input-field" placeholder="Last Name" />
</div>

<!-- other input fields -->
<div class="other-input">
<input type="email" required placeholder="Email" />
<input type="text" required placeholder="Mobile" />
<input type="password" required placeholder="Password" />
<input type="password" required placeholder="Confirm Password" />
</div>

<!-- terms and condition -->
<div class="tnc">
<p>
<input type="checkbox" class="chechbox" required />
</p>
<p>Agree to terms & conditions.</p>
</div>

<!-- submit button -->
<button class="btn">Submit</button>
</form>
</div>
</body>
</html>

2. style.css

* {
font-family: Arial, Helvetica, sans-serif;
}

.container {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}

form {
background: #53E0BC;
width: 450px;
height: 600px;
display: flex;
flex-direction: column;
justify-content: center;
gap: 15px;
padding-left: 5px;
border-radius: 10px;
}

.form-heading {
text-align: center;
color: #fff;
}

input {
font-size: 16px;
border: 0;
outline: none;
background: #ffffff;
border-radius: 10px;
height: 40px;
width: 90%;
padding: 3px 15px;
}

.name-input {
display: flex;
justify-content: flex-start;
align-items: center;
gap: 15px;
padding-left: 10px;
}

.name-input-field {
width: 40% !important;
}

.other-input {
display: flex;
flex-direction: column;
align-items: center;
gap: 15px;
}


.tnc {
cursor: pointer;
width:300px !important;
display: flex;
justify-content: flex-start;
align-items: center;
gap: 10px;
padding-left: 10px;
}

.btn {
outline: 0;
border: 0;
border-radius: 10px;
height: 40px;
width: 100px;
font-weight: 600;
margin-left: 38%;
background: #fff;
}

.btn:hover {
cursor: pointer;
background: #EAF0F1;
}

--

--

TechLoons

Welcome to TechLoons, your go-to source for the latest tips and information on a wide range of topics.