How to create: a form with icons

Learn how to create a form with icons.

Register

Try it yourself

How to create an icon form

Step 1 - Add HTML:

Use the <form> element to handle input. You can learn more about related information in our PHP tutorial.

Then add input controls for each field:

<form action="/action_page.php">
  <h2>Register Form</h2>
  <div class="input-container">
    <i class="fa fa-user icon"></i>
    <input class="input-field" type="text" placeholder="Username" name="usrnm">
  </div>
  <div class="input-container">
    <i class="fa fa-envelope icon"></i>
    <input class="input-field" type="text" placeholder="Email" name="email">
  </div>
  <div class="input-container">
    <i class="fa fa-key icon"></i>
    <input class="input-field" type="password" placeholder="Password" name="psw">
  </div>
  <button type="submit" class="btn">Register</button>
</form>

Step 2 - Add CSS:

* {box-sizing: border-box;}
/* Set the style for the input container */
.input-container {
  display: flex;
  width: 100%;
  margin-bottom: 15px;
}
/* Set the style for the form icon */
.icon {
  padding: 10px;
  background: dodgerblue;
  color: white;
  min-width: 50px;
  text-align: center;
}
/* Set the style for the input field */
.input-field {
  width: 100%;
  padding: 10px;
  outline: none;
}
.input-field:focus {
  border: 2px solid dodgerblue;
}
/* Set the style for the submit button */
.btn {
  background-color: dodgerblue;
  color: white;
  padding: 15px 20px;
  border: none;
  cursor: pointer;
  width: 100%;
  opacity: 0.9;
}
.btn:hover {
  opacity: 1;
}

Try it yourself

Related pages

Tutorial:HTML form

Tutorial:CSS form

Tutorial:CSS Flexbox