2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: Links and Cross References
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								description: Shortcodes for creating links to documents.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								date: 2017-02-01
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								publishdate: 2017-02-01
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								lastmod: 2017-03-31
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								categories: [content management]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								keywords: ["cross references","references", "anchors", "urls"]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								menu:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  docs:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parent: "content-management"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    weight: 100
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								weight: 100	#rem 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								aliases: [/extras/crossreferences/]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								toc: true
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The `ref`  and `relref`  shortcodes display the absolute and relative permalinks to a document, respectively.
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Use `ref` and `relref`
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```go-html-template
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{{</* ref "document" */>}}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{{</* ref "document#anchor " */>}}
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{{</* ref "document.md" */>}}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{{</* ref "document.md#anchor " */>}}
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{{</* ref "#anchor " */>}}
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{{</* ref "/blog/my-post" */>}}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{{</* ref "/blog/my-post.md" */>}}
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{{</* relref "document" */>}}
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{{</* relref "document.md" */>}}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{{</* relref "#anchor " */>}}
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{{</* relref "/blog/my-post.md" */>}}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								To generate a hyperlink using `ref`  or `relref`  in markdown:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```md
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[About ]({{</* ref "/page/about" */>}} "About Us" )
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The `ref`  and `relref`  shortcodes require a single parameter: the path to a content document, with or without a file extension, with or without an anchor.
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								**Paths without a leading `/`  are first resolved relative to the current page, then to the remainder of the site.
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Hugo emits an error or warning if a document cannot be uniquely resolved. The error behavior is configurable; see below.
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Link to another language version
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								To link to another language version of a document, use this syntax:
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```go-html-template
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{{</* relref path="document.md" lang="ja" */>}}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### Get another Output Format
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								To link to another Output Format of a document, use this syntax:
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```go-html-template
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{{</* relref path="document.md" outputFormat="rss" */>}}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Heading IDs
  
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								When using Markdown document types, Hugo generates element IDs for every heading on a page. For example:
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```md
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Reference
  
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								produces this HTML:
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								<h2 id="reference">Reference</h2>
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Get the permalink to a heading by appending the ID to the path when using the `ref`  or `relref`  shortcodes:
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-10-30 09:49:15 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```go-html-template
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{{</* ref "document.md#reference " */>}}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{{</* relref "document.md#reference " */>}}
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Generate a custom heading ID by including an attribute. For example:
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```md
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Reference A {#foo}
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Reference B {id="bar"}
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								produces this HTML:
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								<h2 id="foo">Reference A</h2>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								<h2 id="bar">Reference B</h2>
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Hugo will generate unique element IDs if the same heading appears more than once on a page. For example:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```md
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Reference
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Reference
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Reference
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								produces this HTML:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```html
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								<h2 id="reference">Reference</h2>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								<h2 id="reference-1">Reference</h2>
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								<h2 id="reference-2">Reference</h2>
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Ref and RelRef Configuration
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-09-07 21:37:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The behavior can, since Hugo 0.45, be configured in `config.toml` :
							 
						 
					
						
							
								
									
										
										
										
											2019-10-21 10:22:28 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								refLinksErrorLevel ("ERROR") 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								: When using `ref`  or `relref`  to resolve page links and a link cannot resolved, it will be logged with this log level. Valid values are `ERROR`  (default) or `WARNING` . Any `ERROR`  will fail the build (`exit -1` ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								refLinksNotFoundURL
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								: URL to be used as a placeholder when a page reference cannot be found in `ref`  or `relref` . Is used as-is.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[lists]: /templates/lists/
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[output formats]: /templates/output-formats/
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[shortcode]: /content-management/shortcodes/
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[bfext]: /content-management/formats/#blackfriday -extensions