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
- HTML | <html> xmlns Attribute
- Python - Access Parent Class Attribute
- How to find the parent class name with known class in jQuery ?
- How to override the CSS properties of a class using another CSS class ?
- Difference between Class.method and Class.prototype.method
- HTML | scoped Attribute
- HTML | <th> valign Attribute
- HTML | <col> align Attribute
- HTML | poster Attribute
- HTML | style attribute
- HTML | <area> target Attribute
- HTML | oninvalid Event Attribute
- HTML | <select> autocomplete Attribute
- HTML & CSS | Tabindex attribute & Navigation bars
- HTML | <table> bgcolor Attribute
- HTML | onsubmit Event Attribute
- HTML | onunload Event Attribute
- HTML | srcdoc Attribute
- HTML | Marquee truespeed attribute
- HTML | onkeyup Event 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.