I found inconsistencies in Firefox compared to Chrome, Edge, and Opera. Each browser handles transform-origin
fine when using a CSS class. However, when I place transform-origin
on an SVG element as an attribute, FF ignores the effect. Demo code below. My main question is how to get around this, but I'm also curious to know if this is expected behavior.
CSS transform-origin
works in FF.
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1000 1000'>
<style>
.centered{
transform-origin: center;
}
</style>
<path fill='#500' d='M500 500 400 400 400 600 600 600 600 400z' transform='scale(2)' class='centered'/>
</svg>
Inline SVG doesn't seem to recognize transform-origin
(works consistently in Chrome/edge)
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1000 1000'>
<path fill='#500' d='M500 500 400 400 400 600 600 600 600 400z' transform='scale(2)' transform-origin='center'/>
</svg>
Edit: Another user pointed out this question is similar to How to set transform origin in SVG, but their premise is super broad (how to) and either wrong or outdated (posted 8.5 years ago).
"I tried using the transform-origin attribute, but it does not affect anything."
Perhaps browser support has improved, but my question specifically shows transform-origin
works perfect as a CSS rule in all modern browsers or as a presentational attribute in all modern browsers except FireFox. That differentiation is likely what led to one solution being unique to this thread and a second solution that is a new take on the other threads answers.
Not to mention their question is centered around JavaScript implementation and was published at a time when FireFox didn't recognize keywords like "center" or unitless numbers which detracts from the core SVG markup problem which is that FireFox interprets the presentational attribute transform-origin=''
different than other browsers.