As a general rule, the question “should websites appear the same in every browser?” can be answered authoritatively and succinctly. However, when it comes to some of the new HTML5 form elements, different browsers have very different ways of rendering inputs, to such a degree that their default appearance may clash with your overall design. This is especially true for the search input, which is provided an “iTunes / OS X” style in Safari and Chrome by default, but appears as a standard text input in other browsers. If you wish to have the search input to have consistent look and feel, you have two choices: negate the default Webkit appearance, or customize the appearance of the search input so that it duplicates the Webkit look across all browsers.
We’ll be applying both options to the same basic markup:
- <input type="search" placeholder="search"
- name="search_string" id=search_string" maxlength="25" />
Option 1: Remove the default Webkit appearance from Safari and Chrome
Probably the easiest option of the two, and an approach we have covered in the past with CSS3 & HTML5 Resets. Webkit uses two proprietary CSS properties to customize the appearance of the search input; you have to use those, together with the correct values and attribute selectors, to remove the default appearance.
- input[type=search] {
- -webkit-appearance: textfield; font-size: medium; background: #fff;
- }
- ::-webkit-search-cancel-button { display: none; }
You could then build the input to a shared, consistent appearance across all browsers by adding style rules to the first declaration.
Option 2:> Duplicate the appearance of the basic search input under Webkit for other browsers.
Slightly more complex than the first option, but certainly achievable. I would recommend starting with something like the following:
- input[type=search] { font-size: medium; font-size: 14px;
- border: 1px inset #777; border-radius: 10px; width: 150px;
- background: white; padding: 3px; padding-left: 20px; }
Rendered as a search input in Webkit, Chrome and Safari will ignore everything after font-size: medium. Alternatively, you could hybridize both techniques to achieve even more visual consistency. In this version, I’ve added proprietary support for border-radius to cover earlier browsers:
- input[type=search] {
- -webkit-appearance: textfield; font-size: 12px;
- border: 2px inset #ccc; -moz-border-radius: 10px;
- -webkit-border-radius: 10px; border-radius: 10px; width: 150px;
- background: white; padding: 3px; padding-left: 20px; }
- ::-webkit-search-cancel-button { display: none; }