Sobes.tech
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:

    1. Create an identifier (id) for the target element.
      <h2 id="section2">Section 2</h2>
      
    2. Create a link using # and the identifier.
      <a href="#section2">Go to Section 2</a>
      

In testing context:

  • Checking the correctness of the URL in the href attribute.
  • Checking the accessibility of the target resource (page, section).
  • Checking the correct transition to the desired section when using anchors with #.
  • Checking the target attribute to specify where to open the link (e.g., _blank for a new window/tab).
  • Checking the rel attribute to specify relationships between the current page and the target resource.

Anchors are a fundamental element of navigation on the web.