Class Html


public class Html extends StyledElement<Html>
Represents an HTML <html> (root) element.

The <html> element is the root element of an HTML document and contains all other HTML elements. It represents the entire HTML document and serves as a container for the <head> and <body> sections.

The <html> element restricts its content to exactly one Head element and one Body element. Use the typed Element.addElement(Head) and Element.addElement(Body) methods to add children.

Usage:


 // Create an HTML document root
 Html html = new Html();
 html.setLang("en");
 html.setXmlns(true);

 Head head = new Head();
 head.setTitle("My Page");

 Body body = new Body();
 body.addElement(new H1("Hello World"));

 html.addElement(head);
 html.addElement(body);
 
Since:
2007
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • Html

      public Html()
      Constructs an empty <html> root element.
  • Method Details

    • removeAllElements

      public void removeAllElements()
      Removes all child elements from this HTML document root.
      Overrides:
      removeAllElements in class Element<Html>
    • setDir

      public final Html setDir(TextDirection direction)
      Sets the text direction for the element using a TextDirection enum value.
      Overrides:
      setDir in class Element<Html>
      Parameters:
      direction - The text direction (LTR or RTL).
      Returns:
      This element for method chaining.
    • setManifest

      @Deprecated public Html setManifest(String url)
      Deprecated.
      The Application Cache feature has been removed from the HTML specification. Use Service Workers for offline support instead.
      Sets the manifest attribute for offline web application caching.

      If the URL starts with "/" (absolute path within the application), the servlet context path will be automatically prepended.

      Parameters:
      url - the URL of the cache manifest file
      Returns:
      this element for method chaining
    • setXmlns

      public Html setXmlns(boolean flag)
      Sets or removes the XHTML namespace declaration.

      If flag is true, sets the xmlns attribute to the standard XHTML namespace "http://www.w3.org/1999/xhtml". If false, removes the xmlns attribute.

      Parameters:
      flag - if true, sets XHTML namespace; if false, removes it
      Returns:
      this element for method chaining
    • setXmlns

      public Html setXmlns(String url)
      Sets the XML namespace declaration for this HTML element.

      The xmlns attribute declares the XML namespace for the document. For XHTML documents, this is typically "http://www.w3.org/1999/xhtml".

      Parameters:
      url - the namespace URI, or null to remove the attribute
      Returns:
      this element for method chaining