A mini gallery with links
Make a page with a table of contents at the top (three anchors: Nature, City, Links), two sections with one image and caption each (figure) and a section with two links to external sites that open in a new tab.
A page comes to life when the text gets emphasis, when it links to other pages and when it has images. This lesson covers the elements for formatting text, links (absolute and relative paths, anchors) and images with the required description.
<p><strong>strong</strong> – important text (bold)</p>
<p><em>em</em> – emphasized text (italic)</p>
<p><mark>mark</mark> – highlighted with a marker</p>
<p>H<sub>2</sub>O and x<sup>2</sup> – subscript and superscript</p>
<p><code>code</code> – a piece of code</p>
<blockquote>blockquote – a longer, indented quotation</blockquote>
<p>Special characters: < > & ©</p>
Result:
The browser would take the characters <, > and & as part of the HTML, so they are written as <, >, &.
A link is made with the a (anchor) element, and the address is given with the href attribute:
| Kind | Example | When |
|---|---|---|
| absolute address | <a href="https://developer.mozilla.org">MDN</a> | a link to another site |
| relative address | <a href="contact.html">Contact</a> | a page in the same folder |
| subfolder | <a href="projects/game.html">Game</a> | a file in a subfolder |
| the folder above | <a href="../index.html">Home</a> | .. = one folder up |
| an anchor on the same page | <a href="#hobbies">Hobbies</a> | jumps to the element with id="hobbies" |
<a href="mailto:name@example.com">Write to me</a> | opens the email program |
A link that should open in a new tab gets target="_blank" and, for security, rel="noopener noreferrer". The text of the link should say where it leads: "Competition rules", not "click here".
my_site/
├── index.html ← home page
├── about_me.html
├── contact.html
├── css/
│ └── style.css
└── images/
├── logo.png
└── volleyball.jpg
From index.html an image is referenced as images/logo.png. Write file names in lower case, without spaces and without special letters (my_image.jpg, not My Image.JPG) – servers distinguish upper and lower case, and spaces break addresses.
<img src="https://picsum.photos/id/1025/300/180" alt="A dog wrapped in a blanket" width="300" height="180">
<figure>
<img src="missing.png" alt="This description is shown because the image does not exist" width="200">
<figcaption>Figure 1: figure and figcaption connect an image and its caption</figcaption>
</figure>
Result:
| Attribute | Meaning |
|---|---|
src | the path to the image (relative or absolute) |
alt | a required description: a screen reader for blind users reads it, it is shown when the image cannot be loaded and it helps search engines |
width, height | the dimensions in pixels – the browser knows in advance how much space to leave, so the page does not "jump" while it loads |
loading="lazy" | the image is loaded only when it gets close to the screen |
| Format | What for |
|---|---|
| JPG | photographs |
| PNG | images with a transparent background, screenshots |
| SVG | logos and icons – vector graphics, sharp at any size |
| WebP / AVIF | modern formats – smaller files |
<video src="video/experiment.mp4" controls width="400"></video>
<!-- A YouTube video: on YouTube Share → Embed, then copy the iframe -->
<iframe src="https://www.youtube.com/embed/VIDEO_ID" title="Video title" allowfullscreen></iframe>
The iframe element shows another page inside yours. That is also how the results of the examples are shown on this page.
Each task has an example, a hint and a solution. The solutions have been checked in the browser.
Make a page with a table of contents at the top (three anchors: Nature, City, Links), two sections with one image and caption each (figure) and a section with two links to external sites that open in a new tab.
Logo.PNG ≠ logo.png on a server).alt; if it is only decoration, write it empty: alt="".C:\Users\... work only on your computer – always use relative paths.1. Which attribute gives the address of a link?
2. What is the alt attribute of an image for?
3. What does the path ../index.html mean?
4. Which format is best for a logo that must be sharp at any size?