There are probably extensions that allow to do that, however, this is not necessary as I will show in this post. Maybe you’ve seen the functionality in Safari or just wondered why the close button for tabs in Firefox can’t just always be there. In Safari, the close button appears when hovering over the tab itself.
The following modification adds this functionality to Firefox. You need to create a file called userChrome.css
with the following content:
Firefox v113 and later
.tabbrowser-tab:not([selected]):not([pinned]):hover .tab-close-button {
display: flex !important;
}
Firefox up to v112
.tabbrowser-tab:not([selected]):not([pinned]) .tab-close-button {
visibility: hidden !important;
margin-left: -16px !important;
}
.tabbrowser-tab:not([selected]):not([pinned]):hover .tab-close-button {
visibility: visible !important;
margin-left: 0px !important;
display: -moz-box !important;
}
Instructions
Place this file into the chrome
folder inside your profile’s directory. Follow the directions from Mozilla to find out where to find the profile’s directory location. If the chrome
folder does not exist, you need to create it first.
In the address bar, open about:config and change the following preferences:
browser.tabs.tabClipWidth
to 99 (only needed for older versions of Firefox before v113)- New versions of Firefox (69+) don’t load the
userChrome.css
on startup by default. Make sure thattoolkit.legacyUserProfileCustomizations.stylesheets
is set totrue
.
Then just restart Firefox and you are done.
Update 1: It just tried this again myself due to a fresh installation and you also need to change the browser.tabs.tabClipWidth
preference from it’s default value (140) to 99.
Update 2 (August 2017): As pointed out by Veto in the comments below, this functionality is broken since version 55.0.3. The above CSS has been updated to stay compatible with the new Firefox UI.
Update 3 (December 2017): As pointed out in the comments, pinned tabs were affected too. Thanks to Mike for the solution on how this can be avoided. The above CSS has been adjusted.
Update 4 (October 2019): As pointed out in the comments below, Firefox 69 by default doesn’t load the userChrome.css anymore for new installations.
Update 5 (May 2023): I noticed recently that the close button on hover was not working anymore. I first noticed it on Firefox v113 and on another machine with Firefox v112 it is still working. The CSS rules in Firefox slightly changed. Added a new CSS rule for Firefox v113+. Also the clip width change is not necessary anymore.
Original Source: Post on Neowin Forums
Thanks, still working 🙂
Nope, as of Firefox version 55.0.2 this has been broken. Most likely due to the new changes introduced to the plugin/appearance machinery. The new way of operation will be enforced as of November’s version 57, but why this beautiful gimmick has fallen victim so early in the game, while all the other “old” plugins seem ok, remains a mystery to me. An updated version, if possible, would be highly appreciated.
Well it kind of works, but only up to 12 tabs open. By the 13th tab it becomes unreliable, and 14 and up is simply put a solid broken.
Thanks for letting me know. You’re referring to the new Photon UI which is currently enabled in 55.0.2 nightly, right?
I’ll have to look into it, maybe the structure changed. Out of curiosity, if you disable
browser.photon.structure.enabled
(i.e., set tofalse
) in about:config, does it work properly again?Actually it is set to “false” by default. I think they are not activating it as of yet. Also I am on 64bit firefox and the mod keeps being broken even if updated to 55.0.3. It must be something else they have changed.
Hi Veto, the post has been updated with a new version that works again (tested with 55.0.3 and 57.0.a1). I’ll write a separate post about the details.
Yes, indeed I can confirm it works as good as before. Thanks
Thanks. Still working without Update 1
now the close butoon shows on pinned tabs too, i liked the old behaviour.
I’ve applied this solution and noticed the same behaviour, too. The “close” button on pinned tabs not just looks ugly, but also leads to often occasionally closing pinned tabs, which is very annoying.
But luckily it’s easy to work around this: just add new selector to “not([selected])” of the original css. The selectors should be
not([selected]):not([pinned])
not([selected]):not([pinned]):hover
Otherwise a great solution, many thanks to Matthias for this.
Thanks, Mike! Have never used pinned tabs so I hadn’t noticed it. I updated the CSS above with your solution.
Great, works fine (Firefox 57), thanks a lot!
Works like a charm.
I just needed to create the “chrome” folder, that didn’t exist in my Firefox 57 profile folder.
Thanks for sharing.
Just tried it. Not working anymore.
Which Firefox version are you using?
It’s still working for me with Firefox 69.0.
Oh, I think I was using that version too or maybe 68. But since I was adding more stuff to my userChrome.css and realized that none of it worked, googled about that and learnt that version 69 disables by default the load of user CSS files. I enabled it in about:config and now your code is working! Thanks!
Thanks for pointing that out. Updated the steps to ensure the preference is enabled.
Thank you so much for this. The lack of a close button was driving me nuts.
I can confirm it is working as of 2019-11-22 in Firefox 70.0.1 on macOS 10.14.6.
Thank you!
Confirmed working in Firefox 87.0 (64-bit) on macOS 11.2.3.
On the inactive tabs, the X appears on hover. On the active tab, the X is always present.
Is it possible to make the X appear on hover on an active tab?
Thanks for confirming it still works.
The CSS selector filters out active tabs (
:not([selected])
). I haven’t tried this but removing this from both rules should probably get you the desired result. Let me know either way please.Just what I was looking for, thank you very much!
Hello!
Thank you for the code, very helpful.
It was working until v. 113.0.1 (64-bit) (the actual stable one), unfortunately.
if you had a “buy me a coffee” button on this article – you’d have a coffee right now. thanks so much.
Okay, you HAVE this button. And just to let you know _how_ much I appreciate this page – I tried seven times, until I figured out which adblockers I had to disable until stripe was finally willing to go forward without an error message. (if you have seven coffees now … well, that’s fine too 😆)