Attribute Groups

Attribute Groups

In HTML5, you can use attribute groups to specify a set of related attributes for an element. Attribute groups are not a formal part of the HTML5 specification, but they are a common practice used by many developers to make their HTML code more organized and easier to read.

To define an attribute group, you can create a new attribute with a name that represents the group, and then add a list of related attributes to that group. For example, you might create an attribute group called “form input attributes” that includes the name, value, type, and required attributes commonly used with form input elements:

<!DOCTYPE html>

<html>

<head>

<meta charset=”UTF-8″>

<title>Attribute Groups</title>

</head>

<body>

<form>

<label>

Name:

<input name=”name” value=”” type=”text” required>

</label>

<label>

Email:

<input name=”email” value=”” type=”email” required>

</label>

<label>

Password:

<input name=”password” value=”” type=”password” required>

</label>

</form>

</body>

</html>

In this example, the name, value, type, and required attributes are all related to form input elements and can be grouped together for clarity. By using attribute groups, you can make your code easier to read and maintain, especially for larger documents with many similar elements.

Note that attribute groups are not a formal part of the HTML5 specification, and they are not supported by all browsers or tools. However, many developers find them useful for organizing their code and improving readability.

Attributes are given in the opening tag of an element and have a name and a value pair. The name part of attribute is actually a property of the element and value gives a value (whether text or number) for that property like, ‘xmlns’ attribute describes the XML namespace for the XHTML document to refer to and to specify XHTML 1.0 namespace a value of “http://www.w3.org/1999/xhtml” is given.

Attributes are divided into three groups which are

Core attributes: It consist of class, id and title attributes

Internationalization attributes: It consist of dir, lang and xml:lang attributes

UI event attributes: They are linked to events like onclick, ondoubleclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown onkeyup

Core and internationalization attributes together are also called universal attributes.

The attribute groups are

          • Core Attributes
          • Internationalization
          • UI Events
          • HTML5 New Attributes

it consists of following topics

Get industry recognized certification – Contact us

Menu