HtmlElement.TagName Property

Note: This property is new in the .NET Framework version 2.0.

Gets the name of the HTML tag.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in

public string TagName { get; }
/** @property */
public String get_TagName ()

public function get TagName () : String

Property Value

The name used to create this element using HTML markup.

Many elements in the HTML Document Object Model have attributes, properties, and methods that are unique to those elements; such as the HREF attribute on the A element, or the Submit method on FORM. Use TagName when you have an element of a potentially arbitrary type, and need to perform a type-specific operation.

The following code example finds all of the IMG tags in a document, and uses the TagName property to test whether the IMG is hyperlinked to another page; if it is, the code assigns the URL to the ALT attribute of the IMG tag, so that users can mouse over the image to see where it will take them.

private void AddUrlToTooltip()
    if (webBrowser1.Document != null)
        foreach (HtmlElement elem in webBrowser1.Document.GetElementsByTagName("IMG"))
            if (elem.Parent.TagName.Equals("A"))
                String altStr = elem.GetAttribute("ALT");
                if (!(altStr == null) && (altStr.Length != 0))
                    elem.SetAttribute("ALT", altStr + " - points to " + elem.Parent.GetAttribute("HREF"));
                    elem.SetAttribute("ALT", "Points to " + elem.Parent.GetAttribute("HREF"));

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions