Learn/HTML, CSS & JS/2. Links, images and lists
Lesson 2 of 8
Sign in

HTML, CSS & JS, lesson 2

Links, images and lists

Plain text gets you far, but the web is built on links, and most pages need images and lists too.

Attributes

Some elements need extra information. You give it with attributes inside the opening tag, written as name="value":

<a> is an anchor, the element for links. Its href attribute is where the link goes. The text between the tags is what people click, so make it describe the destination. "Click here" tells nobody anything.

Images

<img> has no closing tag because it has no content. src is the image file, and alt describes the image for people who can't see it (screen readers, slow connections, broken links). Every meaningful image needs a useful alt. A purely decorative image gets .

2 exercises to try what you just read.

Exercise 1

Shopping list

Press Ctrl Enter or Check to test your code.

Exercise 2

A useful link and a described image

Press Ctrl Enter or Check to test your code.

alt=""

Lists

HTML has two common lists:

  • <ul>, an unordered list, for items where order doesn't matter (shown with bullets).
  • <ol>, an ordered list, for steps or rankings (shown with numbers).

Inside either one, each item is an <li>:

Lists can nest: put a whole <ul> inside an <li> to make a sub-list.

Further reading

  • MDN: Creating links
  • MDN: The <img> element
  • MDN: Lists

Make an unordered list with exactly three items: Flour, Milk and Eggs, in that order. Then, below it, add an ordered list with at least two steps of your choice.

Add:

  1. A link with the text Pancake science that points to https://en.wikipedia.org/wiki/Pancake.
  2. An image with src="https://picsum.photos/320/200" and an alt text of at least 10 characters that describes it.
<a href="https://developer.mozilla.org">Read the MDN docs</a>
<img src="pancakes.jpg" alt="A stack of pancakes with berries on top">
<ol>
  <li>Whisk the eggs.</li>
  <li>Add the milk.</li>
</ol>