How To Remove Border From Input Field When Clicked

10 min read

If you want to know how to remove border from input field when clicked, this guide walks you through the CSS and JavaScript techniques that let you eliminate the default focus outline while keeping your form stylish and accessible. Whether you are building a clean, minimalist UI or need to suppress the native focus ring for custom designs, the methods described below will give you full control over the appearance of input elements during user interaction Worth knowing..

Introduction

When a user tabs through a form or clicks an <input> element, most browsers apply a subtle outline (often a blue border) to indicate focus. This visual cue is essential for keyboard navigation and screen‑reader users, but it can clash with modern design systems that favor custom focus styles or no border at all. By understanding the underlying CSS :focus pseudo‑class and the optional JavaScript event handling, you can decide whether to hide the outline globally, target specific fields, or replace it with a branded highlight And that's really what it comes down to..

Steps to Remove the Border on Click

1. Identify the Default Outline

The default focus style is actually an outline, not a border. This makes them safe to remove without risking the integrity of your layout. Outlines are drawn outside the element's box, so they never affect layout. The most common way browsers render outlines is a thin, solid line that appears around the perimeter of the input.

2. Use outline: none in CSS

The simplest solution is to add outline: none; to your CSS rule for the :focus state:

input:focus {
  outline: none;
}

This declaration tells the browser to draw no outline when the element receives focus. Plus, it works for all input types (text, email, password, etc. ) and across modern browsers (Chrome, Firefox, Safari, Edge) Took long enough..

Tip: If you also want to remove any custom border that you may have set, add border: none; inside the same rule Small thing, real impact..

3. Target Specific Input Fields

If you only need to remove the border for a subset of fields, use a class or ID selector:

/* Example: only the login username field */
#username:focus {
  outline: none;
  border: none;
}

You can also combine multiple selectors:

input[type="search"]:focus,
input[type="number"]:focus {
  outline: none;
}

4. Replace the Outline with a Custom Style

Many designers prefer to keep a visual focus indicator but change its appearance. You can replace the default outline with a box-shadow or a colored border:

input:focus {
  outline: none;          /* hide default */
  box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
  border-color: #007bff;
}

The box-shadow creates a glowing effect that is fully customizable and works well with modern UI kits. It also satisfies accessibility guidelines because it still provides a clear focus cue.

5. Use JavaScript to Dynamically Remove the Border

In scenarios where focus behavior must be conditional—such as when a validation error occurs or when a modal overlay is open—you can add a small script: