HTML Structure: Practice Questions
Question 1
Count the elements in the HTML below.
<body>
<h1>Groceries</h1>
<ul>
<li>apples</li>
<li>bread</li>
<li>milk</li>
</ul>
<p>Don't forget the <a href="list.html">full list</a>.</p>
</body>How many
<li>elements are there?How many
<ul>elements?How many
<a>elements?How many
<p>elements?How many
<h1>elements?
Answer
3
1
1
1
1
Question 2
Use the HTML below to answer the questions about its structure.
<body>
<div>
<h1>Title</h1>
<p>Some <a href="more.html">text</a> here.</p>
</div>
</body>What is the parent element of the
<h1>?What are the direct children of the
<div>?What is the parent element of the
<a>?Is the
<a>a direct child of the<div>? Explain in a few words.
Answer
the <div>
the <h1> and the <p>
the <p>
No – the <a> is nested inside the <p>, so it is a descendant of the <div> but not a direct child of it.
Question 3
The HTML below has one invalid closing tag.
Which line contains the bug?
What exactly is wrong?
Which tag should replace it?
Answer
Line 5 – the closing </p> tag.
The closing </p> does not match the opening <div> on line 2.
</div>
Question 4
A student wants the word “very” bold and the word “important” both bold and italic, but the tags below are tangled. (<strong> makes text bold; <em> makes it italic.)
<p>This is <strong>very <em>important</strong> text</em>.</p>What is wrong with the way the tags are written?
Mark or briefly describe the changes needed so the tags nest cleanly and the words have the intended formatting.
Answer
The <strong> and <em> tags overlap instead of nesting: <em> opens inside <strong>, but </strong> closes before </em>, so the tags cross each other’s boundaries. Tags must nest, never overlap.
Move </em> to immediately after “important”, before </strong>. Now <em> opens and closes entirely inside <strong>, and ” text” is outside both. Marking this move on the HTML also earns credit.
Question 5
Consider this image element.
<img src="beach.jpg">Which attribute – the one every
<img>should have for accessibility – is missing?Why does that attribute matter? Give one concrete reason.
Write just the missing attribute with a sensible value.
Answer
the alt attribute
alt text is read aloud by a screen reader for a blind reader, and it is shown if the image fails to load; it keeps the page usable by people who cannot see the image.
alt=“a sandy beach at sunset” (any real, descriptive alt text)
Question 6
For each element below, state whether it belongs in the <head> or in the <body> of a page.
<title><h1><p><img><ul>
Answer
head
body
body
body
body
Question 7
Study the nested list below.
<ul>
<li>fruit
<ul>
<li>apple</li>
<li>banana</li>
</ul>
</li>
<li>vegetable</li>
</ul>How many
<ul>elements are there?How many
<li>elements are there in total?Which list items are indented one level deeper, nested inside “fruit”?
Is “vegetable” nested inside “fruit,” or is it a sibling of “fruit” in the outer list?
Answer
2
4 (fruit, apple, banana, vegetable)
apple and banana
It is a sibling of “fruit” in the outer list (it is not nested inside fruit).
Question 8
An attribute is written inside an opening tag as name="value". For each opening tag below, list every attribute’s name and its value separately.
<a href="https://rtealwitter.com">
<img src="cat.jpg" alt="a photo of my cat">Answer
Tag 1 (<a>): name = href, value = https://rtealwitter.com Tag 2 (<img>): name = src, value = cat.jpg name = alt, value = a photo of my cat
Question 9
Consider this link.
<a href="https://cats.com">dogs</a>What text does the reader see and click on?
Where does clicking the link actually send them?
Which attribute controls the destination?
Answer
dogs (the text between the tags)
https://cats.com
the href attribute (The visible text and the href destination are independent of each other.)
Question 10
Answer these questions about the parts of an element.
In
<p>Hello</p>, identify the three parts: the opening tag, the content, and the closing tag. Together, what is the whole thing called?For the paragraph shown, how are its opening and closing tags written differently?
An
<img>has no closing tag. Why not?
Answer
opening tag = <p>, content = Hello, closing tag = </p>; together they form an ELEMENT.
For this paragraph, the closing tag has a slash (/) before the tag name. More generally, an opening tag can also contain attributes, while a closing tag cannot.
<img> is a void element: it cannot contain child content, so HTML defines it without a closing tag. Its attributes identify and describe the image to display.
Question 11
Answer these questions about the standard skeleton every HTML page starts from.
What must the very first line of a modern HTML page be?
The entire document nests inside one element. Which element?
That element has exactly two children. Name both, in order.
Does the first line from part (a) have a closing tag?
Answer
<!DOCTYPE html>
the <html> element
<head> then <body>
No – <!DOCTYPE html> is a declaration, not a normal element, so it has no closing tag.
Question 12
Use the complete page below.
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1>Welcome</h1>
<p>Hello.</p>
<p>Goodbye.</p>
</body>
</html>How many
<p>elements are on the page?How many elements are direct children of the
<html>element?Is the text “My Page” shown on the page itself? If not, where does it appear?
Does
<!DOCTYPE html>count as one of the elements?
Answer
2
2 (the <head> and the <body>)
No – “My Page” is the <title>, which appears in the browser tab (and as the search-engine name), not in the visible page body.
No – <!DOCTYPE html> is a declaration, not an element.
Question 13
A student moved a line into the wrong section of the skeleton.
<!DOCTYPE html>
<html>
<head>
<title>My First Page</title>
<h1>My First Page</h1>
</head>
<body>
<p>Hello, world.</p>
</body>
</html>Which element is in the wrong section, and where does it belong?
The browser may still show the heading anyway. Why is putting it there still a mistake?
Answer
The <h1> is inside the <head>, but it belongs in the <body>.
The <head> is for information ABOUT the page, not for visible content. Putting an <h1> there tells the browser something false about the page; even though the browser is forgiving and may still render it, that “lie” starts to cost you once CSS and search engines enter the picture.