Class in html:
- The class is an attribute which specifies one or more class names for an HTML element.
- The class attribute can be used on any HTML element.
Explanation: In the above example CSS styles all elements with the class name “country”.
- Before Clicking the hide elements button:
After clicking on the hide elements button :
Using multiple classes:
HTML elements can have more than one class name, where each class name must be separated by a space.
Explanation: All three headers have the class name “country”, but in addition to that, CHINA also has the class name “middle”, which makes the text center-aligned.
Using same class in different tags: Different tags, like <h2> and <p>, can have the same class name and thereby share the same style.
Explanation: Even if the two elements do not have the same tag name, they can have the same class name, and get the same styling.
Supported Browser: The browser supported by Class attribute are listed below :
- Google Chrome
- Internet Explorer
- Python - Access Parent Class Attribute
- HTML | min Attribute
- HTML | <a> rel Attribute
- HTML | rel attribute
- HTML | name Attribute
- HTML | <img> alt Attribute
- HTML | <map> name Attribute
- HTML | <li> value Attribute
- HTML | max attribute
- HTML | dir Attribute
- HTML | alt attribute
- HTML | value Attribute
- HTML | <bdo> dir Attribute
- HTML src attribute
- HTML | for Attribute
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.