EN
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