Attributes, links and images
Learn
Attributes add details
Tags say what something is. Attributes add the details: where a link goes, which picture to show. They live inside the opening tag, as name="value":
<a href="https://example.com/tickets">Buy tickets</a>Here a is the element (a link, short for "anchor"), href is the attribute, and the text between the tags is what people click. Attribute values go in quotes. Forget a closing quote and the browser keeps reading until it finds one, swallowing whatever text sits in between.
Learn
Where a link goes
An href can be:
- absolute: a full address with
https://, for another site - relative: a path on this site, like
/web/orabout.html #gigs: a jump to the element withid="gigs"on the same page
Link text should make sense on its own. "Buy tickets" tells you where you are going; "click here" does not, and people using a screen reader often jump from link to link hearing only the text.
Learn
Images need alt text
An image is one tag with no closing tag:
<img src="/assets/noodle/happy.svg" alt="Noodle waving" width="120">src is where the picture lives. alt is the text read aloud by screen readers and shown if the picture fails to load, so describe what the picture shows or does. width sets the size in pixels; give only one of width or height and the picture keeps its shape.
Try
Run it: a band page
Press Run and the page appears in the preview under the editor. Change some text or a colour and run it again.
<h1>The Paper Planes</h1> <img src="/assets/noodle/happy.svg" alt="The band's mascot, a blue noodle, waving" width="120"> <p>Indie pop from Leeds. New single out Friday.</p> <ul> <li><a href="https://example.com/tickets">Buy tickets</a></li> <li><a href="#gigs">Jump to the gig list</a></li> </ul> <h2 id="gigs">Gigs</h2> <p>12 March, Brudenell Social Club</p>
Practice
Link to the lyrics
Turn the words Read the lyrics into a link that goes to https://example.com/lyrics.
<h2>Neon Rain</h2> <p>Read the lyrics</p>
Practice
An image people can hear
Add an image of Noodle under the heading. Its file is /assets/noodle/celebrating.svg. Make it 150 pixels wide and give it alt text that says what it shows (more than one word, and not just "image").
<h2>We won the school music prize</h2> <p>Thanks to everyone who voted.</p>
Break/fixFix the bug
A picture that never appears
The gig poster should show Noodle's happy face, but the page shows only the alt text (or nothing). Fix the image tag.
<h2>Gig poster</h2> <img scr="/assets/noodle/happy.svg" alt="Noodle smiling" width="120">
Your turn
An album card that links out
Build a card for the album Night Swim from nothing:
- an
h2with the album name - the cover,
/assets/noodle/curious.svg, 200 pixels wide, with alt text that describes it - a link with the text
Listen on the band's sitethat goes tohttps://example.com/night-swim - a link with the text
Skip to the track listthat jumps to anh3further down with the idtracks
On your own. Hints open after your first check.
Passed
You can now