[Home](https://kaplia.pro/en/) › [Knowledge base](https://kaplia.pro/en/knowledge-base/) › [HTML & CSS — Course for Beginners](https://kaplia.pro/en/html-css/)

# Content Tags

> Learn HTML content tags: h1–h6 headings, paragraphs, lists, images and figure captions, plus the CSS box model — padding, margin, border — and line-height.

- Address: https://kaplia.pro/en/html-css/content-tags/
- Published: 2026-07-20
- Author: [Vitalii Kaplia](https://kaplia.pro/en/author/vitalii-kaplia/)
- Course: [HTML & CSS — Course for Beginners](https://kaplia.pro/en/html-css/)

## Headings: H1 — H6

Headings are the main way to structure information on a page. HTML provides **six levels** of headings: from `<h1>` to `<h6>`. In practice, 3–4 levels are usually enough even for complex pages.

### Rules of use

- `<h1>` — the main heading of the page; there must be **only one** per page. It is intensively indexed by search engines.
- Levels follow in sequence: `h1 → h2 → h3 → h4`. You cannot skip levels (for example, placing `h4` immediately after `h1`).
- Headings of the same level can be repeated as many times as needed.
- Even if the designer did not draw a main heading — still mark up an `<h1>` and hide it visually with CSS.

The heading level is determined by the logical structure of the document, **not** by its visual size. The appearance is set by CSS.

An article about Shevchenko: `<h1>` — "Taras Shevchenko", `<h2>` — "Biography" and "Work", `<h3>` — "Childhood", "Youth", and so on.

## Paragraphs: <p>

The `<p>` (paragraph) tag marks up a fragment of text united by a common meaning. Section or category titles should not be marked up as paragraphs — headings exist for that.

### Important nuances

- The `<p>` tag by itself does not add spacing — spacing is created by the browser's default styles. In a real layout there may be no space at all between paragraphs.
- If a paragraph is whole, keep it on a single line of code (line breaks concern only the width of the editor window).
- The formatting of the opening and closing tags must be uniform: either both on separate lines, or both on the same line as the text.

## Line spacing: line-height

The CSS property `line-height` sets the distance between lines of text.

### Absolute value (in pixels)

```css
p {
  line-height: 24px;
}
```

The line spacing is fixed rigidly. If the font size changes — the spacing stays the same, and the text may look "crammed together" or too spread out.

### Relative value (unitless)

A relative unit is a fraction of the font size. It is written **without** units of measurement:

```css
p {
  line-height: 1.5;
}
```

If `font-size: 16px`, then `line-height: 1.5` = 16 × 1.5 = **24px**.

Calculation formula: `line-height = desired_spacing_px ÷ font-size_px`. For example, 24 ÷ 16 = 1.5.

The advantage of relative units: with any change of font size, `line-height` is recalculated automatically, and visually the amount of "air" between the lines stays proportional.

You can see what value the browser recalculated it to on the **Computed** tab in DevTools.

The default font size for the page is **16px**. If you have not set a `font-size` for an element, it inherits this value.

## Lists: <ol>, <ul>, <li>

List tags are used to mark up enumerations. Each list item is wrapped in a `<li>` (list item) tag.

### Two types of lists

| Tag | Type | When to use |
| --- | --- | --- |
| `<ol>` | Ordered List | The order of items **matters** (steps of instructions, chronology of events) |
| `<ul>` | Unordered List | The order of items **does not matter** (menu items, a list of skills) |

Calling lists "bulleted" and "numbered" is not entirely correct: bullets and numbering are merely styling via CSS. The choice of tag is determined by the *logic* of the enumeration, not by its appearance.

### Nesting rules

- Inside `<ol>` or `<ul>` there can be **only** `<li>` tags — no other tags directly inside the list.
- Inside `<li>` you can use any tags: paragraphs, images, tables, other lists, and so on.
- A nested list is placed **inside** the `<li>` tag of the parent list.

### Styling markers: list-style-type

The CSS property `list-style-type` changes the type of marker or numbering:

```css
ol {
  list-style-type: disc;  /* black dot instead of numbers */
}
```

Popular values: `disc`, `circle`, `square`, `decimal`, `lower-alpha`, `none`. The full list is in the reference [MDN: list-style-type](https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-type).

An ordered list `<ol>` can be styled with markers (dots), and an unordered list `<ul>` — with numbering. The tag defines the semantics, and CSS the appearance.

### Why list semantics matter

Screen readers (programs for the blind) announce the type of list: "ordered list, 5 items" or "unordered list". Correct markup makes the site accessible to all users and raises its position in search results.

## Images: <img>

The `<img>` tag is self-closing (without a closing part) and inserts an image into the page. It has **two required attributes**.

### The src attribute

`src` (source) — the path to the image. It can be absolute (a URL from the internet) or relative (a path to a local file).

```markup
<img src="images/photo.jpg" alt="Image description">
```

A common mistake: writing `scr` instead of `src`. Remember: **s-r-c** (source).

### The alt attribute

`alt` (alternative text) — alternative text. It is needed for three purposes:

1. **If the image fails to load** — the browser shows the text from `alt` instead of the picture.
2. **For search engines** — search engines do not "see" images; they index the value of `alt` and use it in image search.
3. **For screen readers** — blind users hear the description of the image when focus lands on it.

`alt` is **not** a tooltip. For a tooltip, the `title` attribute is used. They should not be identical.

### The title attribute

A universal attribute for any tag. On hover, a tooltip appears. It is useful for icon-based interfaces, where it is not always clear what a button does.

You cannot style `title` with CSS. For a custom tooltip you need JavaScript.

## Image with a caption: <figure> and <figcaption>

If an image has an explanatory caption — use the `<figure>` wrapper and the caption tag `<figcaption>`.

```markup
<figure>
  <img src="photo.jpg" alt="Description">
  <figcaption>Image caption</figcaption>
</figure>
```

### Features

- `<figure>` — a semantic wrapper that tells the browser: here is a media element related to the content (a picture, video, code, etc.).
- Inside `<figure>` there can be only **one** `<figcaption>`.
- `<figcaption>` is optional — it may be absent.
- `<figure>` is **not** a picture. The content image is only `<img>`.
- In the text you should not refer to the position of a figure ("as shown in the figure above"). Instead, use numbered references ("figure 1"), so that the logic is not broken when the block is moved.

If a picture has no caption but directly complements the text — it can still be wrapped in `<figure>`.

## Text wrapping: float

The CSS property `float` makes an element "float" to the left or right edge, while the text wraps around it on the opposite side.

| Value | Effect |
| --- | --- |
| `left` | The element is pushed to the left, the text wraps on the right |
| `right` | The element is pushed to the right, the text wraps on the left |
| `none` | No wrapping (default) |

```css
figure {
  float: left;
}
```

`float` is intended **exclusively** for text wrapping. Do not use it to create page layout (sidebar + content). For layout there are Flexbox and CSS Grid.

If the picture is wrapped in `<figure>` — it is exactly the `figure` (the outermost parent tag) that should be floated.

## Inner spacing: padding

The `padding` property sets the spacing from the boundaries of an element **inward**, toward its content. It is the analog of margins in a document — the distance from the edge of the sheet to the text.

### Longhand properties

| Property | Side |
| --- | --- |
| `padding-top` | Top padding |
| `padding-right` | Right padding |
| `padding-bottom` | Bottom padding |
| `padding-left` | Left padding |

### Shorthand notation

| Notation | Meaning |
| --- | --- |
| `padding: 10px 20px 15px 5px;` | top, right, bottom, left (clockwise) |
| `padding: 10px 20px 15px;` | top, left+right, bottom |
| `padding: 10px 20px;` | top+bottom, left+right |
| `padding: 10px;` | the same on all sides |

**Not setting** a property and **setting it to 0** are different things in CSS. If you do not set it — the element may inherit a value from the browser styles or from other rules.

Use the `padding` shorthand only when you need to set **all four** sides. If you only need some — write the longhand properties (`padding-top`, `padding-left`, etc.).

## Border: border

The border (`border`) is located outside the `padding`. By default it is invisible on all elements, but it is available for styling.

### Three components of a border

| Property | What it sets | Example |
| --- | --- | --- |
| `border-width` | Thickness | `2px` |
| `border-style` | Style | `solid`, `dashed`, `dotted`, `double`, `none` |
| `border-color` | Color | `#ddd`, `red` |

Each of these properties has 4 sub-properties for individual sides (for example, `border-top-width`, `border-left-style`, etc.).

### Shorthand notation

If all 4 sides are the same, use:

```css
figure {
  border: 2px solid #ddd;  /* thickness style color */
  padding: 15px;
}
```

The order in the shorthand: thickness → style → color. It is better not to use fractional thickness values — different browsers may round them differently.

## Outer spacing: margin

The `margin` property sets the spacing **outside** an element. The syntax and shorthand notation are absolutely the same as for `padding`.

```css
figure {
  margin: 0 30px 25px 0;  /* top right bottom left */
}
```

If you need to reset the outer spacing set in the browser styles — write `margin: 0` explicitly, rather than simply not setting it.

### The box model: the big picture

\[box-model\]

In DevTools: blue — content, green — padding, yellow — border, orange — margin.

## Inline markup: <span>

The `<span>` tag is a universal inline container with no semantic meaning of its own. It is used to style individual words or phrases.

**When <span>**

- You need to visually highlight text (bold, italic, color), but it is not emphatic in meaning
- There is no matching semantic tag

**When <strong> / <em>**

- Text needs to be emphasized precisely *by meaning*: this is important information for search engines and screen readers

The `<b>` tag is not recommended for styling. All formatting is done only through CSS. The `<strong>` tag is only for semantic emphasis.

All semantic tags (`<h1>`–`<h6>`, `<p>`, `<ol>`, `<ul>`, `<strong>`, `<figure>`, etc.) serve three purposes: search engines, screen readers, and the readability of the source code.

## New types of selectors

### Selector by tag (already familiar)

```css
p { color: #333; }
```

Applies to **all** elements with that tag.

### Selector by identifier: #id

```markup
<p id="intro">Text</p>

#intro { color: blue; }
```

- The `id` attribute is universal; it can be assigned to any tag.
- The value of `id` must be **unique** on the page — two elements with the same `id` is invalid code.
- In CSS the selector begins with `#` (a hash).

`id` is **not recommended** for styling. It has a very high priority (specificity), which makes it harder to override styles. Identifiers are used mainly for JavaScript and anchor links.

### Selector by class: .class

```markup
<span class="book-name">Kobzar</span>

.book-name { font-weight: bold; }
```

- A class **can be repeated** on an unlimited number of elements.
- In CSS the selector begins with `.` (a dot).
- One element can have **several classes**, listed separated by a space: `class="book-name primary"`.
- Name classes by the purpose of the element, not by its appearance.

Two classes on one element: `<span class="book-name primary">` — will receive styles both from `.book-name` and from `.primary`.

### Comparison of selectors

|  | By tag | By id | By class |
| --- | --- | --- | --- |
| Syntax | `p { }` | `#name { }` | `.name { }` |
| Can repeat | Yes (tags) | No (unique) | Yes |
| Several on an element | — | Only 1 | As many as you like |
| Recommendation | For basic styles | Not for styling | **The main method** |

If two classes set the same property with different values — the rule that comes **later in the CSS file** wins. The order of the classes in the `class` attribute does not matter.

## Code formatting

Follow a consistent formatting style:

- Nested tags must be indented **2 spaces** relative to the parent tag.
- Code editors and sandboxes (CodePen, etc.) have an **auto-formatting** feature — use it before checking.
- The formatting of the opening and closing tags must be consistent.

### Multi-line editing

Two ways to edit several lines at once in the editor:

- **Cmd (Mac) / Ctrl (Windows) + click** — click into the desired lines, and the cursor expands across several lines at once.
- **Alt/Option + drag** — "stretch" the cursor vertically across consecutive lines (rectangular selection).

## Tips for beginners

- **Do not be afraid to ask questions.** There are no stupid questions. Any question leads to understanding.
- **Ask specific questions.** Instead of "I don't understand anything" — "what does this property mean?".
- **Do not copy others' work.** A solution made by another person does not stick in your head.
- **Forget about optimization for the next two years.** Do not save lines of code. If you only need to set 2 paddings — write 2 longhand properties, not the shorthand.
- **Get used to code formatting right away.** All development is built on adhering to style guides.
- **Reach the solution on your own.** A mentor only gently guides with hints — and that is the right approach.

## Summary

What we covered in this lecture:

1. **Headings** `<h1>`–`<h6>` — levels and rules of use
2. **Paragraphs** `<p>` — marking up text fragments
3. **Lists** `<ol>`, `<ul>`, `<li>` — ordered and unordered
4. **Images** `<img>` — the `src`, `alt`, `title` attributes
5. **Image with a caption** `<figure>` + `<figcaption>`
6. **CSS box model properties**: `padding`, `border`, `margin`
7. **line-height** — absolute and relative values
8. **list-style-type** — styling list markers
9. **float** — text wrapping (and only wrapping!)
10. **Selector by id** (`#`) and **selector by class** (`.`)
11. **The <span> tag** — inline text styling with no semantic meaning
