HTML Practice Quiz.

Thirty HTML questions in three levels. Pick an answer and see at once whether you were right, and why.

  • 30 questions
  • 3 levels
  • No sign-in
  • Checked in Chrome
0 day streakBest –
HTML

<!-- No markup for this one. Think it through. -->

1 / 10

Where does the <title> element belong?

0 correct

Your score and streak are saved in this browser. No account needed.

All 30 HTML questions and answers

Prefer to read? Open any question to see the code, the answer and the reason behind it.

Basics

Tags, text and attributes
1Page structureWhere does the <title> element belong?

Where does the <title> element belong?

  1. AInside <body>
  2. BBefore <html>
  3. CInside <head>
  4. DInside <header>

Answer: C. The head holds information about the page: its title, character set, styles and scripts. The title shows in the browser tab and in search results, not in the page itself.

2HeadingsWhich element marks the most important heading on a page?

Which element marks the most important heading on a page?

  1. A<h1>
  2. B<h6>
  3. C<header>
  4. D<title>

Answer: A. Headings run from h1 (most important) down to h6. header is a container for introductory content, and title names the document in the browser tab.

3Links<a href="https://example.com" target="_blank">Docs</a>

What does target="_blank" do here?

<a href="https://example.com" target="_blank">Docs</a>
  1. ADownloads the page
  2. BMakes the link text bold
  3. COpens the link in the same tab
  4. DOpens the link in a new tab or window

Answer: D. target names where the link opens. _blank means a new browsing context, which browsers show as a new tab. Without it, the link opens in the current tab.

4Images<img src="team.jpg" alt="Five people around a desk">

What is the alt attribute for?

<img src="team.jpg" alt="Five people around a desk">
  1. AA tooltip shown on hover
  2. BText used when the image cannot be seen
  3. CA caption shown under the image
  4. DThe name of the image file

Answer: B. alt is the text alternative: screen readers read it out, and browsers show it if the image fails to load. The hover tooltip comes from the title attribute, and captions use figcaption.

5Lists</ol>

How does a browser show this list?

<ol>  <li>Tea</li>  <li>Milk</li></ol>
  1. ANumbered: 1. Tea, 2. Milk
  2. BWith bullet points
  3. COn one line, separated by commas
  4. DAs a table with two rows

Answer: A. ol is an ordered list, so each item gets a number. ul is the unordered list and shows bullet points.

6Void elementsWhich of these elements never has a closing tag?

Which of these elements never has a closing tag?

  1. A<p>
  2. B<div>
  3. C<br>
  4. D<span>

Answer: C. br is a void element: it cannot have content, so there is nothing to close. img, input, hr and meta are void elements too.

7id and classHow many elements on one page may share the same id?

How many elements on one page may share the same id?

  1. AAny number
  2. BOne. An id must be unique
  3. CTwo
  4. DIt depends on the tag

Answer: B. An id identifies a single element. Links to #id, label for and getElementById all rely on that. Use class when several elements belong together.

8CommentsWhich of these is an HTML comment?

Which of these is an HTML comment?

  1. A// note
  2. B# note
  3. C/* note */
  4. D<!-- note -->

Answer: D. HTML comments start with <!-- and end with -->. The other forms are comments in JavaScript, CSS and Python, and a browser would show them as text in a page.

9Character references<p>5 &lt; 10 &amp;&amp; 10 &gt; 5</p>

What text does the browser show?

<p>5 &lt; 10 &amp;&amp; 10 &gt; 5</p>
  1. A5 &lt; 10 &amp;&amp; 10 &gt; 5
  2. B5 10 10 5
  3. C5 < 10 && 10 > 5
  4. DNothing

Answer: C. &lt; &gt; and &amp; are character references for <, > and &. They let you show characters that would otherwise be read as the start of a tag or of another reference.

10White space again</p>

How is this text displayed?

<p>Hello      world   again</p>
  1. AHello world again, on one line with single spaces
  2. BWith every space and the line break kept
  3. CHelloworldagain
  4. DThe browser shows an error

Answer: A. Browsers collapse any run of spaces, tabs and line breaks in normal text into one space. Use br for a line break, or pre when the spacing matters.

Core

Forms, tables and structure
11Labels<input id="email" type="email">

What does the for attribute do?

<label for="email">Email</label><input id="email" type="email">
  1. ASets the placeholder text
  2. BSubmits the form
  3. CChecks that the email is valid
  4. DTies the label to the input with that id

Answer: D. for holds the id of the field the label describes. Clicking the label then focuses the field, and screen readers announce the label when the field is reached.

12Form data</form>

Which values are sent when this form is submitted?

<form>  <input name="q" value="cats">  <input id="page" value="2">  <button>Go</button></form>
  1. Aq=cats and page=2
  2. BOnly q=cats
  3. COnly page=2
  4. DNothing

Answer: B. A field is sent under its name. The second input has an id but no name, so it is left out. id is for the page; name is for the server.

13Buttons in forms</form>

What happens when this button is clicked?

<form action="/save">  <input name="title">  <button>Save</button></form>
  1. ANothing. A button needs type="submit"
  2. BThe browser shows an error
  3. CThe form fields are cleared
  4. DThe form is submitted

Answer: D. Inside a form, a button with no type is a submit button. Write type="button" when a button should only run your JavaScript and not send the form.

14Semantic elementsWhich element is meant for a block of main navigation links?

Which element is meant for a block of main navigation links?

  1. A<nav>
  2. B<menu>
  3. C<links>
  4. D<aside>

Answer: A. nav marks a section of navigation links, and assistive technology lists it as a landmark. aside is for loosely related content, and links is not an HTML element.

15Block and inline<section>D</section>

Which of these elements is inline by default?

<div>A</div><span>B</span><p>C</p><section>D</section>
  1. A<div>
  2. B<p>
  3. C<span>
  4. D<section>

Answer: C. span flows within a line of text. div, p and section are block-level: each starts on a new line and takes the full width available.

16Validation</form>

What happens if this form is submitted with the field empty?

<form>  <input type="email" name="email" required>  <button>Join</button></form>
  1. AThe form is sent with an empty value
  2. BThe browser stops the submit and shows a message
  3. CThe field is removed from the form
  4. DThe page reloads without sending

Answer: B. required makes the browser check the field before sending. An empty required field fails the check, so the form is not sent and the browser points at the field.

17Tables</table>

What does colspan="2" do?

<table>  <tr><td colspan="2">Total</td></tr>  <tr><td>Tea</td><td>4</td></tr></table>
  1. AMakes the cell span two rows
  2. BGives the cell a 2px border
  3. CMakes the cell span two columns
  4. DSplits the cell in two

Answer: C. colspan stretches a cell across that many columns. rowspan is the attribute that stretches a cell down across rows.

18Relative URLs<img src="images/logo.png" alt="Logo">

This markup is on https://example.com/blog/post.html. Which file does the browser request?

<img src="images/logo.png" alt="Logo">
  1. Ahttps://example.com/blog/images/logo.png
  2. Bhttps://example.com/images/logo.png
  3. Chttps://images/logo.png
  4. DNone. The path is invalid

Answer: A. A path with no leading slash is relative to the folder of the current page, here /blog/. Start it with a slash (/images/logo.png) to count from the root of the site.

19Checkboxes</form>

What is sent for this field when the form is submitted?

<form>  <input type="checkbox" name="news" checked></form>
  1. Anews=true
  2. BNothing
  3. Cnews=checked
  4. Dnews=on

Answer: D. A ticked checkbox with no value attribute sends the value "on". An unticked checkbox sends nothing at all, which is why servers must treat a missing field as "no".

20The viewport meta tag content="width=device-width, initial-scale=1">

What is this tag for?

<meta name="viewport"      content="width=device-width, initial-scale=1">
  1. AIt makes the page as wide as the device screen
  2. BIt sets the page title on phones
  3. CIt stops visitors from zooming
  4. DIt loads a separate mobile stylesheet

Answer: A. Without it, phones lay the page out on a wide virtual screen and shrink it to fit, so everything looks tiny. With it, the layout width matches the device and responsive CSS works.

Tricky

What the browser really builds
21Optional end tags<p>Two

How many paragraph elements does the browser create?

<p>One<p>Two
  1. AOne, with the second nested inside it
  2. BTwo, side by side
  3. CNone. The markup is invalid
  4. DOne, holding "One Two"

Answer: B. The end tag of a p is optional. A new p start tag closes the paragraph that is open, so you get two sibling paragraphs.

22Nesting rules<p>Intro <div>Box</div> outro</p>

How does the browser build this?

<p>Intro <div>Box</div> outro</p>
  1. AThe div sits inside the paragraph
  2. BThe page fails to load
  3. CThe div is removed
  4. DThe paragraph ends before the div

Answer: D. A paragraph cannot contain block elements. The div start tag closes the open p, so the div becomes its sibling. The stray </p> at the end then creates an extra empty paragraph.

23defer</head>

When does this script run?

<head>  <script src="app.js" defer></script></head>
  1. AAs soon as it has downloaded
  2. BBefore any HTML is read
  3. CAfter the HTML has been parsed
  4. DOnly when the visitor clicks something

Answer: C. defer downloads the file while the page is being parsed and runs it once parsing is finished, keeping the order of deferred scripts. async is the one that runs as soon as the download ends.

24Boolean attributes<input type="checkbox" checked="false">

Is this checkbox ticked when the page loads?

<input type="checkbox" checked="false">
  1. ANo
  2. BYes
  3. CIt depends on the browser
  4. DThe browser shows an error

Answer: B. For a boolean attribute only its presence counts; the value is ignored. checked="false" still ticks the box. Leave the attribute out to start unticked.

25Case in tag names<DIV>Hello</DIV>

What does a browser do with this in an HTML page?

<DIV>Hello</DIV>
  1. ATreats it as a normal div
  2. BShows the tags as text
  3. CIgnores the element
  4. DShows a syntax error

Answer: A. Tag and attribute names in HTML are not case-sensitive. <DIV>, <Div> and <div> are the same element. Lower case is the convention.

26Tables in the DOM</table>

In the page the browser builds, what is the parent of the <tr>?

<table>  <tr><td>A</td></tr></table>
  1. A<table>
  2. B<thead>
  3. C<tbody>
  4. D<td>

Answer: C. The parser adds a tbody around rows written directly inside a table. This is why a selector such as table > tr matches nothing.

27Input values<input type="number" value="5">

In JavaScript, what is input.value for this field?

<input type="number" value="5">
  1. AThe number 5
  2. BNaN
  3. Cundefined
  4. DThe string "5"

Answer: D. value is always a string, whatever the type of the input. Use input.valueAsNumber or Number(input.value) when you need to do arithmetic.

28Labels without for</label>

Does clicking the word "Agree" tick the box?

<label>  <input type="checkbox"> Agree</label>
  1. ANo. The label needs a for attribute
  2. BYes. An input inside a label is tied to it
  3. COnly if the input has an id
  4. DOnly in some browsers

Answer: B. A label is tied to the first field placed inside it, with no for or id needed. Clicking anywhere in the label acts on that field.

29Unknown elements<fancy-box>Hi</fancy-box>

What does a browser do with a tag it does not know?

<fancy-box>Hi</fancy-box>
  1. AShows "Hi", treating it as a plain inline element
  2. BShows a syntax error
  3. CHides the content
  4. DStops reading the rest of the page

Answer: A. HTML never stops at an unknown tag. The element is kept in the page with no special meaning or styling, and its content is shown. This is what makes custom elements possible.

30Character encoding<meta charset="utf-8">

Where should this tag go?

<meta charset="utf-8">
  1. AAt the end of <body>
  2. BInside <title>
  3. CBefore the doctype
  4. DIn <head>, within the first 1024 bytes of the file

Answer: D. The browser must know the encoding before it reads any text, so the standard requires the declaration to sit within the first 1024 bytes. Put it first in the head, before the title.

Questions people ask

Is this HTML quiz good for beginners?

Yes. Basics covers the tags and attributes every page uses. Core moves to forms, tables and page structure, and Tricky is about what a browser actually does with markup, which is where even experienced developers get caught.

How were the answers checked?

Where a question is about what the browser does with a piece of markup, that markup was loaded in Chrome and the result compared with the marked answer. The remaining answers follow the HTML Standard.

Is my score saved?

Yes, in your browser on this device. Your best score for each level, your day streak and the question you stopped at are all there when you come back. Nothing is sent to a server and you do not need an account.

How do I get more HTML questions?

Open the AI Quiz Generator on Rune Learn, type a topic such as "HTML forms" or "semantic HTML", and it writes a fresh quiz with explanations.