Markdown Links
A Markdown link is the link text in square brackets followed by the destination in parentheses: [text](url). The destination can be a web address, a file in your project, an email address or a heading in the same file.
This guide covers every link type, plus two things most guides skip: adding a tooltip, and opening a link in a new tab. For pictures, see the image syntax page.
π’ Practice as you read: Open the Markdown Editor to test each example, or use the Markdown Link Generator to build one quickly.
Syntax at a glance
| Link type | Syntax |
|---|---|
| Inline | [Text](https://example.com) |
| With a tooltip | [Text](https://example.com "Tooltip") |
| Reference | [Text][ref] plus [ref]: https://example.com |
| Autolink | <https://example.com> |
<name@example.com> or [Email us](mailto:name@example.com) |
|
| Relative | [Guide](docs/guide.md) |
| Root-relative | [Lists](/markdown-lists) |
| Heading in this file | [Jump](#installation) |
| Heading in another file | [Install](docs/guide.md#installation) |
| Image as link | [](https://example.com) |
Inline links
The most common type. Text and destination sit together.
Visit the [GitHub website](https://github.com).
Add a title in quotes after the URL for a hover tooltip:
[MDConvertHub](https://mdconverthub.com "Free online Markdown tools")
Many renderers turn the title into the HTML title attribute, and browsers usually show it on hover. Support varies by renderer and device, so never put essential information in it.
Reference links
Define the destination once and reuse the label. This keeps long paragraphs readable.
Read the [documentation][docs] or the [docs][] again later.
[docs]: https://mdconverthub.com/docs
The second form, [docs][], uses the text itself as the label. Labels are not case-sensitive.
Autolinks and bare URLs
Wrap a URL or email in angle brackets and it becomes a clickable link with no custom text. This works in every CommonMark renderer.
<https://mdconverthub.com>
Many GitHub-style renderers also link a bare URL that starts with http://, https:// or www., with no brackets. That is a GFM extension, not core CommonMark, so a strict CommonMark renderer shows plain text instead. If the link must work everywhere, use angle brackets. To show a URL as text, put it in backticks.
Email links
<support@example.com>
[Email us](mailto:support@example.com)
Both open the reader's default email app with the address filled in.
Relative and root-relative links
Both point to files in the same project instead of a full URL.
- Relative paths start from the current file:
[Install](docs/installation.md)or[Parent](../README.md). - Root-relative paths start with
/and resolve from the site root on a website, or the repository root on GitHub:[Lists](/markdown-lists).
Both keep working when the project is cloned or moved. Image paths follow the same rules, explained in adding images step by step.
Links to headings
Many platforms create an anchor for every heading. You link to it with # and the anchor name:
[Jump to Installation](#installation)
## Installation
On GitHub, the anchor is the heading in lowercase, with punctuation removed and spaces turned into hyphens. If two headings are the same, the second gets -1 added, the third -2, and so on. Other platforms differ, so check yours. The full rules are in the heading anchor guide.
To link to a heading in another file, add the anchor after the path: [Install](docs/guide.md#installation).
Open a link in a new tab
Markdown has no syntax for this. Plain [text](url) follows the platform's default behaviour. If your platform allows HTML, use an <a> tag:
<a href="https://example.com" target="_blank" rel="noopener">Visit site</a>
Check first that your platform does not sanitize HTML. Some remove the target attribute, and GitHub is likely one of them, so the link will open in the same tab there. For other HTML limits, see what gets stripped.
URLs with spaces or parentheses
A space or an unbalanced parenthesis ends the URL early and breaks the link.
| Problem | Fix |
|---|---|
| Space in the path | Wrap the path in angle brackets, [Guide](<my guide.md>), or write %20. Better: rename the file with hyphens. |
| Parenthesis in the URL | Write it as %28 and %29, or escape with a backslash. |
Link text that is bold, code or an image
Put the formatting inside the brackets:
[**Bold link**](https://example.com)
[`npm install`](https://www.npmjs.com)
[](https://example.com)
The image form is explained in the image reference.
Write good link text
| Avoid | Prefer |
|---|---|
[Click here](https://example.com/setup) |
[Setup guide](https://example.com/setup) |
[https://example.com/setup](https://example.com/setup) |
[Setup guide](https://example.com/setup) |
Link text should make sense when read alone, because screen readers list links out of context. Use HTTPS where it is available, and check every link before you publish. Broken URLs, paths and anchors fail silently, and an automated link check finds them.
Common mistakes
| Mistake | Fix |
|---|---|
Missing closing parenthesis: [GitHub](https://github.com |
[GitHub](https://github.com) |
Empty link text: [](https://example.com) |
[Project website](https://example.com) |
Wrong relative path: [Guide](guide.md) when the file is in docs/ |
[Guide](docs/guide.md) |
Space between ] and ( |
Remove it: [Text](url) |
| Anchor does not match the heading | Check capitalization, punctuation and duplicate headings. |
Where each link type works
Inline, reference and relative links work in GitHub, GitLab, VS Code and Obsidian. Bare-URL autolinks need a GFM-style renderer. Obsidian also has its own [[wikilink]] syntax, which other tools do not read. For chat and note apps, check the app's own docs.
Frequently Asked Questions
- 1
How do I link to a heading in another Markdown file?
Write the path, then
#and the heading's anchor:[Install](docs/guide.md#installation). The anchor has to match the heading in the other file exactly, so renaming that heading breaks the link. - 2
How do I put a space or parenthesis in a Markdown link URL?
Wrap the URL in angle brackets,
[Guide](<my guide.md>), or encode the characters:%20for a space,%28and%29for parentheses. Renaming files to use hyphens avoids the problem. - 3
Why isn't my heading link working?
The anchor does not match the heading. GitHub lowercases the heading, drops punctuation and turns spaces into hyphens, and adds
-1to duplicate headings. Copy the anchor from the rendered page, or check the anchor rules on the Markdown Headings page. - 4
Why is a plain URL not clickable?
Clickable bare URLs are a GFM extension. A strict CommonMark renderer shows them as text. Wrap the URL in angle brackets,
<https://example.com>, and it works everywhere. - 5
Can link text be bold or code?
Yes. Put the formatting inside the brackets:
[**Bold**](url)or[`code`](url). Do not wrap the whole link in the formatting unless you want the same effect on the brackets.
