Fall 2026
  • Discord
  • Gradescope
  • Syllabus

On this page

  • Question 1
  • Question 2
  • Question 3
  • Question 4
  • Question 5
  • Question 6
  • Question 7
  • Question 8
  • Question 9
  • Question 10
  • Question 11
  • Question 12
  • Question 13
  • Question 14
  • Question 15
  • Question 16
  • Question 17
  • Question 18
  • Question 19
  • Question 20
  • Question 21
  • Question 22
  • Question 23
  • Question 24
  • Question 25
  • Question 26
  • Question 27
  • Question 28
  • Question 29
  • Question 30
  • Question 31
  • Question 32

HTML Structure: Practice Questions

Question 1

You change a paragraph in VS Code, reload the browser, and still see the old words. The editor tab has an unsaved-change dot. What step is missing, and why does it matter?

Answer

Save the file, then reload the browser. The browser reads the file on disk; the new words are still only in the editor until they are saved.

Question 2

In <p>Hello</p>, identify the opening tag, content, and closing tag. What is the whole unit called? Why is img different?

Answer

Opening tag: <p>; content: Hello; closing tag: </p>. Together they form one element. An img is a void element, so it has an opening tag but no child content or closing tag.

Question 3

How many elements does this fragment contain? Explain why counting every tag gives a different number.

<h2>Opening Hours</h2>
<p>Tuesday through Sunday.</p>
Answer

Two elements: one h2 and one p. Each opening/closing pair belongs to one element, so the four tags do not mean four elements.

Question 4

A page needs a main heading “Workshop”, a section heading “Materials”, and a paragraph “Bring a pencil.” Write those three elements in that order.

Answer

<h1>Workshop</h1> <h2>Materials</h2> <p>Bring a pencil.</p>

Question 5

Write an unordered list with two separate items: “paper” and “pencil”. Make each item a child of the list.

Answer

<ul> <li>paper</li> <li>pencil</li> </ul>

Question 6

Choose an ordered or unordered list for each situation and explain the difference: steps to reset a password; ingredients to buy.

Answer

Use ol for password-reset steps because their sequence matters. Use ul for ingredients because the items are a group without a required sequence. Both use li for their items.

Question 7

Will the line break in this source create two displayed paragraphs? Rewrite it so there are two paragraphs.

<p>Doors open at six.
The talk starts at seven.</p>
Answer

No. Ordinary whitespace collapses to a space within the paragraph. Use: <p>Doors open at six.</p> <p>The talk starts at seven.</p>

Question 8

Indent this fragment so its nesting is easy to see. Does adding that indentation change which elements are children of the list?

<ul><li>red</li><li>blue</li></ul>
Answer

<ul> <li>red</li> <li>blue</li> </ul> No. The tags determine the nesting; indentation makes it easier to read.

Question 9

Count the li, ul, p, and h1 elements.

<div>
    <h1>Groceries</h1>
    <ul>
        <li>apples</li>
        <li>bread</li>
        <li>milk</li>
    </ul>
    <p>Bring a shopping bag.</p>
</div>
Answer

li: 3; ul: 1; p: 1; h1: 1. Each opening and closing pair is one element.

Question 10

Which line has a closing tag that does not match the element it should close? Write the corrected tag.

<div>
    <div>
        <p>The quick brown fox</p>
        <p>jumps over the lazy dog.</p>
    </p>
</div>
Answer

Line 5 should be </div>. That closes the div opened on line 2; the paragraphs already closed on lines 3 and 4.

Question 11

Repair the nesting. Only “important” should be emphasized, and “very important” should be strong.

<p>This is <strong>very <em>important</strong> text</em>.</p>
Answer

Move </em> immediately after important, before </strong>: <p>This is <strong>very <em>important</em></strong> text.</p>

Question 12

Name the parent of the h1, the two direct children of the div, and the parent of the strong. Is strong a direct child of div?

<div>
    <h1>Notice</h1>
    <p>Bring <strong>water</strong>.</p>
</div>
Answer

The h1’s parent is div. The div’s direct children are h1 and p. The strong element’s parent is p. It is a descendant of div, but not a direct child.

Question 13

How many lists and list items are there? Which items are nested inside “fruit”? Is “vegetable” a child or a sibling of the outer “fruit” item?

<ul>
    <li>fruit
        <ul>
            <li>apple</li>
            <li>banana</li>
        </ul>
    </li>
    <li>vegetable</li>
</ul>
Answer

There are 2 ul elements and 4 li elements. Apple and banana are in the list inside fruit. Vegetable and fruit are sibling list items in the outer list.

Question 14

Are the two p elements siblings? Name each one’s parent and their shared ancestor.

<div>
    <div><p>Morning</p></div>
    <p>Evening</p>
</div>
Answer

No. The first p has the inner div as its parent; the second p has the outer div as its parent. Their shared ancestor is the outer div.

Question 15

Write HTML with this element tree. Use “Supplies” for the heading and “rope” and “torch” for the items.

div
  h2
  ul
    li
    li
Answer

<div> <h2>Supplies</h2> <ul> <li>rope</li> <li>torch</li> </ul> </div>

Question 16

Move the last list item into the existing list without changing its text. After the move, what is its parent, and which element is its sibling?

<ul>
    <li>First</li>
</ul>
<li>Second</li>
Answer

Move <li>Second</li> before </ul>: <ul> <li>First</li> <li>Second</li> </ul> Its parent is ul, and the First li is its sibling.

Question 17

Write the first line of a modern HTML document. Name its outer element and that element’s two direct children, in order. Is the first line itself an element?

Answer

First line: <!DOCTYPE html>. Outer element: html. Direct children: head followed by body. The first line is a declaration, not an element.

Question 18

Place each element in either the head or the body: title, h1, p, img, and ul.

Answer

head: title. body: h1, p, img, ul. The head describes the page; the body contains its visible content.

Question 19

How many paragraphs are there? Name the two direct children of html. What appears in the browser tab, and what is the heading inside the page?

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>My Page</title>
    </head>
    <body>
        <h1>Welcome</h1>
        <p>Hello.</p>
        <p>Goodbye.</p>
    </body>
</html>
Answer

Two paragraphs. The html children are head and body. The tab says My Page, and the page heading is Welcome.

Question 20

Which element is in the wrong section? Move it to the right place. Why is seeing a heading in the browser not enough to establish that the HTML structure is correct?

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>My First Page</title>
        <h1>My First Page</h1>
    </head>
    <body>
        <p>Hello, world.</p>
    </body>
</html>
Answer

Move <h1>My First Page</h1> from head into body. A browser may repair invalid HTML while displaying it, so the result can look right even when the source structure is wrong. A validator checks the source structure.

Question 21

List each attribute’s name and value. Do not include the tag names.

<a href="https://example.com">
<img src="cat.jpg" alt="A cat asleep on a chair">
Answer

href = https://example.com; src = cat.jpg; alt = A cat asleep on a chair.

Question 22

What text is clickable? Where does clicking it lead? Which part would you change to make it open dogs.html while keeping the visible text?

<a href="cats.html">dogs</a>
Answer

The clickable text is dogs. It opens cats.html. Change href=“cats.html” to href=“dogs.html”; leave the content between the tags unchanged.

Question 23

Change only what visitors click so the link reads “Read the guide”. Keep its destination unchanged.

<a href="guide.html">Click here</a>
Answer

<a href=“guide.html”>Read the guide</a>

Question 24

Write a link whose visible text is “Museum hours” and whose destination is https://example.com/visit.

Answer

<a href=“https://example.com/visit”>Museum hours</a>

Question 25

The image shows a sandy beach at sunset. Add the missing accessibility attribute and explain who it helps.

<img src="beach.jpg">
Answer

alt=“A sandy beach at sunset”. The text gives the image’s information to someone using a screen reader and can appear when the image cannot load.

Question 26

From index.html, write an image element that loads the photo shown in this folder. Its description should be “A red kite in flight”.

site/
    index.html
    images/
        kite.jpg
Answer

<img src=“images/kite.jpg” alt=“A red kite in flight”>

Question 27

This is meant to be a link to another page. Fix the attribute and remove the attribute from the closing tag.

<a src="schedule.html">Schedule</a src="schedule.html">
Answer

<a href=“schedule.html”>Schedule</a> Links use href for their destination. Attributes belong in the opening tag, not the closing tag.

Question 28

The picture file moves from beside index.html into a folder named photos. Update this element. Does its description need to change?

<img src="owl.jpg" alt="An owl perched on a branch">
Answer

<img src=“photos/owl.jpg” alt=“An owl perched on a branch”> Only src changes. Moving the file does not change what the image shows.

Question 29

Which file supplies the picture, and which file opens when it is clicked? Change the destination to booking.html without changing the picture.

<a href="tour.html"><img src="room.jpg" alt="Tour the room"></a>
Answer

room.jpg supplies the picture. tour.html is the destination. Change href to booking.html: <a href=“booking.html”><img src=“room.jpg” alt=“Book a room tour”></a> The alt text can also be updated to describe the new link purpose.

Question 30

You want the browser tab to say “City Museum” and the visible main heading to say “Opening Hours”. Write the two elements, and say which belongs in head and which in body.

Answer

Put <title>City Museum</title> in head. Put <h1>Opening Hours</h1> in body. The tab title and visible heading are separate elements.

Question 31

A teammate receives your page’s file: address but cannot open it on their own computer. Why? What must happen for them to visit it through an https: address?

Answer

The file: address points to a location on your computer; it does not publish the files. Put the site files on a web server, then share the https: address where that server makes the page available.

Question 32

The file images/map.png is a map of the park. The following fragment has two problems: the paragraph should be visible page content, and the image should load from that file. Describe both fixes and add useful alternative text.

<head>
    <title>Park Walk</title>
    <p>Meet at the north gate.</p>
</head>
<body>
    <h1>Saturday Walk</h1>
    <img src="map.png">
</body>
Answer

Move <p>Meet at the north gate.</p> from head into body. Change the image to <img src=“images/map.png” alt=“Map of the park”>. The title remains in head.