span
A generic inline container.
Learn HTML Span with practical examples for structure, layout semantics, metadata, embedded content, scripts, accessibility, SEO and live practice.
HTML structure and layout
A span is like div, but inline. It has no meaning by itself and should usually live inside text or small inline interface pieces.
Use span when you need a styling hook around part of a sentence and no semantic element such as strong, em, code, mark or abbr fits.
A span should not replace meaningful text elements. If the text is emphasized, use em or strong. If it is code, use code. If it is just a visual highlight, span can be right.
A generic inline container.
A small wrapper for styling part of text.
strong, em, code, mark, abbr, time and more.
Often used to style a span consistently.
Syntax and structure
A span is safe when it supports styling or scripting without pretending to be semantic content.
<p> Learn <span class="highlight">semantic HTML</span> before styling everything with CSS. </p>
<span class="heading">Course title</span> <span class="important">Warning: payment required</span> <span onclick="submitForm()">Send</span>
Rules that matter
Layout-focused HTML is strongest when meaning, grouping, metadata and behavior hooks all have a clear reason to exist.
Span is useful around a small phrase, number, icon label or status text.
Use strong, em, code, mark, time or abbr when they match the meaning.
Visual size does not create document structure.
Use button or a with href for real interaction.
A span wrapping whole sections is probably the wrong element.
Use names like status, price or highlight instead of random color names.
Production thinking
This matters because small inline details often become design polish. Span gives you a hook without damaging the sentence structure.
Span adds no semantic information. If the distinction matters to assistive technology, choose a meaningful element.
Spans are common in design systems for badges, inline statuses and animated text. Keep their purpose narrow.
A styled span does not create headings or emphasis for search engines. Use real elements when meaning matters.
Live code lab
Edit the HTML or CSS, then use Run to refresh the preview. The preview is isolated, so links and forms stay inside this practice area.
Mini assignment
Practice assignment
Try it yourself
Self-check
Do not only read this page. Answer these questions out loud or write the answers in your own notes. If one answer feels vague, revisit the examples before moving on.