Tsallaka zuwa abun ciki
Justice Tech School

The div and span Elements

div is a generic block container and span is a generic inline container. They have no meaning of their own and are mostly used to attach classes and styles.

Prefer a semantic element (article, nav, section) when one fits, and use div only when none does.

Example
<div style="border: 2px solid #166534; padding: 12px; border-radius: 8px">
  <p>Inside a div with <span style="color: crimson; font-weight: bold">a styled span</span>.</p>
</div>

Exercise

Wrap part of a sentence in an inline container.

<p>Hello <>world</></p>

Quiz Test

When should you use div?

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