Remove Arrow on Input Type Number with Tailwind CSS



When using an <input type="number"> field, browsers automatically show up and down arrows to adjust the number. While these arrows can be helpful, they might not fit your design. Tailwind CSS doesn't have a built-in way to remove them, so you'll need to manually hide the arrows while still using Tailwind for the rest of your styling.

Our goal is to remove the arrows without affecting the other Tailwind styles.

Approaches

We will cover two methods to remove the arrows from <input type="number"> fields:

Adding custom CSS for Webkit browsers

In Webkit browsers like Chrome, Safari, and Edge, <input type="number"> fields automatically display up and down arrows. In this approach, we use pseudo-elements like ::-webkit-outer-spin-button and ::-webkit-inner-spin-button to remove these arrows.

Steps we have taken include:

  • First, we created a folder and added a styles.css file.
  • Next, we added CSS rules to remove the arrows by targeting the ::-webkit-outer-spin-button and ::-webkit-inner-spin-button pseudo-elements in Webkit-based browsers.
  • After that, we linked the custom CSS file in the <head> section of the HTML document.

Example

Here's an example that removes the arrows in Webkit browsers like Chrome, Safari, and Edge by targeting the spin buttons with custom CSS.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Remove Arrow on Input</title>
    <script src="https://cdn.tailwindcss.com"></script>
</head>

<body class="bg-gray-100 p-8">
    <h1 class="text-2xl font-semibold mb-6">
        Remove Arrow on Input Type Number
    </h1>
    <input type="number" class="border p-2 rounded" 
        placeholder="Enter a number">
</body>

</html>

<style>
    /* Remove arrows in Webkit browsers (Chrome, Safari, Edge) */
    input[type="number"]::-webkit-outer-spin-button,
    input[type="number"]::-webkit-inner-spin-button {
        -webkit-appearance: none;
        margin: 0;
    }
</style>

Output

output of first approach

Cross-browser solution (including Firefox)

In this approach, we remove input arrows in all major browsers, including Firefox, by combining the previous approaches. While Approach 2 focused on Webkit-based browsers (Chrome, Safari, and Edge), Firefox requires an additional rule to remove the arrows.

For Firefox, we use the -moz-appearance: textfield; CSS rule to remove the arrows.

Steps we have taken include:

  • First, we used custom CSS to remove the arrows in Webkit browsers (Chrome, Safari, Edge).
  • Then, we added -moz-appearance: textfield; to ensure arrows are removed in Firefox.

Example

Here's an example that removes the number input arrows in Webkit browsers like Chrome, Safari, Edge, and Firefox.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Remove Arrow on Input</title>
    <script src="https://cdn.tailwindcss.com"></script> 
</head>

<body class="bg-gray-100 p-8">
    <h1 class="text-2xl font-semibold mb-6">
        Remove Arrow on Input Type Number
    </h1>
    <input type="number" class="border p-2 rounded" 
        placeholder="Enter a number">
</body>

</html>

<style>
    /* Remove arrows in Webkit browsers (Chrome, Safari, Edge) */
    input[type="number"]::-webkit-outer-spin-button,
    input[type="number"]::-webkit-inner-spin-button {
        -webkit-appearance: none;
        margin: 0;
    }
    /* Remove arrows in Firefox */
    input[type="number"] {
        -moz-appearance: textfield;
    }
</style>

Output

output of second approach

Conclusion

In this article, we learned how to remove the arrows from a number input using Tailwind CSS and custom CSS. We used two methods: custom CSS for Webkit browsers and a cross-browser solution (including Firefox) to make sure the input looks clean in all major browsers.

Updated on: 2025-01-03T09:11:28+05:30

131 Views

Kickstart Your Career

Get certified by completing the course

Get Started