In this HTML article we are going to Hyperlinks and Anchors in HTML, Hyperlinks and anchors are integral components of HTML (Hypertext Markup Language), the language used to create web pages. they are the key elements that allow users to navigate through different web pages, explore the Internet, and access information with easy.
Hyperlinks and Anchors in HTML
In HTML hyperlinks are created by using anchor tag <a>. these tags are used to specify the target location, also known as destination of the hyperlink. destination can be another web page, specific section of web page, or even downloadable file such as PDF or an image.
This is the syntax for HTML anchor tag
1 |
<a href="destination">Link Text</a> |
In this code href stands for hypertext reference, which is the attribute that specifies destination of the hyperlink. destination can be URL, file name or an anchor on the same page. Link Text is the visible text that the user clicks on to activate the hyperlink.
For example this code creates hyperlink to GeeksCoders homepage:
1 |
<a href="https://www.geekscoders.com">Go to GeeksCoders</a> |
When user clicks on the Go to GeeksCoders link, the browser will open new tab or window and display GeeksCoders homepage.
Anchors on the other hand are used to create internal links within web page. An anchor is created by using anchor tag with unique identifier specified in name attribute. Anchors are usually placed at the beginning of the section to which the link will point.
This is the syntax
1 |
<a name="anchorName">Section Title</a> |
In this code name is the attribute of specifies unique identifier for the anchor. anchorName is the identifier name for the anchor which can be any text string without spaces. Section Title is the visible text that represents the section.
For example the following code creates an anchor with identifier section1:
1 2 |
<a name="section1"></a> <h2>Section 1</h2> |
To create hyperlink to this anchor we have used the anchor tag with href attribute set to #anchorName where anchorName is the identifier name of the anchor:
1 |
<a href="#section1">Go to Section 1</a> |
when the user clicks on Go to Section 1 link the browser will scroll down to the anchor with the identifier section1 and display the section.
Learn More on Python
- How to Integrate PyQt6 with OpenCV
- How to Create Button in Python & PySide6
- How to Use Qt Designer with PySide6
- How to Add Icon to PySide6 Window
- How to Load UI in Python PySide6
- How to Create RadioButton in PySide6
- How to Create ComboBox in PySide6
- How to Create CheckBox in Python PySide6
- Responsive Applications with PyQt6 Multithreading
- Event Handling in Python and PyQt6
- How to Use Stylesheets in Python PyQt6