Classes in HTML are references used to apply some CSS properties to HTML elements. With classes, you can use the dot operator to define the style of the class, and add classes whenever you want to apply that style. In this tutorial you will learn about HTML classes and their applications.
This “html class” tutorial covers the following topics:
- HTML class attribute
- multiple classes
- Same class with different tags
HTML class attribute
In HTML, you can add “class” as an attribute to an element to indicate that the element should have a style attribute of class.
![]()
Here we used “heading” to define the class name. Then I styled the element using this class name.
![]()
multiple classes
You can also use multiple classes within the same element. Here the class names must be separated by spaces.
![]()
All three headers have a class name of “country”, but BELGIUM also has a class name of “middle”, so the text is centered.
![]()
Same class with different tags
Different HTML tags can use the same class name and thus incorporate the same styles.
![]()
Here, as you can see, different tags have the same class name ‘country’. Both tags share similar styles.
![]()
Full Stack Web Developer – Advance your career as a MEAN Stack developer with the MEAN Stack Master Program. Register now!
So much for the HTML class.
Conclusion
This concludes this HTML class tutorial. You learned how to use classes in HTML tags to properly style the tags with CSS by specifying individual class names.
If you’re looking for a comprehensive course in full-stack development, be sure to check out our full-stack web development graduate program in partnership with Caltech CTME. This course provides industry-applied, applied training in all the skills, tools, and languages you need to learn to be a successful full-stack developer.
If you have any questions regarding this “Classes in HTML” tutorial, share them in the comments section. Our subject matter experts are available to answer your questions. Have fun learning!
