Difference between just using the style attribute or span tag


#1

Hey,
Can anyone help explain what differences between just using the style attribute or using the span tag?


#2

Style is for styling other tags, whereas span is a tag of its own, specifically for styling:

<h1 style="color: red">Red</h1>
<span style="color: red">Red also</span>

You can nest spans in other tags, and use them to style specific words etc. in sentences:

<p style="color: red">red red red <span style="color: blue">BLUE</span> red red red</p>

On their own, without style attributes inside, span tags don't do anything, but with the style attribute they can do a lot.


#3

How is that different? Span allows you to select a bit in a paragraph (and other elements):

<p>i am <span>red</span><p>

then you could add the style attribute to the span tag


#4

Makes so much sense now
Thanks guys!:grinning: