Container elements are used for grouping and styling in HTML. These are particularly useful for breaking down your webpage into sections. They aid in styling by isolating the part that you want the style rule to apply to. For instance, if you wanted a word in a sentence to be a different colour; you would have the sentence inside a paragraph and wrap the word you want to colour in a span element. This span can then be targeted with style rules, which will be covered in the CSS section, resulting in only a colour change to the word wrapped in the span element, not the whole paragraph.
| Element | Description | Common Attributes |
|---|---|---|
<div></div>
|
A division element that encapsulates other page elements and divides a HTML into sections. Typically used for larger sections. | IDs and classes used for styling purposes (covered just down the page). |
<span></span>
|
An inline small container element that takes up the same amount of space as its content. They are used to style or manipulate a specific portion of text. | IDs and classes used for styling purposes (covered just down the page). |