Removing Number Input Spin Buttons with Tailwind CSS
The Problem
Number input fields (type="number"
) in HTML display increment/decrement buttons (spin buttons) by default in most browsers. While useful in some contexts, these buttons are often unwanted when designing clean, minimal interfaces.
<!-- Default number input with spin buttons -->
<input type="number" placeholder="Phone number" class="border p-4 outline-none">
Recommended Modern Solution
Use inputmode="numeric"
Instead
The most straightforward and reliable approach is to avoid type="number"
entirely and use inputmode="numeric"
with type="text"
:
<input type="text" inputmode="numeric" class="border p-4 outline-none">
Why this works best
inputmode="numeric"
shows a numeric keyboard on mobile devices without displaying spin buttons- Provides consistent behavior across all browsers
- Avoids browser-specific CSS workarounds
- Supported in all modern browsers as of 2021
Browser Support: Check current compatibility
CSS-Based Solutions
If you must use type="number"
, here are the CSS approaches to hide spin buttons:
Global CSS Solution
Add this to your base CSS layer to remove spin buttons from all number inputs:
@layer base {
input[type="number"] {
/* Firefox */
appearance: textfield;
/* Chrome, Safari, Edge */
&::-webkit-inner-spin-button,
&::-webkit-outer-spin-button {
appearance: none;
margin: 0;
}
}
}
Tailwind Utility Class Solution
Create a custom utility for more granular control:
@utility hide-spin-button {
/* Firefox */
appearance: textfield;
/* Chrome, Safari, Edge */
&::-webkit-inner-spin-button,
&::-webkit-outer-spin-button {
appearance: none;
margin: 0;
}
}
<input type="number" class="hide-spin-button border p-4 outline-none">
Inline Tailwind Classes
For one-off usage, you can use these Tailwind classes:
<input
type="number"
class="[appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none border p-4 outline-none"
>
Browser Compatibility Notes
Browser differences
- Firefox: Uses
appearance: textfield
- Chromium-based browsers: Require targeting
::-webkit-inner-spin-button
and::-webkit-outer-spin-button
pseudo-elements - Safari: Similar to Chrome, uses WebKit prefixes
Alternative: Custom Select Input
For some use cases, a custom select element might be preferable:
<select class="border p-4 outline-none appearance-none">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
When to Use Each Approach
Recommendation guide
- For new projects: Use
inputmode="numeric"
withtype="text"
- When maintaining existing code: Use the CSS solutions
- For mobile-first applications:
inputmode="numeric"
provides the best mobile experience - When you need precise control: Use the utility class approach
Conclusion
The simplest and most reliable method to avoid number input spin buttons is using inputmode="numeric"
instead of type="number"
. For cases where you must use number inputs, the CSS solutions provided will effectively hide the spin buttons across all modern browsers while maintaining the numeric input functionality.
Remember that Tailwind CSS v4's browser support baseline ensures these solutions work consistently across all supported browsers without needing vendor prefixes.