span
span
The <span>
element in HTML is an inline container used for grouping text or elements, allowing for styling and manipulation. Common attributes include class
, id
, style
, title
, lang
, and custom data-*
attributes. These attributes enhance the flexibility of content presentation and interactivity without disrupting the flow of text.
Syntax
<span attribute1="value" attribute2="value" ...>Content</span>
Example
Col
- Here, the first two columns should have a background color of red:
ISBN | Title | Price |
---|---|---|
3476896 | My first HTML | $53 |
5869207 | My first CSS | $49 |
<table>
<colgroup>
<col span="2" style="background-color: red;">
<col style="background-color: yellow;">
<col>
</colgroup>
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td>$53</td>
</tr>
<tr>
<td>5869207</td>
<td>My first CSS</td>
<td>$49</td>
</tr>
</table>
Colgroup
- Set the background color of the first two columns using the
span
attribute in the<colgroup>
element:
ISBN | Title | Price |
---|---|---|
3476896 | My first HTML | $53 |
5869207 | My first CSS | $49 |
<table>
<colgroup span="2" style="background:red"></colgroup>
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td>$53</td>
</tr>
<tr>
<td>5869207</td>
<td>My first CSS</td>
<td>$49</td>
</tr>
</table>
conclusion
The <span>
element is a versatile inline container used for grouping content, enabling styling and interaction without disrupting the flow of text. It works well with attributes like class
, id
, and style
for dynamic presentation. Additionally, the span
attribute in <colgroup>
allows for efficient styling of multiple table columns.
slot
The slot attribute in HTML is utilized in web components to create placeholder regions for inserting child elements, allowing for flexible composition and styling of components.
spellchecker
The spellcheck attribute in HTML determines if the browser should check the spelling of the content in an input field, enhancing text accuracy and the overall user experience.