Junior
What is an anchor?
sobes.tech AI
Answer from AI
Anchor in web development is an HTML element that creates a hyperlink (connection) between two resources. It is most commonly used to create links to other web pages or to specific sections of the current page.
The main tag for creating an anchor is <a href="...">.
Examples of usage:
-
Link to an external resource:
<a href="https://www.google.com">Link to Google</a> -
Link to an internal resource (another page of the site):
<a href="/about-us">About Us</a> -
Link to a specific section on the same page:
- Create an identifier (id) for the target element.
<h2 id="section2">Section 2</h2> - Create a link using
#and the identifier.<a href="#section2">Go to Section 2</a>
- Create an identifier (id) for the target element.
In testing context:
- Checking the correctness of the URL in the
hrefattribute. - Checking the accessibility of the target resource (page, section).
- Checking the correct transition to the desired section when using anchors with
#. - Checking the
targetattribute to specify where to open the link (e.g.,_blankfor a new window/tab). - Checking the
relattribute to specify relationships between the current page and the target resource.
Anchors are a fundamental element of navigation on the web.