Skip to content
Norn
Menu

norn-heading-anchor

A heading that links to itself, so a reader can copy a link to the section. The heading text is the link, with a # before it. Where the pointer can hover and the page is at least 70rem wide, the # hangs in the margin and shows while the heading is hovered or has focus. Elsewhere it stays in line: there is no hover to reveal it, or no room in the margin for it. The default slot is the heading text. headingAnchors in @allons-y/webc-patterns/markdown writes this component for Markdown headings. The # takes --norn-text-muted.

<norn-heading-anchor> a component, from @allons-y/webc-patterns

Examples

Color scheme
Width

Open on its own

Source
<norn-heading-anchor @slug="install">Install</norn-heading-anchor>
<p>Install the package from npm.</p>
<norn-heading-anchor @slug="with-npm" :@level="3">With npm</norn-heading-anchor>
<p>Run the install command in the project folder.</p>
Color scheme
Width

Open on its own

Source
<div style="display: grid; gap: 1.5rem">
	<div style="display: grid; gap: 0.5rem">
		<p><code>level = 2</code></p>
		<div>
			<norn-heading-anchor @slug="section" :@level="2">Section</norn-heading-anchor>
		</div>
	</div>
	<div style="display: grid; gap: 0.5rem">
		<p><code>level = 3</code></p>
		<div>
			<norn-heading-anchor @slug="section" :@level="3">Section</norn-heading-anchor>
		</div>
	</div>
	<div style="display: grid; gap: 0.5rem">
		<p><code>level = 4</code></p>
		<div>
			<norn-heading-anchor @slug="section" :@level="4">Section</norn-heading-anchor>
		</div>
	</div>
	<div style="display: grid; gap: 0.5rem">
		<p><code>level = 5</code></p>
		<div>
			<norn-heading-anchor @slug="section" :@level="5">Section</norn-heading-anchor>
		</div>
	</div>
	<div style="display: grid; gap: 0.5rem">
		<p><code>level = 6</code></p>
		<div>
			<norn-heading-anchor @slug="section" :@level="6">Section</norn-heading-anchor>
		</div>
	</div>
</div>

Props

Write them with the @ prefix, and :@ for an expression.

NameTypeDescription
@slug required string The heading's id, and the link's fragment.
@level number The heading level. One of 2, 3, 4, 5, or 6. Falls back to 2.

Slots

NameDescription
default The heading text.

Tokens

The global tokens from tokens.json the component reads. Set one in a project's tokens.css to change it everywhere.

Type a value to try it in every example above. Reset puts the default back.

Token Type Default Override
--norn-ui-accentThe brand color, shared by every component. <color> #2346d4
--norn-ui-motion-durationLength of a state change, such as a hover layer. <time> 150ms
--norn-ui-motion-easingEasing for every transition. <easing-function> cubic-bezier(0.2, 0, 0, 1)
--norn-text-mutedSecondary text color. <color> light-dark(#4b5160, #a4abba)
--norn-space-2xsSmallest spacing step. <length> 0.25rem
--norn-space-mMedium spacing step. <length> 1.25rem