← Back to blog/Guides

Markdown Links: URLs, Relative Paths, and Heading Anchors

Write accessible Markdown hyperlinks and troubleshoot broken paths, reference labels, URL punctuation, and heading fragments.

F
Faizan Khan
• 7 min read

To create a Markdown link, write [descriptive link text](https://example.com/page). The square brackets hold the visible label; the parentheses hold the destination. Use a label that explains where the link goes, then choose an absolute URL, a relative file path, or a heading fragment based on where the document will be rendered.

Markdown
1Read the [CommonMark specification](https://spec.commonmark.org/0.31.2/).
HTML
1<p>Read the <a href="https://spec.commonmark.org/0.31.2/">CommonMark specification</a>.</p>

Choose the right kind of destination

DestinationExample sourceBest suited to
Absolute HTTPS URL[Reference](https://example.com/reference)External pages and unambiguous web destinations
Relative file[Setup](./setup.md)Repository documents that move together
Root-relative URL[Setup](/docs/setup)A known published site rooted at that domain
Same-page fragment[Recovery](#recovery)A heading or explicit ID on the current page
Email link[Email support](mailto:help@example.com)Opening the reader's configured email handler

The paths and email address in this table are examples to replace, not live DocsAlot destinations. A relative repository link and a published site route can differ. A documentation builder may transform setup.md into /docs/setup, but that is the builder's behavior, not a rule built into Markdown.

Before choosing relative paths, decide whether the source must work on GitHub, a local preview, the published site, or all three. A path that works in only one environment can be acceptable if that is the intended reading surface; it should be a deliberate choice.

Inline links and optional titles

An inline link can include a title after the destination:

Markdown
1[Review the restore procedure](./restore.md "Recovery reference")

The title is additional metadata, not a substitute for the visible label. Do not put essential prerequisites only in a hover title: touch users may never encounter it.

For a link in ordinary prose, prefer "review the restore procedure" to "click here." The label remains useful when a reader scans links out of context. If the destination is a download, a large file, or a separate application, say so in the surrounding text where relevant.

Standard Markdown does not provide a portable "open in new tab" suffix. HTML target attributes and platform-specific link components are separate features. Avoid surprising navigation unless the publication has a clear convention.

Reference-style links keep repeated destinations together

Markdown
1Read the [syntax reference][commonmark] before changing the parser.
2
3Use the same [specification][commonmark] during review.
4
5[commonmark]: https://spec.commonmark.org/0.31.2/ "CommonMark 0.31.2"

The definition supplies the URL to both links and is not displayed as an ordinary paragraph. This is useful for repeated sources or paragraphs whose URLs would make source lines difficult to read.

Collapsed references use the label as the reference name:

Markdown
1Read [CommonMark][].
2
3[CommonMark]: https://spec.commonmark.org/0.31.2/

If a definition is missing, the bracketed source can remain visible instead of becoming a link. Keep labels unique and meaningful; do not reuse a label for unrelated destinations. The CommonMark link rules cover reference matching and inline destination parsing.

Reference definitions are not a comment system. See Markdown comments for the visibility and MDX differences.

Handle spaces, parentheses, and literal brackets

URL punctuation is a common source of broken links. Prefer a properly encoded URL, including %20 for a space. Angle brackets can delimit a destination containing spaces in supporting CommonMark renderers:

Markdown
1[Release checklist](<./release checklist.md>)

Balanced parentheses can occur in a destination, but complicated URLs are easier to review when encoded or tested explicitly. If a URL is cut off at a closing parenthesis, inspect the source boundaries before changing the label.

Escape literal square brackets in the label:

Markdown
1[Read the \[preview\] instructions](./preview.md)

For visible URL text without a custom label, CommonMark supports angle-bracket autolinks:

Markdown
1<https://example.com/reference>

Bare URL linking without angle brackets is an extension in systems such as GFM. Do not assume every Markdown engine recognizes it. Explicit link syntax is usually clearer in published documentation.

Link to a heading without guessing its ID

Markdown
1[Jump to recovery](#recovery-options)
2
3## Recovery options

This works when the renderer gives that heading the ID recovery-options. CommonMark does not define an automatic heading-ID algorithm. GitHub and documentation frameworks may differ on punctuation, repeated headings, Unicode, or explicit custom IDs.

Copy the destination from the rendered heading's permalink and test it in a fresh page load. Repeated headings often receive suffixes, which makes hand-maintained anchors fragile. Our table-of-contents guide includes a worked navigation example and a heading-change review process.

An image can be the label of a link

Markdown
1[![Export dialog with CSV selected](./images/export.png)](./export.md)

The inner expression creates an image; the outer expression makes it a link. Because the image is the link's content, its alternative text needs to communicate a useful destination or purpose, not just a filename.

If the image merely decorates a nearby text link, avoid creating an extra unlabeled or redundant navigation target. The Markdown image guide covers alternative text and asset paths separately from hyperlink syntax.

Do not nest one ordinary link inside another. HTML anchors cannot provide meaningful independent nested destinations. Use two separate links with distinct labels.

A practical broken-link review

Check these layers in order:

  1. Confirm that the source actually parsed into an anchor rather than literal brackets.
  2. Check the resolved URL, including case, spaces, fragments, and trailing path segments.
  3. Confirm that the destination exists in the intended environment.
  4. Open it without your authoring session to detect private or permission-bound destinations.
  5. Follow the same link from the published page, not only the editor preview.
  6. For heading links, verify that the target is still the intended section after edits.

A successful HTTP response is not enough if the link opens a generic landing page rather than the promised procedure. Review relevance as well as reachability. For a larger document, the Markdown cheat sheet provides a compact reference for links alongside the surrounding structure.

FAQ

What is the basic Markdown hyperlink format?

Use square brackets for the visible label followed immediately by parentheses containing the URL, as in [Reference](https://example.com/reference).

Why does my relative Markdown link work locally but not online?

The published site may have a different base path or route convention from the source files. Inspect the final resolved URL and the documentation builder's link rules.

How do I open a Markdown link in a new tab?

Core Markdown has no portable new-tab option. Use supported HTML or a documented site component only when the platform permits it and the behavior is appropriate.

Continue This Guide