HtmlDocument.Body Property

Definition

Gets the HtmlElement for the BODY tag.

C#
public System.Windows.Forms.HtmlElement Body { get; }
C#
public System.Windows.Forms.HtmlElement? Body { get; }

Property Value

The HtmlElement object for the BODY tag.

Examples

The following code example creates a new DIV element and appends it to the bottom of the document using the AppendChild method.

C#
private void AppendText(String text)
{
    if (webBrowser1.Document != null)
    {
        HtmlDocument doc = webBrowser1.Document;
        HtmlElement textElem = doc.CreateElement("DIV");
        textElem.InnerText = text;
        doc.Body.AppendChild(textElem);
    }
}

Remarks

An HTML document is split into two major sections:

  • HEAD, which contains the document's title, any document meta-data, and SCRIPT elements.

  • BODY, which contains all of the elements involved in the on-screen appearance of the document.

There is no equivalent Head property on HtmlDocument. To obtain the HEAD element, use GetElementsByTagName.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also