Animated Search Form with HTML & CSS
01/12/2021
Contents
Demo
Code
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Animated 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 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: #1e1b14;
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;
background-image: url(search_01.svg);
background-position: center;
background-size: 20px 20px;
background-repeat: no-repeat;
background-color: #f43c48;
color: rgba(0,0,0,0);
font-size: 1rem;
outline: none;
cursor: pointer;
transition: width .2s;
}
.form-input::placeholder {
opacity: 0;
color: #cecdd3;
font-size: 1rem;
}
.form-input:focus {
width: 100%;
height: 50px;
border-radius: 25px;
background-image: url(search_02.svg);
background-position: 95%;
background-size: 20px 20px;
background-repeat: no-repeat;
background-color: #fff;
color: rgba(0,0,0,1);
cursor: text;
}
.form-input:focus::placeholder {
opacity: 1;
}
h1 {
margin: 30px 0;
color: #fff;
font-size: 3rem;
letter-spacing: 1px;
text-align: center;
}
@media screen and (max-width: 480px) {
h1 {
margin: 10px 0;
font-size: 2rem;
}
}