HTML link attributes tell the browser how a link works. They set where the link goes, how it opens, and what extra details it adds.
What are HTML Link Attributes?
The HTML link attribute is part of the <a> tag. It defines link behavior. It controls how the link loads and what data it sends to the browser.
Here is the syntax you need to know:
<a href="URL" [attribute]=["value"]>Link Text</a>Here is an example:
<a href="https://example.com" target="_blank">Visit Site</a>This code sets a link that opens in a new tab.
Here are the commonly used link attributes:
- href sets the link destination.
- target controls how the link opens.
- rel sets the relation between the current page and the target.
- download tells the browser to download the file.
So, what are the differences between internal and external link attributes?
Internal links point to pages on the same site. External links point to other sites.
The internal link uses a short path like /about.html and keeps the visitor in the same domain.
An external link uses a full URL like https://news.com/page.html. It sends the visitor outside the site.
Examples of Link Attributes in HTML
Internal link with href:
<a href="/about.html">About Us</a>This link sends the user to the about page on the same site and keeps the navigation smooth and does not load a new tab.
External link with target:
<a href="https://example.com" target="_blank">Visit Example</a>This link sends the user to another site. It opens in a new tab so the current page stays in place. This is common for outside resources.
Link with rel attribute:
<a href="https://othersite.com" rel="nofollow">External Resource</a>This link goes to an external page. The rel attribute tells search engines not to pass ranking to this site. It is often used for sponsored or untrusted links.
Link with download attribute:
<a href="/files/report.pdf" download="AnnualReport.pdf">Download Report</a>This link points to a file. The browser does not open it. Instead, it downloads the file and saves it with the given name.
Wrapping Up
You learned what HTML link attributes are and how they work. You also saw the difference between internal and external links.
Here is a quick recap:
- Use
hrefto set the link path. - Use
targetto control how the link opens. - Use
relto mark a relation or block search flow. - Use
downloadto force file download.
FAQs
What are the most common HTML link attributes?
- href - defines the link destination
- target - controls where to open link
- rel - defines link relationship
- download - forces file download
<a href="https://example.com" target="_blank" rel="noopener">Visit</a>
This link opens in a new tab safely.How do you open a link in a new tab using HTML?
<a href="https://google.com" target="_blank">Google</a>
Explanation: Using target="_blank" makes the link open in a new browser tab.
What does the rel attribute do in HTML links?
- rel="nofollow" - tells search engines not to pass ranking
- rel="noopener" - prevents security risks
- rel="sponsored" - marks paid links
<a href="https://ads.com" rel="sponsored">Ad Link</a>
Best for SEO and link safety.How can you force a link to download a file?
<a href="file.pdf" download>Download PDF</a>
Explanation: Adding the download attribute tells the browser to save the file instead of opening it.Similar Reads
The heading elements define a content structure in HTML. Use <h1> to <h6> to show levels. <h1> means the main…
In this article, you will learn how HTML legend works in the fieldset tag with examples. HTML fieldset and legend…
You use the HTML <table> tag to display structured data in rows and columns, using table elements such as <tr>…
The address tag in HTML shows contact details. The <address> tag helps show who owns the page or article. Understand…
The HTML <template> tag lets you store HTML content that won’t show up right away. JavaScript can pull it in…
data-* attributes store extra values on elements without an extra DOM nodes or backend requests. What are data-* attributes in…
Use the HTML object tag to embed different types of external files into your webpage. It works for videos and…
The HTML embed tag is used to display media content, such as videos or audio. It can also display PDFs…
The <main> tag in HTML marks the central content of a webpage. It tells browsers and assistive technologies where the…
HTML5 gave the web new elements that describe content with more meaning. Developers now use these elements to build pages…