Animated Search Box Using HTML & CSS

Hello wizards, I hope you are doing great. Today in this blog you’ll learn how to create the "Animated Search Box" project using HTML & CSS.

Preview 

In the above video, you’ve seen the preview of the "Animated Search Box" project and I hope you are now able to create this type of project. If not, I have provided all the HTML & CSS code below. 

Animated Search Box [Source Code] 

To get the following HTML & CSS code for the Animated Search Box project. You need to create two files one is an HTML file, and the second one is a CSS file. After completing these two files, you can copy-paste the codes on your document. 

Remember, you’ve to create a file with a .html extension for HTML code and a .css extension for CSS code.

You can also download all source code files from the given download button.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Animated Search Box</title>
    <link rel="stylesheet" href="style.css">

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"
        integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>

<body>

    <h1>Animated Search Box</h1>
    <div class="container">
        <input type="checkbox" id="checkbox">
        <div class="search-box">
            <input type="text" placeholder="Search...">
            <label for="checkbox" class="icon">
                <i class="fas fa-search"></i>
            </label>
        </div>
    </div>

</body>

</html>
CSS
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Poppins", sans-serif;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  height: 100vh;
  background-color: lightblue;
}

h1 {
  margin-bottom: 20px;
}

.container {
  max-width: 400px;
  width: 100%;
}

#checkbox {
  display: none;
}

.container .search-box {
  position: relative;
  height: 50px;
  max-width: 50px;
  margin: auto;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
  border-radius: 25px;
  transition: all 0.3s ease-in-out;
}

#checkbox:checked ~ .search-box {
  max-width: 380px;
}

.search-box input {
  font-size: 18px;
  position: absolute;
  outline: none;
  border: none;
  background: white;
  height: 100%;
  width: 100%;
  border-radius: 25px;
  padding-left: 20px;
}

.search-box .icon {
  cursor: pointer;
  width: 50px;
  height: 100%;
  font-size: 20px;
  text-align: center;
  line-height: 50px;
  border-radius: 25px;
  color: blue;
  background: white;
  position: absolute;
  top: 0;
  right: 0;
}

#checkbox:checked ~ .search-box .icon {
  width: 60px;
  color: white;
  background: blue;
  border-radius: 0 25px 25px 0;
}
You have to wait 15 seconds.

Generating Download Link...

Post a Comment

Previous Post Next Post