HTML elements for structuring content and their correct use
2. Seznamy (<ul>, <ol>, <dl>)
Lists are used to organize items into a clear format. There are three main types:
Unordered list (<ul>)
Used when order doesn't matter. Each item is inside a <li>.
In browser:
- Apples
- Bananas
- Pears
Ordered list (<ol>)
Used when order plays a role. Items are numbered.
In browser:
- Preheat oven to 180°C
- Prepare the dough
- Bake for 20 minutes
Descriptive list (<dl>)
It is used to define terms and explain them.
In browser:
HTML
HyperText Markup Language – slouží ke stylování webových stránek
CSS
Cascading Style Sheets – used for styling web pages
3. Images (<img>)
The <img> tag is used to insert images. It must have a src attribute (the source of the file) and it is advisable to add alt (alternative text for screen readers and in case of missing images).
Correct use of images:
✅ Use relevant images - Don't add images just for the sake of appearance, but where they have informational value.
✅ Fill in the alt attribute - Important for accessibility and SEO.
✅ Use the right formats - e.g. .jpg for photos, .png for transparent images, .webp for better compression.
4. Multimedia container - <figure>
The <figure> element is used for better formatting of images, graphs or tables. It can be combined with <figcaption> to add a caption.
Benefits of using <figure>:
✅ Helps with logical organization of content.
✅ Allows you to add a label without having to use <p>.
✅ It gives us a wrapping element that allows us to manipulate the width and height of the image without distorting it.
5. Tables (<table>)
Tables are used to organize data in rows and columns. The structure of a table includes:
<table>- wrapper element<tr>- table row<th>- header cell (bold)<td>- regular cell
Browser output:
| Name | Age |
|---|---|
| Petr | 25 |
| Anna | 30 |
Proper use of tables:
✅ Use for data, not for layout!
✅ Add <th> for the header - makes the table easier to read.
1. Block vs. line elements
Before we look at individual tags, it's good to understand the difference between block and line elements:
| Element type | Behavior |
|---|---|
| Block elements | They take up the entire width, starting on a new line (e.g. <div>, <section>, <p>). |
| Line elements | They only take up as much space as needed and continue on the same line (e. g. <span>, <a>, <strong>). |
2. <div> - universal block container
The <div> tag is used as a container for grouping other HTML elements. It is mainly used for CSS styling or JavaScript manipulation.
✅ Using divs to group content:
📌 When to use <div>?
- If you want to group elements for styling.
- If you need to create a page layout.
- Unless you have a more appropriate semantic tag (e.g.
<section>).
🚫 When to avoid <div>?
- If there is a semantically more appropriate element (e.g.
<header>,<section>or<article>).
3. <span> - universal line container
Unlike <div>, <span> is a line element. It is used to highlight a section of text or apply styles to specific words.
✅ Using span to style a section of text:
<p>Our shop offers <span class="discout">20% discout</span> for all products.</p>
📌 When to use <span>?
- If you want to edit only part of the text inside another element.
- If you need to change the color, font or style of specific words.
🚫 When to avoid <span>?
- If you can use a semantic tag like
<strong>or<em>.
4. <section> - thematic content section
The <section> element groups related content, usually with a heading. Unlike <div>, it has semantic value and tells search engines and assistive technologies that a given block forms a separate section of content.
✅ Use section to logically separate parts of a page:
- If a piece of content has an independent meaning.
- If it contains a title (
<h2>,<h3>, ...). - If you want to better structure the content of the page.
🚫 When to avoid <section>?
- Unless the section has its own topic or title (in which case it is better to use
<div>).
Comparison: when to use <div>, <span> and <section>?
| Element | Type | Usage | Example |
|---|---|---|---|
<div> |
Block | Universal container, grouping of elements | <div class="box">Content</div> |
<span> |
Line | Highlighting part of the text | <span style="color: red;">Red text</span> |
<section> |
Block | Thematically related content | <section><h2>Title</h2></section> |
Summary
Proper use of HTML elements helps the clarity and accessibility of the page.
🔹 Headings – Use logically, only one <h1>.
🔹 Lists– Unordered (<ul>) for lists, ordered (<ol>) for steps, descriptive (<dl>) for definitions.
🔹 Images– Always add alt and use the correct formats.
🔹 Figures – Helps with the correct placement of images and captions.
🔹 Tables – Use only for data, not for page layout.
🔹 <div> is a universal block element, but should only be used when there is no more appropriate semantic tag.
🔹 <span> is ideal for styling parts of text, but should not be used excessively.
🔹 <section> helps organize web content into logical units, improving readability and SEO.
Following these rules will ensure that your website is well structured, clear and accessible to all users. We may also encounter other tags