Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

css
classes
multiple

How to use multiple classes on the same element in CSS

Educative Answers Team

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 class = "firstclass secondclass thirdclass"> 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.

RELATED TAGS

css
classes
multiple
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring