Add ID attribute to root element
See original GitHub issueWould there be any support for adding an ID with the icon name to the root <svg>
element?
This would allow for referencing the icons in an SVG <use>
element. For example, adding id="hi-archive"
would allow importing via:
<svg class="h-6 w-6 text-red-500">
<use xlink:href="/img/heroicons/outline/archive.svg#hi-archive"/>
</svg>
This would be ideal for things like menu icons that are used on every page, eliminating the need to embed the full SVG each time while still allowing them to have the color styled.
It would increase the file size of the SVGs, but tools like svgo’s cleanupIDs
can be used to mitigate this if you’re not using them.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:5
Top Results From Across the Web
XSLT -- generate unique id for root element and append that ...
I need to: (1) Generate a unique id attribute for the root element. (2) Append ...
Read more >Adding an id-attribute to element - Oxygen XML Forum
Hello, I've got another newbie question. How can I add an id-attribute with consecutive numbers in it in my xml.file.
Read more >There was need for the id attribute on the root element
Since we style the root element in XML , there was a certain need for the id attribute on the html element in...
Read more >The HTML Document / Root element - MDN Web Docs - Mozilla
The HTML element represents the root (top-level element) of an HTML document, so it is also referred to as the root element.
Read more >Identity attribute - OASIS Open
Within the same document, the topic id alone suffices (as in #topicid ). Where the topic element is the root element of the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@davecardwell wouldn’t it make more sense to use both folder and filename as id?
e.g.
heroicons/outline/archive.svg
should get the IDoutline-archive
That way you can also combine them in a sprite, which would not work with the same hardcoded ID for each image.Found a solution through webpack configuration that doesn’t require editing the assets… The following config in my Vue project add automatically the file name as ID when creating the sprite
That makes using any icon from the sprite possible with just
<svg><use href="#icon_name" /></svg>