HTML class attribute

HTML class attribute

In this tutorial, we will learn about class attribute in HTML with the help of examples.

class attribute

The class attribute is used to specify one or more classnames for a tag.

Note : The class attribute is mostly used to point to a class in a stylesheet and used by a Javascript to target the elements with the specified class name.


<a class = "newLink">......</a>

Attribute values

Value Description
className Used to specify one or more class names for an element

Note : To specify multiple classes we have to seperate the class names with a space.

Class Naming Rules

Naming rules to specify class name :

  • Must contaim at least one character
  • Must begin with a letter A-Z or a-z
  • Can be followed by : letters(A-Z, a-z), digit(0-9), hypens("-"), and underscore("_")
  • Must not contain any space characters

Next Tutorial

We hope that this tutorial helped you develop better understanding of the concept of Class Attribute in HTML.

Keep Learning : )

In the next tutorial, you'll learn about HTML contenteditable attribute.

- Related Topics