Skip to content

Set exported SVG tag ID to its source layer name #2879

Description

@kebjs

When exporting to SVG no node id is created; this should be set to the layer name so that the id becomes available for other tools, e.g. styling, animation with SVG. Figma does this (set the checkbox on Export, screenshot).

Image
Image

Image Image

Activity

  1. added theissue type on Jul 14, 2025
  2. hollermay commented on Jul 20, 2025

    @hollermay

    Would like to work on this please assign me this issue.

  3. Keavon commented on Jul 28, 2025

    @Keavon
    Member

    @hollermay you can open a PR that tags this issue. We'll assign you to the issue once you've successfully completed it and the PR is merged.

    As a note, you'll want to only have the layer name show in the ID field when exporting, not normally. There is a render options struct that has that flag you can use to pick when to include it. Be sure to escape invalid characters in an ID.

  4. changed the title [-]Set node id in SVG to layer name[/-] [+]Set exported SVG tag ID to its source layer name[/+] on Sep 2, 2025
  5. partg952 commented on Nov 1, 2025

    @partg952

    is this issue still open for fix?

  6. Keavon commented on Nov 1, 2025

    @Keavon
    Member

    Yes. See the discussion above for useful info, also.

  7. partg952 commented on Nov 1, 2025

    @partg952
    Image

    so this is an svg exported from figma so are we supposed add id to the children too , or just the svg tag must have the id attribute?

  8. Keavon commented on Nov 1, 2025

    @Keavon
    Member

    Adding an id attribute to the container SVG tag? That would be useless (or even bad). The requested behavior here is, as you show in your screenshot, ids given to each named layer. Deduplicated (they must be unique) with suffix numbers if needed, and skipped if unnamed.

  9. partg952 commented on Nov 2, 2025

    @partg952

    Oh okay, different layers in an svg must be given an id?

  10. kebjs commented on Nov 3, 2025

    @kebjs
    Author

    Below a more complete Figma example export including Frame, Groups, duplicate names.

    All id tags are relevant

    • on the g tag to handle grouped objects, e.g. to hide/show them completely
    • on the rect to manipulate this object, e.g. assign an action
    • note the re-naming to make ids unique: my:square and my:square_2 (dedup as mentioned above)
    • names/ids of the objects like "Ellipse 123" are assigned automatically by Figma.
    Image

    Filename as set by Figma from the frame example-grouping.svg

    
    <svg width="555" height="542" viewBox="0 0 555 542" fill="none" xmlns="http://www.w3.org/2000/svg">
    
    <g id="example-grouping">
    <g id="Group 11">
    <rect id="my:square" x="176" y="163" width="379" height="379" fill="#FFB2B2"/>
    <rect id="my:square_2" width="379" height="379" fill="#D9D9D9"/>
    <g id="my:doughnut">
    <circle id="Ellipse 45" cx="283" cy="271" r="157" fill="#8F8F8F"/>
    <circle id="Ellipse 46" cx="283" cy="271" r="96" fill="#C0F1FF"/>
    </g>
    </g>
    </g>
    </svg>
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    • Status
      Short-Term

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions