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 | <html> xmlns Attribute
- HTML | <img> src Attribute
- HTML | dir Attribute
- HTML | <bdo> dir Attribute
- HTML | max attribute
- HTML | <img> alt Attribute
- HTML | min Attribute
- HTML | low Attribute
- HTML | <a> rel Attribute
- HTML | for Attribute
- HTML | value Attribute
- HTML | rel attribute
- HTML | alt attribute
- HTML | name 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.