5. Images
A web page without images is boring and hard to digest. That's why we're going to learn to insert images with different formats and scenarios.
| Tag | <img> |
|---|---|
| Description | Insert image. |
| Attributes | src: Path of the image.alt: Alternative text if the image isn't loaded, is broken, or is being viewed by a special browser.height: Height of the image in pixels,width: Width of the image in pixels. |
| Type | Inline |
| Tag | <source> |
|---|---|
| Description | Links multimedia content (images, audio and video). |
| Attributes | srcset: Path of the multimedia content.type: Type of content (MIME). |
| Type | Inline |
| Tag | <picture> |
|---|---|
| Description | Container for <source> and <img>. |
| Attributes | Global |
| Type | Block |
| Tag | <figure> |
|---|---|
| Description | Self-representing container for an image, illustration, diagram, code fragment, etc. With the possibility of adding a caption to the image with <figcaption>. |
| Attributes | Global |
| Type | Block |
The supported formats and their recommendations are varied.
- AVIF
- Transparency, wide color range, looping animations and very low weight.
- WEBP
- Transparency, many colors, looping animations and low weight.
- JPEG
- Many colors, medium weight.
- PNG
- Transparency, few colors, medium weight.
- GIF
- Looping animations, few colors, high weight.
- SVG
- Vector, low weight.
Whenever you can, use vector formats such as SVG. They are lighter and adapt to any size without losing quality. And in case you need a bitmap format, such as a photograph, use AVIF.
Single image
<img src="oveja-zombie-blog.svg" alt="Zombie sheep">
Image that is a hyperlink
<a href="#">
<img src="oveja-zombie-blog.svg" alt="Zombie sheep">
</a>
Changing the image depending on the resolution
<picture>
<source srcset="oveja-smartphone.png" media="(max-width: 800px)">
<img src="oveja.png" alt="Sheep">
</picture>
Resize the browser to less than 800px wide and the image will change.
Different image formats
<picture>
<source srcset="logo.avif" type="image/avif">
<img src="logo.jpg" alt="logo">
</picture>
Self-contained with and without caption
Just an image.
<figure>
<img
src="oveja-zombie-blog.svg"
alt="Friendly sheep"
>
</figure>
Image with caption.
<figure>
<img
src="oveja-zombie-blog.svg"
alt="Friendly sheep"
>
<figcaption>Sheep challenging you with its gaze</figcaption>
</figure>
You can download a pack of royalty-free images, in different formats (AVIF, WEBP and JPEG), resized and optimized for web at Place image.
Activity 1
Build the following web page.

Activity 2
Build the following web page.

Activity 3
Build the following web page with several articles invented by you. Try to be as pirate as possible.

Activity 4
Build a website where you describe the steps to cook your best recipe. Accompany it with images and a pinch of parsley.
This work is under a Attribution-NonCommercial-NoDerivatives 4.0 International license.
Desafíos de programación atemporales y multiparadigmáticos
Te encuentras ante un librillo de actividades, divididas en 2 niveles de dificultad. Te enfrentarás a los casos más comunes que te puedes encontrar en pruebas técnicas o aprender conceptos elementales de programación.
Buy the bookWill you buy me a coffee?
This is how I keep writing without ads or paywalls.
Sure, it's on me!
Comments
There are no comments yet.