Open In App

How to create links with ‘target=”_blank”‘ in Markdown ?

Last Updated : 01 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will see how to create links with ‘target=”_blank”‘ in Markdown. Markdown is a free and open-source lightweight markup language that can be utilized to include formatting elements to plaintext text documents. It is a special way to write words that makes them look different on a computer. For instance, you can make some words look big and important, make some words look slanted, or add pictures and links to your words. It’s like coloring on a piece of paper, but for writing on a computer.

Markdown is used to format text on websites, blogs, and other digital documents. It provides a way to add formattings, such as headings, bold and italic text, lists, links, and images, to plain text without requiring the use of HTML or other more complex formatting languages. Markdown documents are typically saved with a .md or .markdown file extension and can be easily converted to HTML or other formats using a variety of tools and libraries. Many platforms, such as GitHub, use Markdown as their preferred format for documentation and other forms of content. 

Some common examples of Markdown syntax include:

  • # for headings (with ## for subheadings, ### for sub-subheadings, and so on).
  • * orfor unordered lists, and 1., 2., 3., and so on for ordered lists
  • **text** for bold text, and *text* for italic text
  • [link text](URL) for links, with the option to add a title attribute using quotes after the URL 

Overall, Markdown provides a simple and intuitive way to format text without requiring extensive knowledge of HTML or other more complex formatting languages. 

In target = “_blank”, when you click on a link on a website, it usually takes you to another tab. Sometimes, the website wants to keep you on its website, but still show you the other page. So, they can make the link open in a new window or tab. The “target” attribute is a special code that website designers use to tell the computer to open the link in a new window or tab, instead of replacing the current page. When the “target” attribute is set to “blank”, then it means “open the link in a new window or tab”. 

Syntax: For creating links in Markdown:

[Click here to visit GeeksForGeeks](https://www.geeksforgeeks.org/)

Example 1: In this example, the link text “here” is enclosed in square brackets, followed by the actual URL in parentheses. The {:target=”_blank”} syntax is then used to set the target attribute of the link to _blank, which tells the browser to open the link in a new tab when it is clicked.

HTML




Click [here](https://www.geeksforgeeks.org/){:target="_blank"} 
to visit GeeksForGeeks website.


Output: When we save this code is saved as a .md file and viewed in a Markdown editor or rendered it to HTML, it will display a hyperlink that, when clicked, will open the Example website in a new browser tab.

 

Example 2: This example describes the use of the target attribute by setting its value as “_blank”, which will open links in a new tab every time.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <meta charset="UTF-8">
    <title>
        Markdown Link with Target Blank Example
    </title>
</head>
  
<body>
    <h1>Click 
        <a href="https://www.geeksforgeeks.org/" 
           target="_blank">here
        </a> to visit GeeksForGeeks website.
    </h1>
</body>
  
</html>


Output: From the output, when we create a link Click Me to open geeksforgeeks! but it will open in a new browser tab.

 

It’s important to note that overuse of this attribute can be frustrating for users, as it can result in multiple open windows or tabs cluttering the desktop. It’s a good practice to use the target=”_blank” attribute only for external links that take the user away from your website, and not for internal links. In general, it’s a good practice to test any links with the target=”_blank” attribute to make sure they work as intended and to provide clear information to the user that the link will open in a new window or tab.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads