As of 2023, this can be simplified.
Firefox search field appears as a text field.
Only Chrome and Safari change the search field appearance.
- Remove cancel button (Chrome & Safari):
[type="search"]::-webkit-search-cancel-button {
appearance: none;
}
- Remove Safari left inner padding under macOS or the magnifying glass on the left under iOS:
[type="search"]::-webkit-search-decoration {
appearance: none;
}
[type="search"]::-webkit-search-decoration,
[type="search"]::-webkit-search-cancel-button {
appearance: none;
}
- Make the search field to be displayed like a text field under Safari:
[type="search"] {
appearance: textfield;
outline-offset: -2px; /* Fix outline style in Safari */
}
(source: https://github.com/necolas/normalize.css/blob/8.0.1/normalize.css#L285-L293)
The -2px
"breaks" Chrome :-/
-webkit-search-results-button
and -webkit-search-results-decoration
are not needed because Chrome >= 53 (released in 2016) does not support the results
attribute anymore.
Chrome 117 shadow DOM uses only one pseudo-element -webkit-search-cancel-button
which is specific to input type="search"
:
In addition Safari 17.0 shadow DOM uses -webkit-search-decoration
which adds a left inner padding under macOS 13.6 or a magnifying glass on the left under iOS 17.0:
Demo:
[type="search"].no-cancel-button::-webkit-search-cancel-button {
appearance: none;
}
[type="search"].no-decoration::-webkit-search-decoration {
appearance: none;
}
[type="search"].no-decoration-no-cancel-button::-webkit-search-decoration,
[type="search"].no-decoration-no-cancel-button::-webkit-search-cancel-button {
appearance: none;
}
[type="search"].as-textfield {
appearance: textfield;
outline-offset: -2px;
}
<input type="search" placeholder="input type='search'">
<br><br>
<input type="search" class="no-cancel-button" placeholder="no cancel button">
<br><br>
<input type="search" class="no-decoration" placeholder="no decoration">
<br><br>
<input type="search" class="no-decoration-no-cancel-button" placeholder="no decoration no cancel button">
<br><br>
<input type="search" class="as-textfield" placeholder="as textfield">
<br><br>
<input type="text" placeholder="input type='text'">
display: none;
you can also use-webkit-appearance:none;
which keeps this crazy vendor prefix rule in it's own space. – Overslaugh