241

Is there a way to let a Link, written in githubs markdown, open in a new tab? All posts I have found related to this suggests to use HTML and target="_blank", which is fine with me, but that doesn't work. For example this link:

<a href="http://stackoverflow.com" target="_blank">Go</a> 

Does not open in a new tab. I'm no interested in replies for all kind of different markdown syntaxes, but only in a solution that will work when I write my markdown on github.

3

6 Answers 6

424

Well, it seems that the simple answer is "It's not possible". GitHub does not include the target attribute even if you use plain HTML, so it's not in the final HTML Anchor tag. Annoying, but OK, users can just do a CTRL+click (on Windows and Linux) or CMD+click (on MacOS) on the link to get the same behavior.

Sign up to request clarification or add additional context in comments.

3 Comments

+1 For not putting some wrong solution like thousands of other people on StackOverflow. You can't open links in a new tab using markdown (c. 2019).
While the answer is correct users can just do XYZ is not a solution to this problem. The behavior wanted is clicking on the link to automatically open in a new tab. The behavior with CTRL or CMD + click is adding 1 additional step. Further more unfortunately, other UX decision make CTRL/CMD+click unreliable sometime (Javascript link for instance) which means that the user would need to know what is an actual link and what is not. I wish Markdown just read the HTML at least.
Don't forget middle-click ("scroll-click" for some) with your mouse also works!
21

There is a solution specific to websites using GitHub pages (not the GitHub website itself): adding line

markdown: kramdown 

to file _config.yml, you can use [go](http://stackoverflow.com){:target="_blank" rel="noopener"} because then GitHub pages engine uses another markdown called kramdown for generating html. However, it does not work on previews and in markdown rendered by GitHub directly in the project repository.

5 Comments

Do you mean we can open github and open README.md to see the function is work for target _blank?
only if you have external site using GitHub Pages
As you said, the links aren't rendered properly on the GitHub Preview, but it worked perfectly after deployed the GitHub page.
NOT WORKING in github
the question is specifically about MD on github, so this answer is out of topic.
7

From what I have read and researched, it is not possible. I wanted to do something similar but soon realized that it is not a feature in git md, unfortunately.

Comments

0

Till date no feature like that has been captured except on github pages, but it will work when you use ctrl and click the link Here are when i tried using the _blank attribute this is when i try using the _blank attribute

And this is the preview i got on github

Comments

-6

It's possible for Github Pages users (Jekyll), the proper way (March 2022) is to add to your _config.yml file these lines:

kramdown: input: Kramdown 

This is specified in the documentation:

You can also change the processor used by Kramdown (as specified for the input key in the Kramdown RDoc). For example, to use the non-GFM Kramdown processor in Jekyll, add the following to your configuration.

Use the Kramdown processor instead of GFM will allow you to add {:target="_blank" rel="noopener"} to markdown links to tell the browser to open link in new tab.

Example

[Stackoverflow The Key](https://stackoverflow.blog/2021/03/31/the-key-copy-paste/){:target="_blank" rel="noopener"} 

/!\ Disclaimer

Changing the markdown processor from GFM (default value) to kramdown can create issues in the HTML result, since all the specific features of GitHub Flavored Markdown (GFM) won't work anymore.

Comments

-24

The answer should be what @Idavid posted in a comment.

[go](http://stackoverflow.com){:target="_blank"}. 

You should also add rel="noopener"

[go](http://stackoverflow.com){:target="_blank" rel="noopener"} 

4 Comments

As of 2019-01-11 neither of these approaches work on GitHub. github.com/mojombo/github-flavored-markdown/issues/28
I might have confused github markdown with github pages. I know on github pages it works.
It works for me in Gitpages. The file in repo is github.com/mind-maps/software/blob/master/index.md. Render as mind-maps.github.io/software with target="_blank"
The question clear states "in githubs markdown", and this works in the github page generated from the markdown - so it covers the question pretty well IMO (question could be clarified a little as to if it refers to the html generated from the markdown as by github). And it solved my need, so upvoting.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.