Skip to content

Help us create more tutorials! Make a donation using the Donate button or become a member using the button below to hide this banner and track your progress.

div element – HTML



To group multiple elements together and style them, use the div element with a class or id attribute:

<div class="my-class">
  <p>The heading element and this paragraph will share similar styles.</p>


As an example, let’s say you had the following rule in your stylesheet:

.my-class {
  background-color: green;

This rule would change the background color of both the heading and the paragraph elements in the code snippet above.


First, recreate the HTML code from the Demo.
Then recreate the CSS code from the Demo.


div element on MDN

Lesson tags: Open Lesson
Back to: CSS Course > CSS HTML Elements