Lesson 3 ยท about 15 minutes
๐ผ๏ธ More Bricks: Headings, Lists & Pictures
Your page has walls now. Today you get THREE new LEGO bricks โ and one brand-new superpower that makes pictures possible.
๐ฌ Watch first (90 seconds)
Headings come in sizes
You already know <h1>, the giant headline. But there's a whole family: <h1> down to <h6>. They are sizes of importance, like a book:
<h1>= the book title. One per page. The boss.<h2>= a chapter title. Use these for the big parts of your page.<h3>= a section inside a chapter. Smaller again.- โฆall the way down to tiny
<h6>(almost nobody uses that one!).
Bricks INSIDE bricks: lists
Here's a cool trick โ LEGO bricks can go inside other bricks. That's called nesting. A list is a big brick (<ul>, "unordered list") holding little bricks (<li>, "list item") inside it:
<ul>
<li>Never melts</li>
<li>Tastes like rainbows</li>
<li>Glows in the dark</li>
</ul>
The browser draws a bullet point (โข) before each item. Swap <ul> for <ol> ("ordered list") and the browser numbers them for you โ 1, 2, 3 โ perfect for top-3 lists or recipes.
One more mini-brick: wrap important words in <strong> and the browser makes them bold. It means "this bit really matters!"
The new superpower: attributes
<img src="photo.jpg" alt="a red sneaker">
src says WHICH picture to show. alt describes the picture for people who can't see it (and it shows up if the picture breaks). And notice: <img> has NO closing tag โ it's a special self-contained brick. Nothing goes inside a picture, so it doesn't need one!
The pattern is always the same: name="value", with quotes around the value. You'll meet lots more attributes soon โ this is a big deal!
๐ ๏ธ Build it (the fun part)
- Open
practice/myshop.htmlin VS Code (the page you built in lessons 1 and 2). - Inside
<body>, under your paragraphs, add a chapter heading:<h2>Why it's awesome</h2> - Under it, add a bullet list with 3 features of YOUR product (type it, don't copy!):
<ul> <li>Ties itself in 2 seconds</li> <li>Never gets smelly</li> <li>Comes in <strong>glow-in-the-dark</strong> green</li> </ul> - Now the picture! Add this line (it's a free placeholder photo from the internet):
Change the<img src="https://picsum.photos/300/200" alt="a photo of my product">altwords to describe YOUR product. - Save (โS), then refresh your browser (โR). Bullet points AND a photo. Your page is starting to look like a real shop! ๐
๐น๏ธ Try it right here โ the lesson checks your code!
Type in the dark box, watch the preview update live, then press Check my code โ.
๐จ Now break it!
Time to break things on purpose in myshop.html. Predict what will happen BEFORE you refresh!
- Change
<ul>and</ul>to<ol>and</ol>. Save, refresh. Numbers! Change it back (unless you like it). - Break the picture on purpose: change the
srcto"https://picsum.photos/oops". Save, refresh. You'll see a broken-picture icon and your alt text โ THAT is exactly whataltis for! Fix the src again. - Change your
<h2>to<h6>. Save, refresh. See how tiny? Now you know why chapter titles use h2. Put it back.
src="...". Also check there's a space between img, src, and alt. And remember: save FIRST, then refresh.
๐ฎ Quiz time
No peeking at the notes above โ trying to remember is what makes it stick!
๐ Want more?
<img>, src and alt, with extra tricks like picture sizes. Reading it counts as a lesson block!