w:hyperlink (Hyperlink)
Wraps inline content as a clickable hyperlink to an external URL or internal bookmark target.
Parent elements
Child elements
Description
w:hyperlink creates an inline hyperlink around one or more runs. It is defined in ECMA-376 Part 1 §17.16.22.
For external links, an r:id attribute references an OPC relationship of type hyperlink. For internal links (to a bookmark), use w:anchor instead. The element contains w:r children whose w:rStyle is typically set to Hyperlink (an underlined, blue character style).
Attributes
| Attribute | Type | Possible Values | Description |
|---|---|---|---|
r:id |
ST_RelationshipId |
A relationship ID referencing an external URL target. | Used for external hyperlinks. |
w:anchor |
ST_String |
A bookmark name (w:bookmarkStart/@w:name). |
Used for internal (same-document) links. |
w:history |
ST_OnOff |
true / false |
Adds the hyperlink URL to the browser/app history when activated. |
w:docLocation |
ST_String |
Any string. | Identifies a location within the linked document (for cross-document links). |
Examples
<!-- External link (r:id targets the relationship URL) -->
<w:hyperlink r:id="rId10" w:history="true">
<w:r>
<w:rPr><w:rStyle w:val="Hyperlink"/></w:rPr>
<w:t>Visit the site</w:t>
</w:r>
</w:hyperlink>
<!-- Internal link to bookmark -->
<w:hyperlink w:anchor="intro">
<w:r><w:t>See Introduction</w:t></w:r>
</w:hyperlink>
// External link
string relId = mainPart.AddHyperlinkRelationship(
new Uri("https://example.com"), true).Id;
new Hyperlink(
new Run(
new RunProperties(new RunStyle { Val = "Hyperlink" }),
new Text("Visit the site")))
{ Id = relId, History = true };
// Internal link
new Hyperlink(
new Run(new Text("See Introduction")))
{ Anchor = "intro" };