Html add search bar

  • HTML Tutorial
  • HTML Introduction
  • HTML full form
  • HTML Editors
  • HTML Comments
  • HTML Basics
  • HTML Layout
  • HTML Elements
  • HTML Heading
  • HTML Paragraphs
  • HTML Text Formatting
  • HTML Quotations
  • HTML Color Styles and HSL
  • HTML Links
  • HTML Images
  • HTML Tables
  • HTML Lists
  • HTML Block and Inline Elements
  • HTML Iframes
  • HTML File Paths
  • HTML Viewport meta tag for Responsive Web Design
  • HTML Computer Code Elements
  • HTML Entities
  • HTML Charsets
  • HTML | URL Encoding
  • HTML | Deprecated Tags
  • HTML Attributes
  • HTML | accept Attribute
  • HTML accept-charset Attribute
  • HTML accesskey Attribute
  • HTML| action Attribute
  • HTML align Attribute
  • HTML alt attribute
  • HTML | async Attribute
  • HTML input autocomplete Attribute
  • HTML autocomplete Attribute
  • HTML autofocus Attribute
  • HTML input autofocus Attribute
  • HTML autofocus Attribute
  • HTML autofocus Attribute
  • HTML Attributes Complete Reference
  • DOM (Document Object Model)
  • HTML DOM activeElement Property
  • HTML DOM anchors Collection
  • HTML DOM close() Method
  • HTML DOM baseURI Property
  • HTML DOM body Property
  • HTML DOM createAttribute() Method
  • HTML DOM doctype Property
  • HTML DOM writeln() Method
  • HTML DOM console error() Method
  • HTML DOM URL Property
  • HTML DOM embeds Collection
  • HTML DOM console warn() Method
  • HTML DOM console trace() Method
  • HTML DOM Complete Reference
  • HTML DOM Audio Object
  • HTML DOM Video Object
  • HTML DOM Video canPlayType( ) Method
  • HTML DOM Audio audioTracks Property
  • HTML DOM Audio autoplay Property
  • HTML DOM Audio buffered Property
  • HTML DOM Audio controls Property
  • HTML DOM Audio currentSrc Property
  • HTML DOM Audio currentTime Property
  • HTML DOM Audio defaultMuted Property
  • HTML DOM Audio defaultPlaybackRate Property
  • HTML DOM Audio duration Property
  • HTML DOM Audio ended Property
  • HTML DOM Audio loop Property
  • HTML DOM Audio/Video Complete Reference
  • Introduction to HTML CSS | Learn to Design your First Website in Just 1 Week
  • HTML Course | Structure of an HTML Document
  • HTML Course First Web Page Printing Hello World
  • HTML Course Basics of HTML
  • HTML Course : Starting the Project – Creating Directories
  • HTML Course Understanding and Building Project Structure
  • HTML Course : Creating Navigation Menu
  • HTML Course : Building Header of the Website
  • HTML Course : Building Main Content – Section 1
  • HTML Course | Building Main Content – Section 2
  • HTML course | Building Main Content – Section 3
  • HTML Course | Building Footer
  • HTML Course | Practice Quiz 1
  • HTML Course | Practice Quiz 2
  • Create a Sticky Social Media Bar using HTML and CSS
  • Create a Search Bar using HTML and CSS
  • How to create Right Aligned Menu Links using HTML and CSS ?
  • How to add a Login Form to an Image using HTML and CSS ?
  • How to Create a Tab Image Gallery ?
  • How to create a Hero Image using HTML and CSS ?
  • How to design Meet the Team Page using HTML and CSS ?
  • How to Create an Image Overlay Icon using HTML and CSS ?
  • How to Create Browsers Window using HTML and CSS ?
  • How to Create Breadcrumbs using HTML and CSS ?
  • How to Create Section Counter using HTML and CSS ?
  • How to Create Toggle Switch by using HTML and CSS ?
  • How to Create a Cutout Text using HTML and CSS ?
  • How to make a Pagination using HTML and CSS ?
  • HTML Tutorial
  • HTML Introduction
  • HTML full form
  • HTML Editors
  • HTML Comments
  • HTML Basics
  • HTML Layout
  • HTML Elements
  • HTML Heading
  • HTML Paragraphs
  • HTML Text Formatting
  • HTML Quotations
  • HTML Color Styles and HSL
  • HTML Links
  • HTML Images
  • HTML Tables
  • HTML Lists
  • HTML Block and Inline Elements
  • HTML Iframes
  • HTML File Paths
  • HTML Viewport meta tag for Responsive Web Design
  • HTML Computer Code Elements
  • HTML Entities
  • HTML Charsets
  • HTML | URL Encoding
  • HTML | Deprecated Tags
  • HTML Attributes
  • HTML | accept Attribute
  • HTML accept-charset Attribute
  • HTML accesskey Attribute
  • HTML| action Attribute
  • HTML align Attribute
  • HTML alt attribute
  • HTML | async Attribute
  • HTML input autocomplete Attribute
  • HTML autocomplete Attribute
  • HTML autofocus Attribute
  • HTML input autofocus Attribute
  • HTML autofocus Attribute
  • HTML autofocus Attribute
  • HTML Attributes Complete Reference
  • DOM (Document Object Model)
  • HTML DOM activeElement Property
  • HTML DOM anchors Collection
  • HTML DOM close() Method
  • HTML DOM baseURI Property
  • HTML DOM body Property
  • HTML DOM createAttribute() Method
  • HTML DOM doctype Property
  • HTML DOM writeln() Method
  • HTML DOM console error() Method
  • HTML DOM URL Property
  • HTML DOM embeds Collection
  • HTML DOM console warn() Method
  • HTML DOM console trace() Method
  • HTML DOM Complete Reference
  • HTML DOM Audio Object
  • HTML DOM Video Object
  • HTML DOM Video canPlayType( ) Method
  • HTML DOM Audio audioTracks Property
  • HTML DOM Audio autoplay Property
  • HTML DOM Audio buffered Property
  • HTML DOM Audio controls Property
  • HTML DOM Audio currentSrc Property
  • HTML DOM Audio currentTime Property
  • HTML DOM Audio defaultMuted Property
  • HTML DOM Audio defaultPlaybackRate Property
  • HTML DOM Audio duration Property
  • HTML DOM Audio ended Property
  • HTML DOM Audio loop Property
  • HTML DOM Audio/Video Complete Reference
  • Introduction to HTML CSS | Learn to Design your First Website in Just 1 Week
  • HTML Course | Structure of an HTML Document
  • HTML Course First Web Page Printing Hello World
  • HTML Course Basics of HTML
  • HTML Course : Starting the Project – Creating Directories
  • HTML Course Understanding and Building Project Structure
  • HTML Course : Creating Navigation Menu
  • HTML Course : Building Header of the Website
  • HTML Course : Building Main Content – Section 1
  • HTML Course | Building Main Content – Section 2
  • HTML course | Building Main Content – Section 3
  • HTML Course | Building Footer
  • HTML Course | Practice Quiz 1
  • HTML Course | Practice Quiz 2
  • Create a Sticky Social Media Bar using HTML and CSS
  • Create a Search Bar using HTML and CSS
  • How to create Right Aligned Menu Links using HTML and CSS ?
  • How to add a Login Form to an Image using HTML and CSS ?
  • How to Create a Tab Image Gallery ?
  • How to create a Hero Image using HTML and CSS ?
  • How to design Meet the Team Page using HTML and CSS ?
  • How to Create an Image Overlay Icon using HTML and CSS ?
  • How to Create Browsers Window using HTML and CSS ?
  • How to Create Breadcrumbs using HTML and CSS ?
  • How to Create Section Counter using HTML and CSS ?
  • How to Create Toggle Switch by using HTML and CSS ?
  • How to Create a Cutout Text using HTML and CSS ?
  • How to make a Pagination using HTML and CSS ?
Читайте также:  Шаблон css html генератор

Источник

Search Bar in HTML

Javascript Course - Mastering the Fundamentals

Search bar in HTML, is a text field that can be used to search content if we know the keywords in between the sentences. This search bar made using HTML is usually located within the navigation bar. Depending on the requirements, we can also add buttons, drop-down lists, and anchors to the navigation bar, along with the search box.

To make navigation easier, it is usually placed at the top of the page. An example of a search bar in HTML is shown below

search-bar

Pre-requisites

What are we Creating ?

We are creating a search bar in HTML and CSS. By entering a query or search term, the user can search for and retrieve relevant information from a database using this search bar.

search-bar-demo

How does Search Bar Work in HTML ?

It is used to search for whatever we want on the website. We have to input a keyword and if it is present it would return it. The syntax is shown below

Examples

Explanation :
We have created a nav bar with Home, Works, and Blog link fields. We then created a search bar and applied CSS to style it and make it beautiful.

output-of-search-bar-example-code

Explanation :
We have created an animated search with HTML and CSS. When we click on the search button it gets expanded this is possible due to the amazing CSS animation properties.

output-of-animated-search-bar-example-code

Output

Creating a Search Bar in HTML

We must first add a bar to the page.

Here are some HTML elements to use :

  • : This element asks users for input.
  • : There are several types of this element, today we will use search.
  • : Use this element to submit the form and begin searching.

The HTML will look like this :

This is all the HTML we need to create the search bar. We are using a few attributes on the tag.

Here is a closer look :

  1. type :
    Determines how the input appears on screen. We are using a search engine here rather than other types such as password , checkbox , and radio .
  2. id :
    The input box can be referenced from JavaScript by setting an ID, which will be used later on.
  3. name :
    In the search box, it is common to use «q» .
  4. placeholder :
    Displays some text to assist users in understanding what the input is for.

To make it accessible to screen readers, we add role and aria-label attributes.

Our Final HTML would look like the one below :

Styling the Search Bar with CSS

Next we are going to add CSS :

The addition of a magnifying glass or search icon can make it easier for users to find the search box. Let’s create a search button with one of the search icon images.

Next by using the flex display, we can arrange the items in the form based on the form’s width and height.

In the next step, we change the look of the input search box by using the all:unset , design. It can be difficult to style many browsers since they all add their design. This can make styling easier because we know what to do.

Last but not least, we have added a bit of padding after setting the font and making sure that the search bar fills the space with height and width.

In a search box, the placeholder text is gray by default, so we must set the style with this CSS rule :

The next step is to replace the search button with a search icon made from SVG, which changes its appearance and feel. We will add an SVG of the search icon.

Now our CSS looks like this :

Once again, we have used all: unset , to reset the button to its default state and then have set its height and width to 44px which is a good size for fingers on touch screens.

Lastly, we set the width and height of the icon and its color to white («#fff»).

We have finished with our search bar :

Complete Solution

Examples

Example A: Search with Icon

First, we create a markup with HTML as a wrapper.

The input type text field will then be placed with a placeholder. The icon will then be placed inside a button.

We are going to use Font Awesome icons, which are lightweight and easy to use, but you can pick anyone else.

The next step is to style the input type search box. We will start by applying a 100% width to the wrapper. You can modify it to suit your needs.

We will then apply the styling to the text field. Our goal is to make the picture look good by adding a border, setting the padding, and adding some color.

The button property will also be modified.

output-of-search-with-icon

Example B: Search with Button

To get started, let’s create the HTML code for an HTML search box with an input text field and a search button inside the same box :

In the following code example, the outermost div element (wraptext) serves as an enclosing box.

To enclose the input text and button in a box is what CSS codes are all about.

It will also enhance the look of our search box :

output-of-search-with-button

Example C: Search without Additional Elements

Now we would add HTML as a wrapper for our search and add CSS to it to beautify it. The only difference we will have here is that we will have any additional search icons as in previous examples.

Explanation :
Here we gave HTML to give the foundation then we added CSS to beautify our foundation and in this example, we did not make use of any search SVG icons

output-of-search-without-additional-elements

Search Events with Example

We will add HTML and CSS to our search bar to make it attractive. In addition to that we will also add an event so that when a user presses the search icon they get redirected to the specified destination :

Explanation :
We have added HTML to give structure and CSS to give it beauty and at last javascript to make it work when clicked else it would not redirect anywhere.

output-of-search-events

Differences between Search and Text Type

It is primarily a matter of style that separates the Text state from the Search state : on platforms with distinct search fields, the Search state will result in a presentation similar to the platform’s search fields, rather than like a regular text field.

Conclusion

  1. This technique is used to search the content of a single page or an entire page using a variety of functionality.
  2. The search bar can also be animated and colored with CSS properties according to our requirements.

Источник

Оцените статью