How to use multiple classes on the same element in CSS

CSS (Cascading Style Sheets) define a webpage element’s appearance by hooking into the attributes that are applied to that element. These attributes can be either an ID or a class and, like all attributes, they must add helpful information to the elements that they are assigned to.

An element is usually only assigned one class. The corresponding CSS for that particular class defines the appearance properties for that class.

However, we can also assign multiple classes to the same element in CSS. In some cases, assigning multiple classes makes page styling easier and much more flexible.

Syntax

To assign multiple classes to an element, separate each class with a space within the element’s class attribute.

<p> Some text... </p>

Code

The first div gets the properties of class1, the second div gets those of class2, while the third gets the properties of both class1 and class2.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved