Class SkipLink


public class SkipLink extends A<SkipLink>
A skip link that allows keyboard users to bypass navigation and jump to main content.

Skip links are a WCAG requirement that help keyboard users avoid having to tab through lengthy navigation menus on every page. The link is visually hidden until focused, then becomes visible so sighted keyboard users can see and use it.

Usage:


 // In createBody(), add skip link as the first element
 body.addElement(new SkipLink("main-content", "Skip to main content"));

 // Create main content area with matching ID
 Div mainContent = new Div();
 mainContent.setId("main-content");
 mainContent.setTabIndex(-1); // Allow programmatic focus
 body.addElement(mainContent);
 

Keyboard behavior:

  • Hidden by default (positioned off-screen)
  • Becomes visible when focused via Tab key
  • Activating the link moves focus to the target element
Since:
2025
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Field Details

  • Constructor Details

    • SkipLink

      public SkipLink(String targetId, String text)
      Creates a skip link targeting the specified element.
      Parameters:
      targetId - The ID of the element to skip to (without the # prefix).
      text - The link text (e.g., "Skip to main content").
    • SkipLink

      public SkipLink(String targetId)
      Creates a skip link with default text "Skip to main content".
      Parameters:
      targetId - The ID of the element to skip to (without the # prefix).
  • Method Details

    • initialize

      protected void initialize()
      Description copied from class: Element
      Hook method called during element initialization.

      Override this method to set up the element's structure by adding child elements. This is called before Element.create() and only once during the element's lifecycle.

      Overrides:
      initialize in class StyledElement<SkipLink>