The If no validation constraints are in place for the input (see
Validation for more details), the value can be any text string or an empty string ( Additional attributesIn
addition to the attributes that operate on all listThe values of the list attribute is the
maxlengthThe maximum number of characters (as UTF-16 code units) the user can enter into the search field. This must be an integer value 0 or higher. If no The input will
fail constraint validation if the length of the text entered into the field is greater than minlengthThe minimum number of
characters (as UTF-16 code units) the user can enter into the search field. This must be a non-negative integer value smaller than or equal to the value specified by The search field will fail constraint validation if the length of the text entered into the field is fewer
than patternThe If the specified pattern is not specified or is invalid, no regular expression is applied and this attribute is ignored completely. Note: Use the
See the section Specifying a pattern for details and an example. placeholderThe If the control's content has one directionality (LTR or RTL) but needs to present the placeholder in the opposite directionality, you can use Unicode bidirectional algorithm formatting characters to override directionality within the placeholder; see How to use Unicode controls for bidi text for more information. Note: Avoid using the readonlyA Boolean attribute which, if present, means this field cannot be edited by the user. Its Note: Because a read-only
field cannot have a value, sizeThe This does not set a limit on how many characters the user can enter into the field. It only specifies approximately how many can be
seen at a time. To set an upper limit on the length of the input data, use the spellcheck
false Disable spell checking for this element. true Enable spell checking for this element. "" (empty string) or no valueFollow the element's default behavior for spell checking. This may be based upon a parent's An input field can have spell checking enabled if it doesn't have the readonly attribute set and is not disabled. The value returned by reading Non-standard attributesThe following non-standard attributes are available to search input fields. As a general rule, you should avoid using them unless it can't be helped. autocorrectA Safari extension, the on Enable automatic correction of typos, as well as processing of text substitutions if any are configured. off Disable automatic correction and text substitutions. incrementalThe Boolean attribute If The mozactionhintA Mozilla extension, which provides a hint as to what sort of action will be taken if the user presses the Enter or Return key while editing the field. This attribute has been deprecated: use the
resultsThe The value must be a non-negative decimal number. If not provided, or an invalid value is given, the browser's default maximum number of entries is used. Using search inputs
Basic example
This renders like so:
Note:
You must remember to set a Differences between search and text typesThe main basic differences come in the way browsers handle them. The first thing to note is that some browsers show a cross icon that can be clicked on to remove the search term instantly if desired, in Chrome this action is also triggered when pressing escape. The following screenshot comes from Chrome:
In addition, modern browsers also tend to automatically store search terms previously entered across domains, which then come up as autocomplete options when subsequent searches are performed in search inputs on that domain. This helps users who tend to do searches on the same or similar search queries over time. This screenshot is from Firefox: At this point, let's look at some useful techniques you can apply to your search forms. Setting placeholdersYou can provide a useful placeholder inside your search input that could give
a hint on what to do using the
You can see how the placeholder is rendered below: Search form labels and accessibilityOne problem with search forms is their accessibility; a common design practice is not to provide a label for the search field (although there might be a magnifying glass icon or similar), as the purpose of a search form is normally fairly obvious for sighted users due to placement (this example shows a typical pattern). This could, however, cause confusion for screen reader users, since they will not have any verbal indication of what the search input is. One way around this that won't impact on your visual design is to use WAI-ARIA features:
Let's have a look at an example:
You can see how this is rendered below: There is no visual difference from the previous example, but screen reader users have way more information available to them. Note: See Signposts/Landmarks for more information about such accessibility features. Physical input element sizeThe physical size of the input box can be controlled using the
The result is this wider input box: Validation
Note: HTML form validation is not a substitute for scripts that ensure that the entered data is in the proper format. It's far too easy for someone to make adjustments to the HTML that allow them to bypass the validation, or to remove it entirely. It's also possible for someone to bypass your HTML entirely and submit the data directly to your server. If your server-side code fails to validate the data it receives, disaster could strike when improperly-formatted data (or data which is too large, is of the wrong type, and so forth) is entered into your database. A note on stylingThere are useful pseudo-classes available for styling valid/invalid form
elements:
The technique also requires a
Making input requiredYou can use the
This renders like so: In addition, if you try to submit the form with no search term entered into it, the browser will show a message. The following example is from Firefox:
Different messages will be shown when you try to submit the form with different types of invalid data contained inside the inputs; see the below examples. Input value lengthYou can specify a minimum length, in characters, for the entered value using the
The example below requires that the entered value be 4–8 characters in length.
This renders like so: If you try to submit the form with less than 4 characters, you'll be given an appropriate error message (which differs between browsers). If you try to go beyond 8 characters in length, the browser won't let you. Specifying a patternYou can use the
Let's look at an example. Say we wanted to provide a product ID search form, and the IDs were all codes of two letters followed by four numbers. The following example covers it:
This renders like so: ExamplesYou can see a good example of a search form used in context at our website-aria-roles example (see it live). Specifications
Browser compatibilityBCD tables only load in the browser See alsoWhich if the following is assigned to each webpage to identify its location on the internet?A URL (Uniform Resource Locator) is a unique identifier used to locate a resource on the Internet.
Is it true that information literacy means you can evaluate whether online information is misleading biased or out of date?If you have information literacy, you can select the right tool to find the information you need. Information literacy means you can evaluate whether online information is misleading, biased, or out of date.
Which of the following is assigned to each web page to identify?A URL (Uniform Resource Locator), as the name suggests, provides a way to locate a resource on the web, the hypertext system that operates over the internet. The URL contains the name of the protocol to be used to access the resource and a resource name.
What is an address that identifies the location of the page on the internet?The web address contains information about the location of the webpage. It is also known as the URL (uniform resource locator).
|