HTML Fundamentals

Session 2 — HTML Elements, Attributes, Links, and Images

🎯 Session Overview

Welcome to Session 2! In our first session, we built the basic skeleton of a web page using <html>, <head>, and <body> tags.

Today, we are going to add the meat and muscles to that skeleton! By the end of this session, you will learn how to:

⏪ Quick Recap: Session 1

Let's do a fast memory check. What did we learn last time?

Now, let's learn exactly how the tags inside the <body> work!

🧱 What is an HTML Element?

An HTML Element is a single piece of content on a web page. Think of elements as Lego bricks. You stack them together to build a house (a website!).

Most elements have three distinct parts:

  1. An Opening Tag: Tells the browser where the element begins.
  2. The Content: The actual text or stuff you want to show on the screen.
  3. A Closing Tag: Tells the browser where the element ends (notice the forward slash /).
<h1> Hello World </h1> Opening Tag Content Closing Tag

If you forget the closing tag, the browser gets confused, and your whole page might look like a giant, messy block of text!

⚙️ What is an HTML Attribute?

Sometimes, an opening tag needs a little extra instructions to do its job. We provide this extra info using an Attribute.

Imagine your HTML element is a person. The tag says "I am a person". The attribute says "I am wearing a blue shirt".

Attributes are always written inside the opening tag. They consist of an attribute name and an attribute value surrounded by quotation marks.

< tag attribute_name = "value" > Content </ tag > Attribute Name Attribute Value

Common Attributes We Will Use Today:

📝 Headings and Paragraphs

Every good article, game review, or blog needs titles and readable text. HTML gives us 6 levels of headings to organize our content, from <h1> (the biggest) down to <h6> (the smallest).

For your normal, everyday sentences, we use the paragraph element: <p>. Paragraphs automatically add space above and below the text so it isn't clustered together.

This is an <h1> This is an <h2> This is an <h3> This is an <h4> This is an <h5> This is an <h6>
<h1>Minecraft Review</h1>
<h2>Why I love this game</h2>

<p>Minecraft is an amazing game where you can build anything you imagine using blocks. I like playing in survival mode with my friends.</p>

Line 1: <h1> creates the main, largest title on the page. Only use one of these per page!

Line 2: <h2> creates a sub-title. It's slightly smaller. Good for dividing your page into sections!

Line 4: <p> creates a block of text. When you close it with </p>, the browser knows the paragraph is finished.

🔗 Adding Links

The "Web" is called a web because all the pages are connected together! We connect pages using the Anchor element, written as <a>.

But an anchor tag alone is useless. It needs to know where to take you when you click it. We tell it where to go using the href attribute (which stands for Hypertext REFerence).

<a href= "https://google.com" > Open Google </a> Tag Attribute Destination URL Clickable Text
<p>Want to learn more?</p>
<a href="https://www.google.com" target="_blank">Search on Google</a>

🖼️ Inserting Images

A website without pictures is pretty boring! To add an image, we use the <img> element.

Important Rule: The <img> tag is what we call an "empty element" or "self-closing tag". Because it doesn't wrap around any text, it does not have a closing tag!

The image tag relies entirely on attributes to work:

<h3>My Pet Dog</h3>

<!-- Adding an image of a dog -->
<img src="dog.jpg" alt="A happy golden retriever" width="400">

<img: Opens the image tag.

src="dog.jpg": The "Source" attribute. This tells the browser the file name (or URL) of the picture to display.

alt="A happy golden retriever": "Alternative text". If the picture fails to load, this text shows up instead. It is also read aloud by screen readers for blind users. Always include this!

width="400": Forces the image to be exactly 400 pixels wide, preventing giant images from breaking your layout.

>: Closes the tag. Notice there is no </img> at the end!

🧩 Putting It All Together

Here is what a simple web page looks like when we combine Headings, Paragraphs, Links, and Images into the <body>!

My Favorite Game

Minecraft

Minecraft is a game made of blocks where you can build anything you can imagine!

[Image of Game]
Visit Official Website

🏋️ Practice Exercises

Open your code editor. Create a new file called practice2.html and try these challenges!

Exercise 1: Title and Story

Create a basic HTML structure. Inside the <body>, add a main heading (<h1>) that says "My Favorite Game". Below it, write a short paragraph describing why you love the game.

Use <h1>Your Title</h1> for the heading, and <p>Your description here.</p> for the paragraph!

Exercise 2: Picture Perfect

Find an image URL of your game online. (Right-click an image on Google -> "Copy Image Address"). Add the image right below your paragraph using the <img> tag.

<img src="paste_your_url_here" alt="Game cover" width="300">

Exercise 3: The Portal

Add a link at the very bottom of your page that takes the user to the official website or wiki of the game.

<a href="https://minecraft.net" target="_blank">Play Here</a>

🔥 Mini Challenge: The Ultimate Game Page

Let's make sure you can put all the pieces together from memory.

Delete everything inside the <body> of your practice file. Create a complete page from scratch containing:

  1. An <h1> with the game name.
  2. An <h2> that says "Why I love it".
  3. A <p> describing the game.
  4. An <img> showing the game cover.
  5. An <a> link pointing to the game's official site.
<body>
  <h1>Roblox</h1>
  <h2>Why I love it</h2>
  <p>I can play thousands of different games with my friends!</p>
  
  <img src="roblox-logo.jpg" alt="Roblox Logo" width="300">
<a href="https://roblox.com">Play Now</a> </body>

🏠 Homework Assignment

Your mission before the next session:

Create a webpage about your Favorite Hobby (sports, drawing, coding, reading, etc.).

The page must include:

Save it as hobby.html and test it in your browser to make sure the link and image actually work!

📝 Session Summary

⬅ Previous Session Next Session ➡