Markdown Guide — Part 5: How to Add Links in Markdown
1. Basic Link Syntax
The basic format for a Markdown link is:
[Link Text](URL "Optional Title")
- The text inside square brackets
[]is the clickable part. - The text inside parentheses
()is the link target, which can be a URL or file path. - The text in double quotes is optional; it appears as a tooltip when you hover over the link.
Example:
[Visit Official Site](https://www.getprettymd.com/ "PrettyMd")
Rendered Result:
Visit Official Site
2. Relative vs. Absolute Paths
Markdown supports both relative paths and absolute paths:
| Type | Example | Use Case |
|---|---|---|
| Relative Path | [View Docs](/blog) |
Suitable for navigation within the same repository |
| Absolute Path | [Visit Website](https://www.getprettymd.com/) |
Suitable for external websites or fixed resources |
Recommendation:
Use relative paths in project documentation to prevent broken links after repository migration.
3. Linking to Headings (Anchor Links)
Markdown allows you to jump to a specific section of a document using anchors.
Syntax:
[Jump to Section](#section-heading)
Anchors are automatically generated from headings using these rules:
- Convert all characters to lowercase;
- Replace spaces with
-; - Remove punctuation marks.
Example:
[Jump to Summary Section](#summary)
Clicking it will take you to the “Summary” section at the end of this article.
4. Automatic Links
You can directly type a URL or wrap it in angle brackets < > to make it clickable:
<https://www.getprettymd.com/>
Rendered Result:
https://www.getprettymd.com/
Tip:
Some renderers (like GitHub) automatically convert bare URLs into clickable links, but it’s safer to wrap them in < > for compatibility.
5. Reference Links
Reference-style links make your Markdown cleaner, especially when reusing the same URLs multiple times.
Syntax:
[Link Text][id]
[id]: URL "Optional Title"
Example:
For more information, see the [Official Markdown Guide][md-doc].
[md-doc]: https://www.markdownguide.org "Markdown Guide"
Rendered Result:
For more information, see the Official Markdown Guide.
Advantages:
- Centralized management of link information;
- Cleaner, more readable content;
- Ideal for long documents and collaborative writing.
