Case ce-0587-link-span-data-href-editing-pattern · Scenario scenario-link-span-internal-representation

Pattern — span + data-href for links during edit, <a> on export

OS: Any Any Device: Desktop or Laptop Any Browser: Any Any Keyboard: US Status: draft
link span data-href architecture serialization pattern

Phenomenon

This entry documents a recurring implementation strategy, not one vendor’s defect. Some teams avoid live <a> nodes inside contenteditable and instead store the URL on span[data-href] (or similar) while editing, then serialize to <a href> for output HTML, email, or static pages.

Mainstream editor packages default to <a> in the DOM while editing—see Lexical @lexical/link, Tiptap Link, and typical ProseMirror link mark toDOM—so choosing spans is an explicit trade-off.

When this pattern appears

  • Need click-to-caret without navigation unless modified (e.g. Ctrl/Cmd+click).
  • Want to delay semantic link markup until a sanitization / merge pass.
  • CMS or design tools that already use data-* for internal references.

Trade-offs (summary)

TopicRisk if only span in the editor
AccessibilityNative link semantics missing until export or ARIA decoration
ClipboardMay need custom copy / cut handlers to emit <a>
SecurityMust validate URLs on the same rules as href

References

Playground for this case

Use the reported environment as a reference and record what happens in your environment while interacting with the editable area.

Reported environment
OS: Any Any
Device: Desktop or Laptop Any
Browser: Any Any
Keyboard: US
Your environment
Sample HTML:
Event log
Use this log together with the case description when filing or updating an issue.
0 events
Interact with the editable area to see events here.

Comments & Discussion

Have questions, suggestions, or want to share your experience? Join the discussion below.