---
title: "Add a hyperlink to a Word document in C#"
url: https://recursiveai.org/onedocument/cookbook/add-hyperlink-to-word-document/
description: "Add a clickable hyperlink to a Word DOCX in C#. Set the display text and destination separately, and download a runnable OneDocument example."
version: "1.0.0"
---

# Add a hyperlink to a Word document in C#

**OneDocument** is a free, open-source Word, Excel and PowerPoint document library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneDocument.Documents) · [GitHub](https://github.com/recursive-ai-oss/onedocument-csharp) · [Docs](https://recursiveai.org/onedocument/docs/) · [Download example (.zip)](https://recursiveai.org/onedocument/cookbook/add-hyperlink-to-word-document/add-hyperlink-to-word-document.zip)

Add a clickable link with its own display text to a new DOCX.

```shell
dotnet add package \
    RecursiveAI.OneDocument.Documents
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using RecursiveAI.OneDocument.Documents;
using var doc = Document.Create();
doc.Body.AddParagraph("").AddHyperlink(
    "the guide",
    "https://example.com/guide");
doc.SaveAs("links.docx");
Console.WriteLine("Wrote links.docx");
```

```text
Wrote links.docx
```

The DOCX shows “the guide” as a clickable link.

Unzip [the example](https://recursiveai.org/onedocument/cookbook/add-hyperlink-to-word-document/add-hyperlink-to-word-document.zip), then `dotnet run`.

## The full program

The download puts the link inside a sentence: “See the guide for details.” Only “the guide” is linked. It uses a reserved example URL, and no request is sent to it.

```csharp
using RecursiveAI.OneDocument.Documents;

using var doc = Document.Create();
var paragraph = doc.Body.AddParagraph("See ");
paragraph.AddHyperlink(
    "the guide", "https://example.com/guide");
paragraph.AddRun(" for details.");
doc.SaveAs("links.docx");
Console.WriteLine("Wrote links.docx");
```

`dotnet run` prints:

```text
Wrote links.docx
```

A blank destination throws `ArgumentException`; a nonblank address being saved does not mean it points to a reachable page.

## Variations

**Show the URL itself.** Replace the `AddHyperlink` call in the full program with this if the reader needs to see the address as well as click it:

```csharp
const string url = "https://example.com/guide";
paragraph.AddHyperlink(url, url);
```

## Related recipes

- [Create a Word DOCX document in C#](https://recursiveai.org/onedocument/cookbook/create-word-document/)
- [Add a table to a Word document in C#](https://recursiveai.org/onedocument/cookbook/add-table-to-word/)

---

## The short answer

To add a hyperlink to a Word document in C#, install `RecursiveAI.OneDocument.Documents`, call `paragraph.AddHyperlink(text, address)`, then save the document as `.docx`. The first argument is what the reader sees; the second is where the link goes.

## How do I insert a hyperlink in a Word document?

A hyperlink belongs to a paragraph. For a link on its own line, start with an empty paragraph, as in the snippet at the top. For a link in the middle of a sentence, start with the text before the link, append the link, then use `AddRun` for the text after it. Include any spaces or punctuation that belong outside the link in those surrounding pieces. `AddHyperlink` appends at the end of the paragraph; it does not look for matching words earlier in the text and turn them into a link.

OneDocument uses the `Hyperlink` character style for the link text and adds the style if the document lacks it. The style and the destination are separate: changing how text looks does not change where it leads. For an external URL, the DOCX stores the destination in a relationship, a separate entry referenced by the hyperlink. OneDocument stores that address without fetching it, so the file can be generated offline. If you generate documents from a list of links, check the destinations before writing if they must be valid; successfully saving a DOCX does not check them for you.

## How do I link to a place in the same Word document?

If your document already has a bookmark named `Details`, pass `#Details` as the address, not a web URL. For example, replace the `AddHyperlink` call in the full program with:

```csharp
paragraph.AddHyperlink("the details", "#Details");
```

The leading `#` tells OneDocument to write an internal anchor instead of an external relationship. The text after `#` is the bookmark name. The call does not add the bookmark itself. Use this in a document that already has that destination; the fresh document in the download does not. To point to a section of a web page instead, put the full URL first and the fragment at the end, as in `https://example.com/guide#details`. That address does not start with `#`, so it is stored as an external link.
