By the end of this lesson, you will be able to:
Make sure you have:
:information_source: HTML Division (
<div>
) is a container element that groups other HTML elements together. Think of it like a box that can hold text, images, and other elements. You can style this box to make your webpage look organized and beautiful!
Here's what you need to know about div elements:
<div>
element helps you organize your webpage content into groups:bulb: Tip Think of a
<div>
like a folder on your computer - it helps you organize things that belong together!
To make your divs look amazing, you can add special attributes:
Attribute | Description |
---|---|
![]() |
ID Attribute: Give ONE specific div a unique name (like giving your pet a name!) |
![]() |
Class Attribute: Give the same name to multiple divs that should look similar |
![]() |
Inline Styling: Add CSS styles directly to your div (quick but not always the best way) |
:memo: Note Remember the difference:
- ID = Unique name for ONE element (use #)
- Class = Shared name for MANY elements (use .)
Divs are super versatile! Here are some common uses:
Let's see how to center an image using a div container:
Block |
---|
![]() |
Output |
![]() |
:bulb: Tip The
text-align: center
style on a div will center everything inside it!
Here's a more complex example showing how divs work together:
:link: Try it yourself: HTML <div>
with CSS layout
Code |
---|
![]() |
Output |
![]() |
Having trouble with your divs? Check these common issues:
My div isn't showing up!
My styling isn't working!
My divs are overlapping!
In this lesson, you learned:
Now it's your turn! Try these challenges:
:memo: Note Pro Tip: Start simple! Create one div first, style it, then add more divs to build your layout step by step.
Remember, divs are the building blocks of modern web layouts. The more you practice, the better you'll get at organizing your web content!