Google Web Toolkit (Beta)
Search this site:

# Class HTML

public class HTML
extends Label
implements HasHTML
A widget that can contain arbitrary HTML.

If you only need a simple label (text, but not HTML), then the Label widget is more appropriate, as it disallows the use of HTML, which can lead to potential security issues if not used properly.

### CSS Style Rules

- .gwt-HTML { }

### Example

    public class HTMLExample implements EntryPoint {

      public void onModuleLoad() {
        // Create a Label and an HTML widget.
        Label lbl = new Label("This is just text.  It will not be interpreted "
          + "as <html>.");

        HTML html = new HTML(
          "This is <b>HTML</b>.  It will be interpreted as such if you specify "
            + "the <span style='font-family:fixed'>asHTML</span> flag.", true);

        // Add them to the root panel.
        VerticalPanel panel = new VerticalPanel();
        panel.add(lbl);
        panel.add(html);
        RootPanel.get().add(panel);
      }
    }

## Constructors

HTML() | Creates an empty HTML widget.
HTML(String) | Creates an HTML widget with the specified HTML contents.
HTML(String, boolean) | Creates an HTML widget with the specified contents, optionally treating it as HTML, and optionally disabling word wrapping.

## Methods

getHTML() | Gets this object's contents as HTML.
setHTML(String) | Sets this object's contents via HTML.

## Constructor Detail

### HTML

public HTML()
Creates an empty HTML widget.

### HTML

public HTML(String html)
Creates an HTML widget with the specified HTML contents.

#### Parameters

html
  the new widget's HTML contents

### HTML

public HTML(String html, boolean wordWrap)
Creates an HTML widget with the specified contents, optionally treating it as HTML, and optionally disabling word wrapping.

#### Parameters

html
  the widget's contents
wordWrap
  `false` to disable word wrapping

## Method Detail

### getHTML

public String getHTML()
Gets this object's contents as HTML.

#### Return Value

the object's HTML

### setHTML

public void setHTML(String html)
Sets this object's contents via HTML. Use care when setting an object's HTML; it is an easy way to expose script-based security problems. Consider using setText(String) whenever possible.

#### Parameters

html
  the object's new HTML