{"route":"/en-US-v0.14.1/reference/model/link/","title":"Link","description":"Documentation for the `link` function.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"example","name":"Example","children":[]},{"id":"syntax","name":"Syntax","children":[]},{"id":"hyphenation","name":"Hyphenation","children":[]},{"id":"accessibility","name":"Accessibility","children":[]},{"id":"links-in-html-export","name":"Links in HTML export","children":[]},{"id":"parameters","name":"Parameters","children":[{"id":"parameters-dest","name":"dest","children":[]},{"id":"parameters-body","name":"body","children":[]}]}],"body":{"kind":"func","content":{"path":[],"name":"link","title":"Link","keywords":[],"oneliner":"Links to a URL or a location in the document.","element":true,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>Links to a URL or a location in the document.</p>\n<p>By default, links do not look any different from normal text. However,\nyou can easily apply a style of your choice with a show rule.</p>\n<h2 id=\"example\">Example</h2>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">show</span> <span class=\"typ-func\">link</span><span class=\"typ-punct\">:</span> <span class=\"typ-func\">underline</span>\n\n<span class=\"typ-link\">https://example.com</span> <span class=\"typ-escape\">\\</span>\n\n<span class=\"typ-func\">#</span><span class=\"typ-func\">link</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;https://example.com&quot;</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">link</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;https://example.com&quot;</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">[</span>\n  See example.com\n<span class=\"typ-punct\">]</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/9817d02583b839b8c8cae2e2fc58ca7e.png\" alt=\"Preview\"></div></div>\n<h2 id=\"syntax\">Syntax</h2>\n<p>This function also has dedicated syntax: Text that starts with <code>http://</code> or\n<code>https://</code> is automatically turned into a link.</p>\n<h2 id=\"hyphenation\">Hyphenation</h2>\n<p>If you enable hyphenation or justification, by default, it will not apply to\nlinks to prevent unwanted hyphenation in URLs. You can opt out of this\ndefault via <code><span class=\"typ-key\">show</span> <span class=\"typ-func\">link</span><span class=\"typ-punct\">:</span> <span class=\"typ-key\">set</span> <span class=\"typ-func\">text</span><span class=\"typ-punct\">(</span>hyphenate<span class=\"typ-punct\">:</span> <span class=\"typ-key\">true</span><span class=\"typ-punct\">)</span></code>.</p>\n<h2 id=\"accessibility\">Accessibility</h2>\n<p>The destination of a link should be clear from the link text itself, or at\nleast from the text immediately surrounding it. In PDF export, Typst will\nautomatically generate a tooltip description for links based on their\ndestination. For links to URLs, the URL itself will be used as the tooltip.</p>\n<h2 id=\"links-in-html-export\">Links in HTML export</h2>\n<p>In HTML export, a link to a <a href=\"/en-US-v0.14.1/reference/foundations/label/\" title=\"label\">label</a> or <a href=\"/en-US-v0.14.1/reference/introspection/location/\" title=\"location\">location</a> will be turned into a\nfragment link to a named anchor point. To support this, targets without an\nexisting ID will automatically receive an ID in the DOM. How this works\nvaries by which kind of HTML node(s) the link target turned into:</p>\n<ul>\n<li>\n<p>If the link target turned into a single HTML element, that element will\nreceive the ID. This is, for instance, typically the case when linking to\na top-level heading (which turns into a single <code>&lt;h2&gt;</code> element).</p>\n</li>\n<li>\n<p>If the link target turned into a single text node, the node will be\nwrapped in a <code>&lt;span&gt;</code>, which will then receive the ID.</p>\n</li>\n<li>\n<p>If the link target turned into multiple nodes, the first node will receive\nthe ID.</p>\n</li>\n<li>\n<p>If the link target turned into no nodes at all, an empty span will be\ngenerated to serve as a link target.</p>\n</li>\n</ul>\n<p>If you rely on a specific DOM structure, you should ensure that the link\ntarget turns into one or multiple elements, as the compiler makes no\nguarantees on the precise segmentation of text into text nodes.</p>\n<p>If present, the automatic ID generation tries to reuse the link target's\nlabel to create a human-readable ID. A label can be reused if:</p>\n<ul>\n<li>\n<p>All characters are alphabetic or numeric according to Unicode, or a\nhyphen, or an underscore.</p>\n</li>\n<li>\n<p>The label does not start with a digit or hyphen.</p>\n</li>\n</ul>\n<p>These rules ensure that the label is both a valid CSS identifier and a valid\nURL fragment for linking.</p>\n<p>As IDs must be unique in the DOM, duplicate labels might need disambiguation\nwhen reusing them as IDs. The precise rules for this are as follows:</p>\n<ul>\n<li>\n<p>If a label can be reused and is unique in the document, it will directly\nbe used as the ID.</p>\n</li>\n<li>\n<p>If it's reusable, but not unique, a suffix consisting of a hyphen and an\ninteger will be added. For instance, if the label <code>&lt;mylabel&gt;</code> exists\ntwice, it would turn into <code>mylabel-1</code> and <code>mylabel-2</code>.</p>\n</li>\n<li>\n<p>Otherwise, a unique ID of the form <code>loc-</code> followed by an integer will be\ngenerated.</p>\n</li>\n</ul>"}],"self":false,"params":[{"name":"dest","details":[{"kind":"html","content":"<p>The destination the link points to.</p>\n<ul>\n<li>\n<p>To link to web pages, <code>dest</code> should be a valid URL string. If the URL\nis in the <code>mailto:</code> or <code>tel:</code> scheme and the <code>body</code> parameter is\nomitted, the email address or phone number will be the link's body,\nwithout the scheme.</p>\n</li>\n<li>\n<p>To link to another part of the document, <code>dest</code> can take one of three\nforms:</p>\n<ul>\n<li>\n<p>A <a href=\"/en-US-v0.14.1/reference/foundations/label/\" title=\"label\">label</a> attached to an element. If you also want automatic text\nfor the link based on the element, consider using a\n<a href=\"/en-US-v0.14.1/reference/model/ref/\">reference</a> instead.</p>\n</li>\n<li>\n<p>A <a href=\"/en-US-v0.14.1/reference/introspection/location/\" title=\"`location`\"><code>location</code></a> (typically retrieved from <a href=\"/en-US-v0.14.1/reference/introspection/here/\" title=\"`here`\"><code>here</code></a>, <a href=\"/en-US-v0.14.1/reference/introspection/locate/\" title=\"`locate`\"><code>locate</code></a> or\n<a href=\"/en-US-v0.14.1/reference/introspection/query/\" title=\"`query`\"><code>query</code></a>).</p>\n</li>\n<li>\n<p>A dictionary with a <code>page</code> key of type <a href=\"/en-US-v0.14.1/reference/foundations/int/\">integer</a> and <code>x</code> and\n<code>y</code> coordinates of type <a href=\"/en-US-v0.14.1/reference/layout/length/\" title=\"length\">length</a>. Pages are counted from one, and\nthe coordinates are relative to the page's top left corner.</p>\n</li>\n</ul>\n</li>\n</ul>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-heading\">= Introduction</span> <span class=\"typ-label\">&lt;intro&gt;</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">link</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;mailto:hello@typst.app&quot;</span><span class=\"typ-punct\">)</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">link</span><span class=\"typ-punct\">(</span><span class=\"typ-label\">&lt;intro&gt;</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">[</span>Go to intro<span class=\"typ-punct\">]</span> <span class=\"typ-escape\">\\</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">link</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">(</span>page<span class=\"typ-punct\">:</span> <span class=\"typ-num\">1</span><span class=\"typ-punct\">,</span> x<span class=\"typ-punct\">:</span> <span class=\"typ-num\">0pt</span><span class=\"typ-punct\">,</span> y<span class=\"typ-punct\">:</span> <span class=\"typ-num\">0pt</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">[</span>\n  Go to top\n<span class=\"typ-punct\">]</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/afe2f0708d82d4ae0eb545a1b6f83c42.png\" alt=\"Preview\"></div></div>","title":null}}],"types":["str","label","location","dictionary"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"body","details":[{"kind":"html","content":"<p>The content that should become a link.</p>\n<p>If <code>dest</code> is an URL string, the parameter can be omitted. In this case,\nthe URL will be shown as the link.</p>"}],"types":["content"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false}],"returns":["content"],"scope":[]}}}