Top community members
All Questions Ask Question

Welcome to Dirask IT community! ❤ 💻
We are community of people that helps each other.

If you think you have some skills to help others

help someone and become a part of our community - List Q & A

What is the difference between id and class in CSS?

0 answers
3 points

I can assign styles using id and class.

Which one should I use and why?

I can achieve the same result using class and id.

Example using class:

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
    <style>
        .test {
            color: red;
        }
    </style>
</head>
<body>
    <div class="test">Hello</div>
</body>
</html>

Example using id:

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
    <style>
        #test {
            color: red;
        }
    </style>
</head>
<body>
    <div id="test">Hello</div>
</body>
</html>

In both examples text changes color from black (default color) to red color.

0 answers

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more