This documentation is archived and is not being maintained.

HtmlElement.GetAttribute Method

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

Retrieves the value of the named attribute on the element.

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

public string GetAttribute (
	string attributeName
public String GetAttribute (
	String attributeName
public function GetAttribute (
	attributeName : String
) : String



The name of the attribute. This argument is case-insensitive.

Return Value

The value of this attribute on the element, as a String value. If the specified attribute does not exist on this element, returns an empty string.

An attribute in HTML is any valid name/value pair for that element. HtmlElement exposes only those attributes that are common to all elements, leaving out those that only apply to certain types of elements; SRC is a predefined attribute for the IMG tag, for example, but not for the DIV tag. Use GetAttribute and SetAttribute to manipulate attributes not exposed on the managed Document Object Model (DOM).

GetAttribute and SetAttribute are case-insensitive.

The following code example retrieves all of the META tags within an HTML document, using GetAttribute to find the META tag with the name Description. The example requires that your application has a WebBrowser control named WebBrowser1.

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