TechBuzzPro

Enable :has Selector in Firefox – Quick Guide

· 5 min read · Apps & Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Yes – you can enable the CSS :has() selector in Firefox by setting the layout.css.has-selector.enabled preference to true in about:config. This unlocks powerful relational selectors for modern web design without needing any extensions.

What You'll Need

  • A desktop or laptop running Firefox version 103 or newer (earlier versions do not support the selector at all).
  • Basic familiarity with opening Firefox's internal configuration page (about:config).
  • An internet connection if you need to update Firefox to the latest release.

Step-by-Step

  1. Open Firefox and verify your version. Click the menu button (three horizontal lines) → Help → About Firefox. If the version number is 103 or higher, you can proceed. If not, let Firefox download the latest update and restart.
  2. In the address bar, type about:config and press Enter. Firefox will show a warning about the risks of changing advanced settings. Click Accept the Risk and Continue to proceed.
  3. In the search box at the top of the about:config page, enter layout.css.has-selector.enabled. If the preference already appears, note its current value (usually false).
  4. If the preference is not listed, create it: click the + Add button (or the “Add” icon), choose Boolean as the type, enter layout.css.has-selector.enabled as the name, and set the value to true. Press OK to save.
  5. If the preference is listed, double‑click it (or click the toggle icon) to switch its value from false to true. The change takes effect immediately; no restart is required, but a quick restart can help if you encounter unexpected behavior.
  6. Close the about:config tab. To confirm the selector works, open a test page or the Firefox Developer Tools (F12) and try a simple rule such as div:has(> img) { outline: 2px solid red; }. If the outline appears around div elements containing an img, the selector is active.

Common Mistakes

  • Using an outdated Firefox version. The :has() selector was introduced experimentally in Firefox 103; older releases ignore the flag entirely.
  • Misspelling the preference name. The exact string is layout.css.has-selector.enabled. Any deviation (e.g., layout.css.hasselector.enabled) creates a new, unrelated setting that does nothing.
  • Setting the value to 1 or yes instead of true. The preference expects a Boolean, so only true or false are valid.
  • Expecting immediate changes on already‑loaded pages. Some pages cache CSS. Refresh the page (Ctrl + R) or clear the cache if the selector seems ignored.
  • Disabling the flag after testing. If you later set the preference back to false, any CSS that relies on :has() will stop working, potentially breaking layout.

Tips

  • Keep Firefox updated automatically. New releases may enable :has() by default, removing the need for the flag.
  • When testing, use a minimal HTML file to isolate the selector. Complex sites may have other CSS that interferes with visual confirmation.
  • Combine :has() with other modern selectors like :is() and :where() for concise, performant rules.
  • If you develop extensions or user styles, remember that the flag only affects the browser process, not other browsers.
  • Document the change in your project’s README so collaborators know the selector requires a recent Firefox build.

Troubleshooting

If the selector does not appear to work after following the steps above, try the following checks in order:

  1. Restart Firefox. Some internal caches only refresh on a full restart. Close all windows and reopen.
  2. Verify the preference value. Re‑open about:config and ensure layout.css.has-selector.enabled is still set to true. A conflicting extension might revert it.
  3. Check for conflicting extensions. Disable any CSS‑modifying extensions (e.g., Stylus, uBlock Origin with custom filters) and test again.
  4. Clear the site cache. Open Settings > Privacy & Security > Cookies and Site Data, click “Clear Data…”, select “Cached Web Content”, and confirm.
  5. Confirm the CSS rule is valid. Use the Developer Tools console to run document.querySelectorAll('div:has(> img)'). If it returns a NodeList, the selector works; if it throws an error, the flag may still be disabled.
  6. Update Firefox. Even if you think you have a recent version, double‑check the official release notes. Some enterprise or ESR builds lag behind the main channel.
  7. Reset the preference. If you suspect the setting is corrupted, delete the layout.css.has-selector.enabled entry (right‑click → Reset) and recreate it as described in the step‑by‑step section.
  8. Reinstall Firefox. As a last resort, uninstall and reinstall the browser from the official Mozilla website. This ensures a clean profile and the latest defaults.

Note: Resetting or reinstalling will preserve your bookmarks if you sync with a Firefox Account, but extensions, custom settings, and local passwords may be lost. Back up your profile folder if you need to retain them.

Frequently Asked Questions

Is the :has() selector enabled by default in the latest Firefox?

As of the most recent stable release, the selector is enabled by default. However, older versions and some ESR builds still require the manual flag.

Does enabling :has() affect page performance?

The selector is implemented efficiently, but because it requires the engine to look ahead in the DOM, complex :has() queries can be slower than simple selectors. Use it judiciously and test performance on target devices.

Can I enable :has() on mobile Firefox?

Mobile Firefox shares the same engine, but the about:config interface is not exposed on Android or iOS. The selector is only available on mobile when the desktop version of the flag is already enabled by the underlying build, which currently means you must rely on the default state of the release.

Will enabling the selector break existing websites?

Enabling the flag does not alter existing CSS; it only adds support for new syntax. Websites that do not use :has() remain unaffected. However, if you add new rules that use the selector, test them across browsers because support is still limited elsewhere.

Do I need to clear my cache after changing the flag?

Usually a page refresh is enough. If you notice stale styles, clearing the cached web content or performing a hard reload (Ctrl + Shift + R) ensures the new selector is evaluated.