All you Need to Know About “a” tag in HTML
Redirecting someone to another page or redirecting content to your webpage is a very good way to keep things interactive. This can be made possible by the “a tag in HTML”. Let’s understand this but first
What are tags in HTML?
HTML tags are like keywords which defines that how web browser will format and display the content. With the help of tags, a web browser can distinguish between an HTML content and a simple content. HTML tags contain three main parts: opening tag, content and closing tag. But some HTML tags are unclosed tags.
When a web browser reads an HTML document, browser reads it from top to bottom and left to right. HTML tags are used to create HTML documents and render their properties. Each HTML tags have different properties.
An HTML file must have some essential tags so that web browser can differentiate between a simple text and HTML text. You can use as many tags you want as per your code requirement.
- All HTML tags must enclosed within < > these brackets
- Every tag in HTML perform different tasks.
- If you have used an open tag <tag> then you must use a close tag <tag> (except some tags)
What is ‘a’ tag in HTML?
A link is specified using HTML tag. This tag is also known as anchor tag and anything inside this opening tag and closing tag becomes the part of the link and the user can just click that part and can reach to that linked content or document. This <a> is the simple tag to use and is as follows:
<!DOCTYPE html>
<html>
<head>
<title> a tag</title>
</head>
<body>
<h2> HTML Links</h2>
<a href=”https://www.google.com/” target=”_blank”> Google </a>
</body>
</html>
Output
a tag
HTML Links
Google
Options in ‘a’ Tag
You can provide a lot of options in this a tag in HTML. Below are some of them
Option | Description |
---|---|
_blank | A linked document is opened in a new tab or new window. |
_self | A linked document is opened in the same frame. |
_parent | A linked document is opened in the parent frame |
_top | A linked document is opened in the full body of the window. |
targetframe | A linked document is opened in a named targetframe. |
download | To create a link that tells a browser to download a file |
Example for the basic understanding the difference in few options given for target attribute of a tag.
<!DOCTYPE html>
<html>
<head>
<title> Link HTML</title>
<base
href=”<a href=”http://www.mildaintrainings.com/”>http://www.mildaintrainings.com/</a>”>
</head>
<body>
<p> Click any of the following links.</p>
<a href=”https://mildaintrainings.com/” target=”_blank”> Opens in new </a> |
<a href=”https://mildaintrainings.com/” target=”_parent”> Opens in parent </a> |
<a href=”https://mildaintrainings.com/” target=”_self”> Opens in self </a> |
<a href=”https://mildaintrainings.com/” target=”_top”> Opens in body </a> |
<a href=”https://mildaintrainings.com/images/logo.png” download=”Example_File”>download a file</a>
</body>
</html>
Output
Link HTML
http://www.mildaintrainings.com/
Click any of the following links.
Opens in new |
Opens in parent |
Opens in self |
Opens in body |
download a file
With this, we come to an end of this a tag in HTML article. I hope you understood what an anchor tag is.
Check out our Full Stack Web Developer Masters Program which comes with instructor-led live training and real-life project experience. This training makes you proficient in skills to work with back-end and front-end web technologies. It includes training on Web Development, jQuery, Angular, NodeJS, ExpressJS, and MongoDB