From the course: Crafting Meaningful HTML

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

When to use div and span elements

When to use div and span elements - HTML Tutorial

From the course: Crafting Meaningful HTML

Start my 1-month free trial

When to use div and span elements

- (Narrator) Div and span, have no semantic meaning by themselves. Although it seems like everyone turns to these elements as some of their first choices in marking up a document. Div and span should be used, only when there's no other element available to convey meaning, or when the purpose of the element, is to hold a CSS class or in some way to group together other elements on a page. So let's see some examples of that in action. So once again, here I am in code pen. And I've given you a very simple example, here we have three paragraphs, there they are. We also have a little bit of CSS down here. I've already put in some classes for a class of warning, which will give things a red background with white letters. Also created a class of bold and a class of italic. So for example, let's just say that these three paragraphs are some kind of warning that we want to draw attention to on our web page. And we want to do that, making them red backgrounds, and white letters and so forth…

Contents