DEV Community

Weather Clock Dash
Weather Clock Dash

Posted on

SVG in Firefox: Animation, Filters, Sprites, and DevTools Debugging

Firefox has long had strong SVG support, and its DevTools include SVG-specific features that help when debugging vector graphics in web applications. Here's what you need to know.

SVG in Firefox: Current Support

Firefox supports:

  • SVG 1.1: Full support
  • SVG 2.0: Mostly supported (ongoing)
  • CSS animations in SVG: Full support (transform, opacity, stroke)
  • SMIL animations: Supported (Chrome deprecated these; Firefox still supports them)
  • SVG filters: Full support
  • SVG foreign object: Supported
  • Inline SVG: Full support

Where Firefox differs from Chrome:

  • SMIL (<animate>, <animateTransform>, etc.): Chrome deprecated SMIL but Firefox still supports it
  • Some SVG 2.0 features like d property animation differ between engines

Inspecting SVG in Firefox DevTools

Inspector: SVG is just HTML elements in the DevTools Inspector. You can select SVG elements and see their properties.

CSS Rules panel: SVG attributes that are also CSS properties (fill, stroke, transform, opacity) show in the CSS rules panel and can be edited live.

Finding SVG elements:

// In Console: select all SVG paths on the page
document.querySelectorAll('svg path')
// Count total SVG elements
document.querySelectorAll('svg *').length
Enter fullscreen mode Exit fullscreen mode

Animating SVG with CSS

SVG animation via CSS transforms works in Firefox:

/* CSS transforms on SVG elements */
.spinning-gear {
  transform-origin: center;
  animation: spin 2s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
Enter fullscreen mode Exit fullscreen mode

transform-origin on SVG: Firefox 78+ correctly handles transform-origin: center on SVG elements. Earlier versions required transform-origin: 50% 50% 0.

SVG vs HTML coordinate systems: SVG elements use their own coordinate system, not the viewport. For complex transforms, you may need transform-box: fill-box to use the element's bounding box as the transform origin:

.animated-path {
  transform-box: fill-box;
  transform-origin: center;
}
Enter fullscreen mode Exit fullscreen mode

SVG Filters

Firefox fully supports SVG filter effects:

<svg>
  <defs>
    <filter id="blur">
      <feGaussianBlur stdDeviation="3"/>
    </filter>
    <filter id="dropshadow">
      <feDropShadow dx="4" dy="4" stdDeviation="4" flood-color="#333"/>
    </filter>
  </defs>
  <rect filter="url(#blur)" x="0" y="0" width="100" height="100" fill="blue"/>
</svg>
Enter fullscreen mode Exit fullscreen mode

CSS SVG filters (apply to any HTML element):

.blurred-element {
  filter: url(#blur);
  /* Or use CSS filter directly: */
  filter: blur(3px) drop-shadow(4px 4px 4px #333);
}
Enter fullscreen mode Exit fullscreen mode

Debugging SVG filters: DevTools → Inspector → CSS rules panel shows the filter property. Click the filter value to see an expanded view of what CSS filters are applied.

SVG Icons and Sprites

SVG sprites (common pattern):

<!-- Sprite sheet defined in page -->
<svg style="display:none">
  <defs>
    <symbol id="icon-arrow" viewBox="0 0 24 24">
      <path d="M5 12h14M12 5l7 7-7 7"/>
    </symbol>
    <symbol id="icon-close" viewBox="0 0 24 24">
      <path d="M18 6L6 18M6 6l12 12"/>
    </symbol>
  </defs>
</svg>

<!-- Use anywhere in the page -->
<svg class="icon"><use href="#icon-arrow"/></svg>
<svg class="icon"><use href="#icon-close"/></svg>
Enter fullscreen mode Exit fullscreen mode

Debugging <use> elements: In Firefox DevTools, <use> elements show in the Inspector. Click to see the referenced symbol. The shadow DOM for the <use> element is visible.

External sprites: <use href="/icons.svg#icon-arrow"/> works in Firefox. External SVG sprites load the SVG file and reference symbols by ID.

CORS and external sprites: If the external SVG is on a different domain, you need CORS headers (Access-Control-Allow-Origin: *) on the SVG file.

SVG Performance

Avoid: animating d (path data) directly. This requires the browser to recalculate path geometry every frame. Use transform animations instead.

Use: CSS transform/opacity animations which run on the compositor thread:

/* Good: compositor-thread animation */
.icon { transition: transform 0.2s ease; }
.icon:hover { transform: scale(1.1); }

/* Bad: main-thread animation (causes layout) */
.icon { transition: width 0.2s; }
.icon:hover { width: 120%; }
Enter fullscreen mode Exit fullscreen mode

Firefox performance for SVG: Check in DevTools Performance panel. SVG repaints show in the "Paint" section of the timeline. If SVG is causing excessive painting, look for:

  • SVG elements with will-change: transform
  • Large SVG areas with complex filters (filters are expensive)
  • SVGs that change frequently (animated charts, etc.)

SVG Accessibility

SVG needs additional markup for accessibility:

<!-- Decorative SVG: hide from screen readers -->
<svg aria-hidden="true">
  <path d="..."/>
</svg>

<!-- Meaningful SVG: provide title and description -->
<svg role="img" aria-labelledby="svg-title svg-desc">
  <title id="svg-title">Bar Chart</title>
  <desc id="svg-desc">Sales data for Q3 2024 showing 20% growth</desc>
  <!-- chart paths -->
</svg>

<!-- Icon with label -->
<button>
  <svg aria-hidden="true"><use href="#icon-download"/></svg>
  Download
</button>
Enter fullscreen mode Exit fullscreen mode

Test in Firefox Accessibility DevTools: DevTools → Accessibility panel → Select your SVG element. The accessibility properties panel shows whether the SVG is correctly described to screen readers.

SMIL Animations (Firefox-specific)

SMIL animations work in Firefox (Chrome dropped support):

<svg>
  <circle r="50" cx="50" cy="50">
    <animate 
      attributeName="cx" 
      from="50" 
      to="200" 
      dur="2s" 
      repeatCount="indefinite"/>
  </circle>
</svg>
Enter fullscreen mode Exit fullscreen mode

Note: Since Chrome doesn't support SMIL, don't use SMIL if you need cross-browser support. Use CSS animations or the Web Animations API instead.

SMIL has one advantage: It can animate SVG attributes that CSS can't animate, like d (path data), points (polygon), and viewBox. For Firefox-only SVG work, SMIL is still viable.

Debugging SVG Path Issues

Common problem: SVG paths look different in different browsers.

In Firefox DevTools:

  1. Inspector → select the path element
  2. Look at the d attribute in the HTML panel
  3. Edit it directly to test changes

Checking bounding boxes:

// In Console: check an SVG element's bounding box
document.querySelector('path').getBoundingClientRect()
document.querySelector('path').getBBox()  // SVG-specific, coordinate system of SVG
Enter fullscreen mode Exit fullscreen mode

getBBox() gives you the bounding box in SVG coordinates. getBoundingClientRect() gives viewport coordinates. Both work in Firefox.

Quick Reference

Feature Firefox
SVG 1.1 Full
Inline SVG Full
CSS animations on SVG Full
SMIL Supported (Chrome dropped)
SVG filters Full
<use> external sprites Supported (requires CORS)
transform-box: fill-box Firefox 78+
transform-origin: center on SVG Firefox 78+

Top comments (0)