The HTML Span Tag is useful for applying custom styles to inline elements. It is a generic inline container for various inline elements. Under the span tag container, you can set the style and then implement them to different elements.
There are two ways in which you can use the HTML Span tag. In a first way, you can declare the styling in a different place under the <style> tag. Then to use the style in elements simply put them under <span> </span> tags.
For example:
HELLO EARTH!
This effect is due to the span Follow for more Interesting articles!
OUTPUT:-
HELLO EARTH
This effect is due to the span
Follow for more
Interesting articles!
In a second way, you can define the inline style under the span tag. The syntax will be:
Text goes here
Let’s understand it better by looking at this example.
HELLO EARTH
First Text Second Text
OUTPUT :-
First Text
Second Text
Difference between HTML Span tag and Div tag
The Span HTML tag and Div HTML tag have a very handsome difference in them. First of all tag is inline element whereas <div> tag is block-level element. However, both tags don’t require attributes with common CSS and class. Span tag takes only required width whereas the Div tag takes the whole width which is available.
Use Mettl to automate your Coding Assessment Test.
More Articles: