Anchor Tag (a tag) in HTML

25
Mr. Coder | 23-Oct-2024
Description

Anchor tag which is seen as <a> is used to create a hyperlink on the html page. It links one page to another page. 

href attribute of <a> tag is used to define the the destination link for the hyperlink as shown below in the example.

<a href="https://thegyanva.com/publication/mister_coder">click here</a>
Output : click here
The above link will load the new page in the same window.

Here comes new attribute which is used to open the destination page in the new window, that is target, we need to set the target as _blank

<a href="https://thegyanva.com/publication/mister_coder" target="_blank">click here</a>
Output : click here

In order to call the JavaScript function instead of redirection we can use the onclick attribute instead of href as shown below in the example.

<a onclick="alert('hello')">click here</a>
Output : click here
Note : removing href attribute will impact the css properties and you might see a difference in color/design properties.

Attributes
hrefUrl of the destination page
mediamedia or device linked document
pingspace separated list of URLs of previous links
targetlocation for opening the page (_blank, _parent, _self, _top)
Comments
Load more comments.
Please Login or Sign up to comment.
logo
facebook youtube