HTML links are elements used to navigate between web pages or different sections within the same page. They are created using the <a>
(anchor) tag. Here's the basic syntax:
<a>
: This is the anchor tag, which defines a hyperlink.href
: This attribute specifies the URL of the page the link goes to.Link Text
: This is the text that appears as the link.This will create a link that says "Visit Example" and leads to the URL "https://www.example.com" when clicked.
HTML links can also be used to link to other parts of the same page by specifying the target location using the id attribute of the element to which you want to link.
in this example, clicking "Jump to Section 2" will scroll the page to the section with the id of "section2".
You can also use relative URLs to link to pages within the same website or directory structure. For example:
This will link to the "about.html" page in the same directory as the current page
Additionally, you can open the link in a new browser tab or window by adding the target="_blank" attribute:
This will open the "https://www.example.com" link in a new tab when clicked.