Rules Hub
Code Ruleset
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP2universalStack: React/SVG
svgiconsscaling
Add a viewBox so SVG icons scale correctly
Include a viewBox attribute on SVG icon components so they scale properly when width/height are overridden by consumers.
PR: hegnar-forum-web · org-mining-3rd-2026-06Created: Jun 18, 2026
Bad example
Old codetsx
| 1 | <svg width="16" height="16" {...props}> |
Explanation (EN)
Without a matching coordinate system, resizing the viewport can crop or fail to scale the paths.
Objašnjenje (HR)
Good example
New codetsx
| 1 | <svg width="16" height="16" viewBox="0 0 16 16" {...props}> |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
For a scalable SVG, derive viewBox coordinates from the artwork coordinate system and test consumer size overrides and aspect ratio.
Exceptions / Tradeoffs (EN)
Do not guess a viewBox from rendered CSS dimensions or override an intentionally cropped coordinate system.