Stylish search form or search box for Blogger blog

Stylish search form or search box for Blogger blog
Stylish search form or search box for Blogger blog
 

Most of the Blogger themes you will come across doesn't have an eye-catchy and elegant search form. If you are looking for a stylish search form for your Blogger blog, then you've come to the right place.

With the search form or box codes, we have here, simply adding it as a widget or inside your Blogger theme HTML will make it look more professional and attractive.

In every website, a search box is empirical and it helps your visitors easily navigate different sections of your website, thus, increasing engagement and reducing bounce rate as well.

A visitor arrives on your website from a particle URL either from a web search or social media. He or she has access to the content on this link, but he or she can't see all the other contents. For this reason, we always have a search form which will help users search for other contents.

Stylish search box for Blogger

One can always add a search form to a webpage, but the main issue w be whether it actual serves the purpose for which it was added for.

You will come across some stylish search forms online but these are in most cases merely for illustrative purposes and if added to your site won't work.

A search box added to any website should be able to crawl all sections of the said website.

Below, we have some working sample codes that will help you add a stylish search box/form to your Blogger site and make it look more professional.

Animated search form for Blogger


This Blogger search form widget can be easily added to the sidebar section or even the menu. The width of the search form will increase to 100% width when you placed the mouse pointer to start typing a search term.

The good thing about this search form is that it is simple yet stylish and of just a few lines of code. Below we have the code for this search box.
<!--Blogger Customiz Animated search form-->
<style>
.bc-anim-input[type=text] {
width: 250px;
box-sizing: border-box;
border: 4px solid #ccc;
border-radius: 10px;
font-size: 16px;
background-color: white;
background-image: url('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq28SrTWu4RlsZM2SnmamcUUoCKnWPVBJVcYbU5LjuYAcYxcMWcv1KGKAwAkj-UmEX_DhF1hbNeDDN6C0AriGONO8MPrYI7ZuflgwLT9eADg2C3ayGvnyBsWMw3i1f6eg0P0qgVh0CWSk2/s21/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}

.bc-anim-input[type=text]:focus {
width: 100%;
}
</style>
<form action="/search" method="get">
<input class="bc-anim-input" name="q" type="text" />
</form>

Search form or box with autocomplete option.

You can add a search form and provide keywords based on popular queries from your website. This way, each time a user starts typing something to search, he will get suggestions to choose from.


From the above demo example, you can see how this search form works. Below is the code for the above search form.
  <!--Blogger search form with autocomplete-->
<style>
* {
box-sizing: border-box;
}

body {
font: 16px Arial;
}

/*the container must be positioned relative:*/
.autocomplete {
position: relative;
display: inline-block;
}

.bc-autocomplet-input {
border: 2px solid #ff6105;
border-radius:5px;
background-color: white;
padding: 10px;
font-size: 16px;
}

.bc-autocomplet-input[type=text] {
background-color: white;
width: 100%;
}

.bc-autocomplet-input[type=submit] {
background-color: DodgerBlue;
color: #fff;
cursor: pointer;
}

.autocomplete-items {
position: absolute;
border: 1px solid #d4d4d4;
border-bottom: none;
border-top: none;
z-index: 99;
/*position the autocomplete items to be the same width as the container:*/
top: 100%;
left: 0;
right: 0;
}

.autocomplete-items div {
padding: 10px;
cursor: pointer;
background-color: #fff;
border-bottom: 1px solid #d4d4d4;
}

/*when hovering an item:*/
.autocomplete-items div:hover {
background-color: #e9e9e9;
}

/*when navigating through the items using the arrow keys:*/
.autocomplete-active {
background-color: DodgerBlue !important;
color: #ffffff;
}
</style>
<!--Custom search form starts-->
<form action="/search" autocomplete="off" method="get">
<div class="autocomplete" style="width: 300px;">
<input class="bc-autocomplet-input" id="myInput" name="q" type="text" />
</div>
<input class="bc-autocomplet-input" type="submit" />
</form>

<script>
function autocomplete(inp, arr) {
/*the autocomplete function takes two arguments,
the text field element and an array of possible autocompleted values:*/
var currentFocus;
/*execute a function when someone writes in the text field:*/
inp.addEventListener("input", function(e) {
var a, b, i, val = this.value;
/*close any already open lists of autocompleted values*/
closeAllLists();
if (!val) { return false;}
currentFocus = -1;
/*create a DIV element that will contain the items (values):*/
a = document.createElement("DIV");
a.setAttribute("id", this.id + "autocomplete-list");
a.setAttribute("class", "autocomplete-items");
/*append the DIV element as a child of the autocomplete container:*/
this.parentNode.appendChild(a);
/*for each item in the array...*/
for (i = 0; i < arr.length; i++) {
/*check if the item starts with the same letters as the text field value:*/
if (arr[i].substr(0, val.length).toUpperCase() == val.toUpperCase()) {
/*create a DIV element for each matching element:*/
b = document.createElement("DIV");
/*make the matching letters bold:*/
b.innerHTML = "<strong>" + arr[i].substr(0, val.length) + "</strong>";
b.innerHTML += arr[i].substr(val.length);
/*insert a input field that will hold the current array item's value:*/
b.innerHTML += "<input type='hidden' value='" + arr[i] + "'>";
/*execute a function when someone clicks on the item value (DIV element):*/
b.addEventListener("click", function(e) {
/*insert the value for the autocomplete text field:*/
inp.value = this.getElementsByTagName("input")[0].value;
/*close the list of autocompleted values,
(or any other open lists of autocompleted values:*/
closeAllLists();
});
a.appendChild(b);
}
}
});
/*execute a function presses a key on the keyboard:*/
inp.addEventListener("keydown", function(e) {
var x = document.getElementById(this.id + "autocomplete-list");
if (x) x = x.getElementsByTagName("div");
if (e.keyCode == 40) {
/*If the arrow DOWN key is pressed,
increase the currentFocus variable:*/
currentFocus++;
/*and and make the current item more visible:*/
addActive(x);
} else if (e.keyCode == 38) { //up
/*If the arrow UP key is pressed,
decrease the currentFocus variable:*/
currentFocus--;
/*and and make the current item more visible:*/
addActive(x);
} else if (e.keyCode == 13) {
/*If the ENTER key is pressed, prevent the form from being submitted,*/
e.preventDefault();
if (currentFocus > -1) {
/*and simulate a click on the "active" item:*/
if (x) x[currentFocus].click();
}
}
});
function addActive(x) {
/*a function to classify an item as "active":*/
if (!x) return false;
/*start by removing the "active" class on all items:*/
removeActive(x);
if (currentFocus >= x.length) currentFocus = 0;
if (currentFocus < 0) currentFocus = (x.length - 1);
/*add class "autocomplete-active":*/
x[currentFocus].classList.add("autocomplete-active");
}
function removeActive(x) {
/*a function to remove the "active" class from all autocomplete items:*/
for (var i = 0; i < x.length; i++) {
x[i].classList.remove("autocomplete-active");
}
}
function closeAllLists(elmnt) {
/*close all autocomplete lists in the document,
except the one passed as an argument:*/
var x = document.getElementsByClassName("autocomplete-items");
for (var i = 0; i < x.length; i++) {
if (elmnt != x[i] && elmnt != inp) {
x[i].parentNode.removeChild(x[i]);
}
}
}
/*execute a function when someone clicks in the document:*/
document.addEventListener("click", function (e) {
closeAllLists(e.target);
});
}

/*An array containing all keywords: Change the keywords here to match your site contents*/
var q = ["Fletro","Magone","GoomShop","Estimate read time","Progressive web app for Blogger","Elementor pro free","Masterstydy","Label page description for Blogger", "Premium Blogger themes", "Median UI", "Materia X2 blogger theme", "amp templates for Blogger", "Wordpress Progressive web app plugins", "Soracart Blogger template", "Easycart"];

/*initiate the autocomplete function on the "myInput" element, and pass along the countries array as possible autocomplete values:*/
autocomplete(document.getElementById("myInput"), q);
</script>

To use this search form, you will have to customise the keywork part of the JavaScript code. Chenge the keyworkds on the section "An arrat containing all keywords:" with your own keywords to make contents on your Blogger blog.

Meaning from the code above, you will have to look for the following part of the Javascript code and change the keywords.


/*An array containing all the country names in the world:*/
var q = ["Fletro","Magone","GoomShop","Estimate read time","Progressive web app for Blogger","Elementor pro free","Masterstydy","Label page description for Blogger", "Premium Blogger themes", "Median UI", "Materia X2 blogger theme", "amp templates for Blogger", "Wordpress Progressive web app plugins", "Soracart Blogger template", "Easycart"];

Simple stylish Blogger search box with clear option

This simple yet stylish Blogger search form with option to clear search term.

The code for the above search form can be found below.


<style>
body {
background-color: #f1f1f1;
font-family: Helvetica,Arial,Verdana;

}
.search-box,.close-icon,.search-wrapper {
position: relative;
padding: 10px;
}
.search-wrapper {
width: 98%;
margin: auto;
margin-top: 50px;
}
.search-box {
width: 80%;
border: 2px solid #ccc;
outline: 0;
border-radius: 15px;
}
.search-box:focus {
box-shadow: 0 0 15px 5px #b0e0ee;
border: 2px solid #bebede;
}
.close-icon {
border:1px solid transparent;
background-color: transparent;
display: inline-block;
vertical-align: middle;
outline: 0;
cursor: pointer;
}
.close-icon:after {
content: "X";
display: block;
width: 15px;
height: 15px;
position: absolute;
background-color: #FA9595;
z-index:1;
right: 35px;
top: 0;
bottom: 0;
margin: auto;
padding: 2px;
border-radius: 50%;
text-align: center;
color: white;
font-weight: normal;
font-size: 12px;
box-shadow: 0 0 2px #E50F0F;
cursor: pointer;
}
.search-box:not(:valid) ~ .close-icon {
display: none;

}
input[type=text] {background-image: url('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq28SrTWu4RlsZM2SnmamcUUoCKnWPVBJVcYbU5LjuYAcYxcMWcv1KGKAwAkj-UmEX_DhF1hbNeDDN6C0AriGONO8MPrYI7ZuflgwLT9eADg2C3ayGvnyBsWMw3i1f6eg0P0qgVh0CWSk2/s21/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
}
</style>
<div class="search-wrapper">
<form action="/search" method="get">
<input type="text" name="q" required class="search-box" placeholder="Search this blog" />
<button class="close-icon" type="reset"></button>
</form>
</div>

Post a Comment

Previous Post Next Post

Contact Form