HTML has a class
attribute that is used by CSS to assign different properties within one block so that it can be assigned to any element. Once assigned a specific class
, these elements will have all the properties that are attributed to that particular class
.
class
in CSS allows the user to apply the same style to multiple elements without having to repeat blocks of CSS code.class
can be assigned to an element, hence they can have multiple styles.class
as opposed to having to change it for multiple elementsclass
can be assigned to different types of elements like a paragraph or a heading style and hence create design coherence if need beAny class
is declared by preceding the class name with a (.
). The code below shows how to do this.
Note: A class name is case-sensitive
Now that we know how to declare a class
, we will learn how to assign it to a particular element. The example below shows how to do this.
From lines 4 to 8 the exampleClass
is defined and assigned particular properties
The exampleClass
is assigned to an element in line 12
The same type of element is declared on line 13 but it does not have any class
assigned to it