Tsallaka zuwa abun ciki
Justice Tech School

The class Attribute

class gives elements a shared name so one CSS rule can style them all. An element can have several classes separated by spaces. In CSS a class selector starts with a dot.

Example
<style>
  .card { border: 1px solid #94a3b8; padding: 10px; margin: 6px 0; border-radius: 6px; }
  .important { background: #fee2e2; }
</style>
<div class="card">Normal card</div>
<div class="card important">Important card</div>

Exercise

Give the element the class "card".

<div ="card">Hi</div>

Quiz Test

Can an element have more than one class?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.