Animated Neumorphism Search Form with HTML & CSS

01/15/2021

Contents

Demo

Full Screen

Code

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Animated Neumorphism Search Form</title>
    <link rel="stylesheet" type="text/css" href="https://demo.plantpot.works/assets/css/normalize.css">
    <link rel="stylesheet" href="https://use.typekit.net/opg3wle.css">
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <div id="container">
      <form class="form">
        <input class="form-input" type="text" name="search" placeholder="Search...">
      </form>
      <h1>Animated Neumorphism<br>Search Form</h1>
    </div>
  </body>
</html>

CSS

@charset "utf-8";
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  font-size: 16px;
}
body {
  background-color: #ecf0f3;
  font-family: futura-pt, sans-serif;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}
#container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
  padding: 20px;
}
.form {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: 300px;
}
.form-input {
  width: 50px;
  height: 50px;
  padding: 5px 15px;
  border: none;
  border-radius: 25px;
  box-shadow: -2px -2px 8px rgba(255, 255, 255, 1),
              -2px -2px 12px rgba(255, 255, 255, 0.5),
              inset 2px 2px 4px rgba(255, 255, 255, 0.1),
              2px 2px 8px rgba(0, 0, 0, .3);
  background-image: url(search.svg);
  background-position: center;
  background-size: 18px 18px;
  background-repeat: no-repeat;
  background-color: #ecf0f3;
  color: rgba(0,0,0,0);
  font-size: 1rem;
  outline: none;
  cursor: pointer;
  transition: width .2s;
}
.form-input::placeholder {
  opacity: 0;
  color: #262524;
  font-size: 1rem;
}
.form-input:focus {
  width: 100%;
  height: 50px;
  border-radius: 25px;
  box-shadow: inset -2px -2px 8px rgba(255, 255, 255, 1),
              inset -2px -2px 12px rgba(255, 255, 255, 0.5),
              inset 2px 2px 4px rgba(255, 255, 255, 0.1),
              inset 2px 2px 8px rgba(0, 0, 0, .3);
  background-image: url(search.svg);
  background-position: 95%;
  background-size: 18px 18px;
  background-repeat: no-repeat;
  background-color: #ecf0f3;
  color: rgba(0,0,0,1);
  cursor: text;
}
.form-input:focus::placeholder {
  opacity: 1;
}
h1 {
  margin: 30px 0 0;
  color: #262524;
  font-size: 2.75rem;
  letter-spacing: 1px;
  text-align: center;
}
@media screen and (max-width: 480px) {
  h1 {
    margin: 10px 0 0;
    font-size: 1.75rem;
  }
}