A longer page may need a container around several pieces of content for future styling, or a name for a small text fragment that is not a warning or code. Generic containers handle these cases without adding a specific content meaning.
Group content with div
div is a generic container, normally displayed as a block using the available width. An empty div may have no visible height. It does not automatically create a card background or border:
<div class="club-card">
<h2>Morning reading group</h2>
<p>Every Saturday at ten.</p>
</div>class groups elements under a name you choose. club-card is not a built-in effect. Multiple elements can share that class so CSS can later select them together. Unlike id, class values can repeat. An element can also have multiple class names separated by spaces.
Name a text fragment with span
span is generic too, but normally participates inline in the surrounding text:
<p>This week's topic is <span class="topic">nature writing</span>. Join us!</p>Without CSS, the span may look exactly like its surroundings. A class name does not automatically color it. Inline text can still wrap in a narrow viewport; inline does not mean it must fit on one line forever.
Prefer meaningful elements when available
Use p for a paragraph, strong for importance and ul or ol for a list. Do not replace them all with div and span merely to style them later. These containers do not supply heading, link or button behavior. Use button when you need a button.
The Lab compares the same words in div and span, then adds a class that has no styling yet. The next lesson introduces meaningful page-region elements.
Page experiment: div and span
Compare the examples, then change one part of the HTML using the observation prompt. Compare the source with the real rendered page.
Each div starts a block by default; sharing a class does not automatically add color.
The preview uses native browser headings, paragraphs and form controls. Switching examples replaces your edits; Reset lab restores the initial state. Follow in-page links, type and select options. This practice preview does not send form data or run scripts. To try locally, save the complete code as index.html and open it in a browser.
KNOWLEDGE QUIZ
Build it yourself: div and span
Create index.html, write a complete page using the requirements below, then save and open it in a browser. Interact with the page to check it. The reference is one possible implementation; wording may differ.
- Use two div containers with class="club-card", each containing an h2 and a p.
- Wrap one topic phrase in span class="topic" and explain why it has no special color yet.