Remove Dotted Border On Buttons

A complete CSS guide to understanding and controlling browser focus outlines while maintaining accessibility

That persistent dotted border around buttons when clicked or focused is one of the most common CSS adjustments developers make. While browsers apply this outline to indicate focus--a critical accessibility feature--design requirements often call for a cleaner appearance. This guide covers the CSS techniques to remove dotted borders from buttons while maintaining accessibility through proper alternatives.

What You'll Learn

  • The browser mechanisms behind focus outlines
  • CSS properties to remove or customize button borders
  • Firefox-specific pseudo-element solutions
  • Accessibility-compliant approaches to focus styling
  • Modern CSS techniques using :focus-visible

Understanding the Browser Focus Outline

The dotted border you see around buttons is the browser's default focus indicator. This visual cue serves a vital accessibility function: it tells keyboard users which element currently has focus, enabling them to navigate and interact with web pages without a mouse.

How Focus Outlines Work

The focus outline is defined by the CSS outline property, a shorthand that combines outline-width, outline-style, and outline-color. Unlike borders, outlines don't take up space in the element's box model--they're drawn outside the border edge without affecting layout. This behavior is documented in the MDN Web Docs CSS outline reference.

Different browsers render focus indicators differently:

  • Firefox: Shows a dotted outline by default
  • Chrome/Safari: Displays a blue ring or outline
  • Edge: Follows Chromium's blue outline behavior

Modern browsers have refined when outlines appear, distinguishing between keyboard focus (tab navigation) and click focus (mouse interaction).

Why Developers Remove Focus Outlines

Design consistency represents the primary reason developers remove default focus outlines. Custom button styles with unique hover and active states often clash with the browser's default focus indicator. Some design systems implement their own focus states through box-shadow techniques, background changes, or other visual treatments that render the default outline unnecessary.

When implementing custom focus styles as part of a broader web development strategy, developers must balance aesthetic requirements with accessibility obligations.

However, removing the focus outline entirely introduces accessibility concerns that must be addressed through alternative approaches.

CSS Techniques to Remove Dotted Borders

The Basic Outline Removal

The simplest approach to remove the dotted border from any element involves setting the outline property to none:

button {
 outline: none;
}

This single declaration removes the focus outline from all buttons. For more specific targeting, apply the same technique to particular button classes, IDs, or button types. This approach is documented in multiple CSS resources including GeeksforGeeks tutorials.

Firefox-Specific Pseudo-Element

Firefox applies focus styles differently than other browsers, requiring additional targeting for complete removal. The ::-moz-focus-inner pseudo-element targets the inner focus style:

button::-moz-focus-inner {
 border: 0;
}

For complete cross-browser consistency, combine both approaches:

button {
 outline: none;
}

button::-moz-focus-inner {
 border: 0;
}

Targeting Links Styled as Buttons

Anchor elements styled as buttons require similar treatment:

a.button {
 outline: none;
}

a.button::-moz-focus-inner {
 border: 0;
}

Links present unique considerations because they have their own default focus behavior that may differ from native button elements, as noted in Perishable Press accessibility guides.

Input Element Focus Removal

Form inputs also display focus outlines:

input[type="submit"]::-moz-focus-inner,
input[type="button"]::-moz-focus-inner {
 border: 0;
}

input {
 outline: none;
}

When building interactive forms as part of custom web development projects, properly managing focus states ensures a polished user experience across all devices.

Complete Button Focus Reset
1/* Complete cross-browser button focus reset */2button,3input[type="button"],4input[type="submit"],5input[type="reset"],6.button {7 /* Standard outline removal */8 outline: none;9 10 /* Remove tap highlight on mobile */11 -webkit-tap-highlight-color: transparent;12}13 14/* Firefox-specific pseudo-element */15button::-moz-focus-inner,16input[type="button"]::-moz-focus-inner,17input[type="submit"]::-moz-focus-inner,18input[type="reset"]::-moz-focus-inner {19 border: 0;20 padding: 0;21}

Accessibility: The Critical Consideration

Removing the focus outline without providing an alternative creates significant accessibility barriers. Users who navigate websites via keyboard--including those with motor disabilities, visual impairments, or who simply prefer keyboard navigation--rely on focus indicators to understand where they are on the page.

WCAG Success Criterion 2.4.7: Focus Visible

The Web Content Accessibility Guidelines (WCAG) require that any keyboard-operable interface have a visible focus indicator. Removing the default outline without providing an equivalent alternative fails this criterion, as outlined in the WCAG 2.1 Focus Visible requirements.

This doesn't mean you cannot customize focus styles--it means you must ensure focus remains visually apparent through other means. The goal is maintaining usability for all users while achieving design objectives.

Accessible websites also perform better in search rankings. Our SEO services incorporate accessibility best practices as part of comprehensive optimization strategies.

Providing Custom Focus Styles

The best practice involves replacing the default outline with custom focus indicators:

button:focus-visible {
 outline: 2px solid #0056b3;
 outline-offset: 2px;
}

button:focus:not(:focus-visible) {
 outline: none;
}

The :focus-visible pseudo-class shows focus indicators when users navigate via keyboard while suppressing them for mouse users who don't need them.

CSS Outline Removal Methods Compared

Choose the right approach for your project requirements

outline: none

Simple and effective for basic outline removal. Works across all modern browsers but requires additional approaches for Firefox compatibility.

::-moz-focus-inner

Firefox-specific pseudo-element targeting. Required in addition to outline:none for complete Firefox button focus removal.

:focus-visible

Modern CSS solution that intelligently shows focus only when needed. Best practice for balancing design and accessibility.

box-shadow Alternative

Using box-shadow for focus indicators provides visual appeal without layout impact. Can be combined with :focus-visible for optimal results.

Modern CSS Alternatives

Using :focus-visible Selectively

Modern browsers support the :focus-visible pseudo-class, which intelligently applies focus styles only when needed:

button:focus:not(:focus-visible) {
 /* No outline for mouse users */
 outline: none;
}

button:focus-visible {
 /* Clear focus indicator for keyboard users */
 outline: 3px solid #4a90d9;
 outline-offset: 2px;
}

This approach respects both design requirements and accessibility needs by showing focus indicators only to users who benefit from them.

Box-Shadow Alternatives

Many designers prefer box-shadow for focus indicators because it doesn't affect layout:

button:focus {
 box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.5);
}

button:focus:not(:focus-visible) {
 box-shadow: none;
}

Box-shadow focus indicators can be more visually appealing and integrate better with modern button designs. This technique is part of our broader CSS best practices for creating polished user interfaces.

Mobile Considerations

For mobile devices, the -webkit-tap-highlight-color property addresses Safari's tap highlight color, which provides another visual indicator:

button {
 -webkit-tap-highlight-color: transparent;
}

This ensures a consistent appearance across mobile and desktop browsers. Mobile-first development approaches ensure these CSS refinements enhance the user experience across all devices and screen sizes.

By implementing these modern CSS techniques as part of a comprehensive web development strategy, you create interfaces that are both visually appealing and accessible to all users.

Frequently Asked Questions

Implementation Checklist

When removing dotted borders from buttons, follow this decision process:

Before You Begin

  • Assess whether the design truly requires focus outline removal, or can accommodate a styled focus state
  • Consider if custom focus styles would better serve both design and accessibility goals
  • Review your target browser support requirements

Implementation Steps

  1. Use :focus-visible when possible -- Modern CSS provides better solutions than complete removal
  2. If removal is necessary, combine outline: none with ::-moz-focus-inner for Firefox compatibility
  3. Always provide alternative focus indicators through box-shadow, background changes, or other visual cues
  4. Test with keyboard navigation to verify focus remains visible and usable
  5. Consider accessibility audits to ensure compliance with WCAG guidelines

Testing Checklist

  • Test focus states with keyboard navigation (Tab key)
  • Verify focus indicators are visible against all background colors
  • Test in Firefox, Chrome, Safari, and Edge
  • Check mobile tap interactions
  • Validate with screen readers if possible

Need Help with CSS Focus Styles?

Our web development team specializes in creating accessible, performant websites with modern CSS techniques.

Sources

  1. GeeksforGeeks: How to Remove Firefox's Dotted Outline on Buttons and Links using CSS - Comprehensive tutorial covering Firefox-specific pseudo-elements, CSS solutions for links, inputs, and buttons.

  2. Perishable Press: Unobtrusive JavaScript - 5 Ways to Remove Unwanted Link Focus Outlines - In-depth article covering both CSS and JavaScript approaches, accessibility implications, and progressive enhancement strategies.

  3. MDN Web Docs: CSS Outline Property - Official documentation for the CSS outline shorthand property, including accessibility considerations and browser compatibility.