Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Omit the xmlns attribute on inline SVG
The xmlns namespace is only needed for standalone SVG files; inline SVG in JSX/HTML should not carry it.
Bad example
| 1 | const Star = (props: React.SVGProps<SVGSVGElement>) => ( |
| 2 | <svg width="32" height="32" viewBox="0 0 35 35" fill="currentColor" xmlns="http://www.w3.org/2000/svg" {...props}> |
| 3 | <path d="..." /> |
| 4 | </svg> |
| 5 | ); |
Explanation (EN)
The xmlns attribute is only meaningful when an SVG document is parsed standalone as XML. Inside the HTML/JSX tree the namespace is implied, so xmlns is dead noise.
Objašnjenje (HR)
Atribut xmlns ima znacenje samo kada se SVG dokument parsira samostalno kao XML. Unutar HTML/JSX stabla namespace je podrazumijevan, pa je xmlns mrtav suvisak.
Good example
| 1 | const Star = (props: React.SVGProps<SVGSVGElement>) => ( |
| 2 | <svg width="32" height="32" viewBox="0 0 35 35" fill="currentColor" {...props}> |
| 3 | <path d="..." /> |
| 4 | </svg> |
| 5 | ); |
Explanation (EN)
Without xmlns the inline SVG renders identically and the JSX is cleaner.
Objašnjenje (HR)
Bez xmlns inline SVG se prikazuje identicno, a JSX je cisci.
Exceptions / Tradeoffs (EN)
Keep xmlns when the markup will be serialized and served as a standalone .svg file or otherwise parsed as XML outside an HTML document.
Iznimke / Tradeoffi (HR)
Zadrzi xmlns kada ce se oznake serijalizirati i posluzivati kao samostalna .svg datoteka ili se inace parsirati kao XML izvan HTML dokumenta.