Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding CSS class to anchor link in markdown (Hugo)

I'm using anchor links in my .markdown document like so:

# {#infrared}

This works fine but I wanted to implement the following CSS so that the link scrolls to the middle of the page and not at the top:

.anchor {
  position: absolute;
  transform: translateY(-50vh);
}

How can I add the class anchor to my anchor link in the markdown document?

like image 409
Aman Avatar asked Oct 27 '25 18:10

Aman


1 Answers

Based on this answer here, we have:

As per the README 1 of Goldmark the Markdown processor that is currently turned on by default in Hugo:

Currently only headings support attributes…

## heading ## {#id .className attrName=attrValue class="class1 class2"}
 
## heading {#id .className attrName=attrValue class="class1 class2"}
like image 144
Aman Avatar answered Oct 29 '25 10:10

Aman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!