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 id attribute adds a unique name to an HTML element. It helps with CSS and JavaScript in the page.…
The HTML samp tag shows the result of a computer program or command. It helps readers know which text came…
The form novalidate attribute in HTML lets you skip browser checks when you submit a form. You can control errors…
The video tag in HTML plays video files directly in the browser. It adds custom playback without third-party services or…
The HTML em tag shows stress or emphasis in text. It changes meaning for readers and screen readers. What is…
The <ins> tag in HTML shows text that the author added after the original content. This helps readers know what…
The HTML embed tag is used to display media content, such as videos or audio. It can also display PDFs…
The breadcrumb in HTML shows a path through a site and marks the place of a page inside it. It…
The iframe tag embeds another HTML page inside the current page. It loads content from a separate source. Understand the…
The <i> tag stands for "italic." It marks text that has a different voice or tone, such as a technical…