Sumari
L'element HTML <span>
és un contenidor en línia genèric per a contingut textual, que no representa res essencial. Pot ser utilitzat per agrupar elements amb fins d'estil (utilitzant els atributs class
o id
), o perquè comparteixen valors d'atribut, com lang. S'ha d'utilitzar només quan cap altre element semàntic sigui apropiat. <span>
és molt semblant a un element <div>
, però <div>
és un element a nivell de bloc, mentre que un <span>
és un element en línia.
Categories de contingut | Contingut dinàmic, Contingut textual. |
---|---|
Contingut permès | Contingut textual |
Omissió de l'etiqueta | Cap, tant l'etiqueta inicial com l’etiqueta final són obligatòries |
Elements pares permesos | Qualsevol element que accepti Contingut textual, o qualsevol element que accepti contingut dinàmic. |
Interfície DOM | HTMLSpanElement ( abans d'HTML 5, la interfície era HTMLElement ) |
Atributs
Aquest element només inclou els atributs globals.
Exemple 1
<p><span>Some text</span></p>
Resultat
Some text
Exemple 2
<li><span>
<a href="portfolio.html" target="_blank">See my portfolio</a>
</span></li>
CSS:
li span {
background: gold;
}
Nota
És il·legal col·locar un element a nivell de bloc dins d'un element en línia.
Especificacions
Especificació | Estat | Comentari |
---|---|---|
HTML Living Standard The definition of '<span>' in that specification. |
Living Standard | |
HTML5 The definition of '<span>' in that specification. |
Recommendation | La interfície DOM és ara HTMLSpanElement . |
HTML 4.01 Specification The definition of '<span>' in that specification. |
Recommendation |
Navegadors compatibles
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Característica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Suport bàsic | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Característica | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Suport bàsic | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Veure
- L'element HTML
<div>