HTML tags are supposed to give meaning to the content inside, but not in the case with
id attribute to them.
div tag represents a generic container. The reason why it is a container is because it defaults to a block. As a block, it starts on its own new line, similar to how
p tags work.
<!DOCTYPE html> <html> <head> <title>Div</title> </head> <body> <div>Division 1</div> <div>Division 2</div> <div>Division 3</div> </body> </html>
span tag accomplishes the same thing as a
div tag except that it is inline, which essentially means that it wraps content but remains inside the same line, and does not start on its own line.
This means you can do something like this:
<!DOCTYPE html> <html> <head> <title>Span</title> </head> <body> <p>The <span class="space">Solar System</span> is a cool place.</p> </body> </html>
You can now apply styles to your
space class and it will only affect the text "Solar System". Pretty cool, huh?
In general, these tags should be used as rarely as possible, as they do not describe the content inside them at all. Whenever possible, and when it makes sense, use alternative tags to give meaning to the content between the tags.
In our next lesson, we'll explore the opposite of these tags, and take advantage of the more semantic tags!