<div class="search-form">
		<div class="input-holder">
			<input type="text" class="search-input" placeholder="Enter your search text" />
			<button class="search-icon" onclick="searchToggle(this, event);"><span></span></button>
		</div>
		<span class="close" onclick="searchToggle(this, event);"></span>
	</div>
body {background: #ccc;}	
.search-form {
    position: absolute;
    transform: translate(-50%, -50%);
    top: 50%;
    left: 50%;
}
.search-form .input-holder {    
    height: 70px;
    width: 70px;
    overflow: hidden;
    border-radius: 6px;
    position: relative;
    transition: all 0.3s ease-in-out;
}
.search-form.active .input-holder {
    width: 450px;
    border-radius: 50px;
    background: rgba(0,0,0,0.7);
    transition: all .5s cubic-bezier(0.000, 0.105, 0.035, 1.570);
}

.search-input::placeholder {color: #f5f5f5;}
.search-form .input-holder .search-input {
    width:100%;
    height: 50px;
    padding: 0 70px 0 20px;
    opacity: 0;
    position: absolute;
    top: 0;
    left: 0;
    background: transparent;
    box-sizing: border-box;
    border: none;
    outline: none;
    font-family: "Open Sans", sans;
    font-size: 20px;
    line-height: 20px;
    color:#fff;
    transform: translate(0, 60px);
    transition: all .3s cubic-bezier(0.000, 0.105, 0.035, 1.570);
    transition-delay: 0.3s;
}
.search-form.active .input-holder .search-input {
    opacity: 1;
    transform: translate(0, 10px);
}
.search-form .input-holder .search-icon {
    width: 70px;
    height: 70px;
    border: none;
    border-radius: 7px;
    background: #f5f5f5;
    padding: 0;
    outline: none;
    position: relative;
    z-index: 2;
    float:right;
    cursor: pointer;
    transition: all 0.3s ease-in-out;
}
.search-form.active .input-holder .search-icon {
    width: 50px;
    height: 50px;
    margin: 10px;
    border-radius: 30px;
}
.search-form .input-holder .search-icon span {
    width: 28px;
    height: 35px;
    display: inline-block;
    vertical-align: middle;
    position:relative;
    transform: rotate(45deg);
    transition: all .4s cubic-bezier(0.650, -0.600, 0.240, 1.650);
}
.search-form.active .input-holder .search-icon span {
    transform: rotate(-45deg);
}
.search-form .input-holder .search-icon span::before, .search-form .input-holder .search-icon span::after {
    position: absolute; 
    content:'';
}
.search-form .input-holder .search-icon span::before {
    width: 5px;
    height: 15px;
    left: 12px;
    top: 25px;
    border-radius: 2px;
    background: #4080ff;
}
.search-form .input-holder .search-icon span::after {
    width: 20px;
    height: 20px;
    left: 0;
    top: 0;
    border-radius: 15px;
    border: 4px solid #4080ff;
}
.search-form .close {
    position: absolute;
    z-index: 1;
    top: 24px;
    right: 20px;
    width: 25px;
    height: 25px;
    cursor: pointer;
    transform: rotate(-180deg);
    transition: all .3s cubic-bezier(0.285, -0.450, 0.935, 0.110);
    transition-delay: 0.2s;
}
.search-form.active .close {
    right: -30px;
    transform: rotate(45deg);
    transition: all .6s cubic-bezier(0.000, 0.105, 0.035, 1.570);
    transition-delay: 0.5s;
}
.search-form .close::before, .search-form .close::after {
    position:absolute;
    content:'';
    background: #fff;
    border-radius: 2px;
}
.search-form .close::before {
    width: 3px;
    height: 15px;
    left: 12px;
    top: 1px;
}
.search-form .close::after {
    width: 15px;
    height: 3px;
    left: 6px;
    top: 7px;
}
function searchToggle(obj, evt){
	var container = jQuery(obj).closest('.search-form');
	if(!container.hasClass('active')){
		container.addClass('active');
		evt.preventDefault();
	}
	else if(container.hasClass('active') && jQuery(obj).closest('.input-holder').length == 0){
		container.removeClass('active');
		container.find('.search-input').val(''); // input clear
	}
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js