HTML Quiz: Test Your HTML Knowledge
Pick how many questions you want, choose a difficulty and go. You'll see why each answer is right or wrong, then you can retry to beat your score.
Which of these is the correct way to write a paragraph?
<p>Hello<p><paragraph>Hello</paragraph></p>Hello<p><p>Hello</p>
HTML is a programming language.
- True
- False
Which file extension do HTML files usually use?
- .html
- .ht
- .txt
- .web
What does the browser show from
<h1>Welcome</h1>?<h1>Welcome</h1>exactly as written- Nothing, because tags hide content
- The word "Welcome" as a large heading
- An error message
Which of these do you need to start writing HTML?
- A paid program
- An internet connection
- A text editor and a browser
- A web server
What does the VS Code extension Live Server do?
- Publishes your site on the internet
- Reloads the browser automatically when you save
- Checks your spelling
- Converts HTML to CSS
Why should you avoid spaces in HTML file names?
- Browsers can't open them at all
- HTML forbids spaces anywhere
- They make the file larger
- They become
%20in links and are easy to mistype
What must be the very first line of an HTML page?
<!DOCTYPE html><html><head><body>
Which part of the page contains the visible content?
- head
- title
- body
- meta
What does
<meta charset="UTF-8">do?- Allows the page to display characters from any language, including emoji
- Makes the page load faster
- Sets the page font
- Makes the page work on phones
The
langattribute in<html lang="en">helps…- the page load in English-speaking countries only
- screen readers pronounce words correctly and search engines know the language
- translate the page automatically
- Nothing, because it's optional decoration
What is an HTML element?
- Only the start tag
- Only the content
- A CSS file
- The start tag, the content and the end tag together
HTML tags should be written in…
- lowercase
- UPPERCASE
- Any mix, but
<P>is recommended - Title Case
How many elements are in
<p>Hi <em>there</em></p>?- 1
- 2
- 3
- 4
What happens to three spaces between two words in HTML content?
- They all show
- They become a line break
- They collapse into a single space
- The browser shows an error
Which attribute tells a link where to go?
- src
- href
- link
- go
Which attribute describes an image for screen readers?
- alt
- title
- src
- describe
Which of these is a boolean attribute?
- href
- class
- required
- src
What is a "global attribute"?
- An attribute that can be used on any element, like
idorclass - An attribute that only works on
<html> - An attribute that affects every page on a site
- An attribute written in capital letters
- An attribute that can be used on any element, like
Which heading is the most important?
<h3><h6><heading><h1>
There is an
<h7>tag in HTML.- False
- True
You want some text to look big, but it isn't a section title. What should you do?
- Use
<h1>because it's big - Use a paragraph and make it big with CSS
- Use
<h6>so it's less important - Use several
<br>tags
- Use
Why do screen-reader users care about headings?
- Screen readers read headings in a louder voice
- Headings are the only text a screen reader reads
- They can jump between headings to skim the page
- They don't, because headings are visual only
What does the
<hr>element represent?- A heading row
- A hidden region
- A hyperlink reference
- A thematic break between sections
Which element keeps spaces and line breaks exactly as typed?
<p><span><pre><keep>
Does
<br>need a closing tag?- No, it's a void element
- Yes,
</br> - Only inside paragraphs
- Only in old HTML
Which tag highlights text like a highlighter pen?
<mark><highlight><em><hl>
Which element is best for a long, separate quotation?
<q><quote><cite><blockquote>
What does
<abbr title="HyperText Markup Language">HTML</abbr>do?- Makes HTML bold
- Marks HTML as an abbreviation and shows the full form on hover
- Hides the text
- Creates a link
Does the browser add quotation marks around
<q>automatically?- Yes
- No
- Only with CSS
- Only in English
What does the
citeattribute on<blockquote>hold?- The author's name
- The date
- The URL of the source
- A visible caption
Which element suits an author's email and phone number at the end of an article?
- footer only
- address
- contact
- cite
How do browsers usually show
<abbr title="...">?- With a dotted underline and a tooltip on hover
- In bold
- In capitals
- They hide it
Why use quotation elements instead of italics or indentation?
- They load faster
- CSS can't style plain paragraphs
- They are required by HTML5
- They describe what the content is, which helps screen readers and search engines
Which element is used for short code inside a sentence?
- code
- pre
- samp
- script
What does
<samp>represent?- Sample images
- A code comment
- Output from a program
- A keyboard key
What is the standard markup for a block of code?
- <code><pre>
- <block>
- <script>
- <pre><code>
Which entity displays a less-than sign?
- <
- >
- &
- &less;
Why add overflow-x: auto to code blocks?
- To hide long lines
- So long lines scroll inside the block instead of widening the whole page on phones
- To add syntax colours
- To wrap every line
Which is a correct HTML comment?
// comment<!-- comment -->/* comment */# comment
What's the keyboard shortcut to toggle a comment in most code editors?
- Ctrl + C
- Ctrl + H
- Alt + C
- Ctrl + /
Why should you never put a password in an HTML comment?
- It will break the page
- Comments are limited to 10 characters
- Anyone can read it by viewing the page source
- Browsers delete comments
What does the style attribute contain?
- HTML tags
- CSS declarations
- JavaScript
- A file name
In
rgb(255 0 0), what colour is shown?- Green
- Red
- Blue
- Black
What does the value after the slash in
rgb(0 0 0 / 50%)control?- Transparency (alpha)
- Brightness
- Hue
- Size
Which colour format makes it easiest to create lighter and darker shades?
- Names
- HEX
- HSL
- None
Why are inline styles avoided for whole websites?
- Browsers ignore them
- They don't support colours
- They must be repeated on every element and are hard to update consistently
- They make pages invalid
What does the
ain<a>stand for?- address
- anchor
- action
- attribute
Which attribute opens a link in a new tab?
new="tab"href="_new"target="_blank"open="tab"
<a href="images/logo.png">is an example of…- an absolute URL
- an email link
- a broken link
- a relative URL
What does
href="../about.html"point to?- about.html in the parent folder
- about.html in a sub-folder
- about.html on another website
- The about section of the current page
What does
../mean in a path?- The current folder
- The website root
- Go up one folder
- The home page
Why are relative paths useful?
- They load faster than absolute URLs
- The site keeps working if it moves to a new domain
- They're required for images
- They hide files
Where can you see which files failed to load?
- In the HTML source only
- In the address bar
- Nowhere
- In the browser developer tools, Console and Network tabs
What does
about.html#teamlink to?- The element with id="team" on about.html
- A file called team
- The team folder
- A new tab
Why should file names avoid spaces?
- Spaces are invalid in HTML
- Servers delete them
- Images can't have spaces
- Spaces become %20 in URLs and cause mistakes
Does
<img>have a closing tag?- Yes,
</img> - No, it's a void element
- Only when it has a caption
- Only in HTML5
- Yes,
When should alt be empty (
alt="")?- When the image is purely decorative
- When you're in a hurry
- Never
- When the image has a caption
What does
loading="lazy"do?- Loads a low-quality version
- Slows the page on purpose
- Hides the image
- Waits to download the image until it's near the screen
Which format is best for a logo that must stay sharp at every size?
- JPG
- GIF
- SVG
- BMP
What does
<li>stand for?- line
- list item
- link
- list index
Which attribute makes an ordered list count down?
downstart="-1"reversedorder="desc"
Which elements make up a description list?
<ul>,<li><dl>,<li><desc>,<term><dl>,<dt>,<dd>
Which element should you use for a clickable action on the page?
- button
- div
- span
- p
What does type="reset" do?
- Reloads the page
- Deletes the form
- Restores every form field to its starting value
- Submits the form
What does the disabled attribute do?
- Makes the button unclickable and unfocusable
- Hides the button
- Changes its colour to red
- Removes it from the form
What's a good minimum size for a button on touch screens?
- 10 by 10 pixels
- 20 by 20 pixels
- About 44 by 44 pixels
- 200 by 200 pixels
Why is a styled div worse than a button?
- Divs can't be styled
- It loads slower
- It can't have click events
- It lacks keyboard focus, Enter and Space activation, and a button role for screen readers
What does
<tr>stand for?- table record
- table row
- text row
- top row
Which element gives a table a title that screen readers announce?
<caption><title><th><legend>
Should you use tables to lay out a whole web page?
- Yes, it's the standard way
- Only on mobile
- No, use CSS Flexbox or Grid; tables are for data
- Only for footers
In a row where one cell has
rowspan="2", what happens to the next row?- It needs an extra cell
- Nothing changes
- It needs one fewer cell, because that space is taken
- It's deleted
Which element is used for a multi-line text box?
<input type="multiline"><textarea><textbox><input rows="4">
What happens to an input that has no
nameattribute when the form is submitted?- It's sent with a random name
- The form refuses to submit
- Its value isn't sent at all
- It's sent as "undefined"
How do you make radio buttons a "choose one" group?
- Put them in a
<ul> - Give them the same
id - Use
type="group" - Give them the same
name
- Put them in a
What is
<legend>used for?- The title of a
<fieldset>group - A form's footer text
- Tooltip text for inputs
- A map key
- The title of a
Which element creates a dropdown list?
- dropdown
- list
- select
- option alone
What is sent to the server for a selected option?
- Its value attribute (or its text if there's no value)
- The visible text always
- Its index
- Nothing
How do checkboxes differ from radio buttons?
- Checkboxes allow one choice
- They're identical
- Radio buttons can't be pre-selected
- Checkboxes allow several choices; radio buttons allow one per group
What does a datalist provide?
- Suggestions while typing, without restricting the value
- A fixed list users must choose from
- A table of data
- Validation messages
Why shouldn't a placeholder replace a label?
- Placeholders aren't valid HTML
- Placeholders are sent with the form
- It disappears when typing and is often hard to read, leaving the field unlabelled
- Screen readers ignore labels
Which input type shows a slider?
- range
- slider
- scale
- number
What does the
stepattribute do on a number input?- Sets how many inputs appear
- Sets the allowed increments, like 0.5
- Moves the cursor
- Limits the number of characters
Which attribute limits a file input to images?
type="image"only="images"filter="img"accept="image/*"
What's the difference between
readonlyanddisabled?- Read-only values are still submitted; disabled values are not
- No difference
- Disabled values are submitted; read-only aren't
- Read-only only works on checkboxes
What happens when you submit a form with an empty required field?
- It's sent anyway
- The browser blocks it and shows a message
- The page reloads
- The field is filled automatically
Is HTML validation enough to protect your server?
- Yes
- Only with pattern
- Only for passwords
- No, the server must validate too
What does autocomplete="new-password" help with?
- Telling password managers to suggest a new strong password
- Blocking autofill
- Validating the password
- Hiding the password
What's the difference between :invalid and :user-invalid?
- They're identical
- :invalid is only for numbers
- :user-invalid only applies after the user has interacted with the field
- :user-invalid is a JavaScript method
What does novalidate on a form do?
- Removes all fields
- Validates on the server
- Turns off the browser's built-in validation, usually so JavaScript can handle it
- Hides error messages forever
Block elements start on a new line.
- True
- False
Which pair is generic (has no meaning of its own)?
<nav>and<a><section>and<strong><header>and<em><div>and<span>
How wide is an inline element by default?
- 100% of the page
- 50%
- As wide as its content
- It has no width
In CSS, how do you select elements with
class="box"?#boxbox*box.box
Can one element have more than one class?
- No, only one
- Yes, separated by commas
- Yes, separated by spaces
- Only if it has no id
Which is a good use for an id?
- Styling every button
- The target of a jump link like
#contact - Styling all paragraphs
- Grouping list items
What must a custom data attribute name start with?
- x-
- custom-
- data-
- my-
What does
el.dataset.state = 'open'do?- Adds or updates data-state="open" on the element
- Nothing
- Creates a new element
- Changes the class
Which is a good use of a data attribute?
- The page's main heading text
- A password
- The alt text of an image
- Storing which category a product belongs to
What does
content: attr(data-label)do in CSS?- Sets a variable
- Hides the element
- Validates the attribute
- Shows the data-label value as generated text
Why should data attribute names use hyphens instead of capitals?
- HTML lowercases attribute names, so camelCase names don't map to dataset as expected
- Capitals are slower
- Hyphens are required by CSS
- Capitals aren't allowed in HTML at all
How many
<main>elements should a page have?- One
- One per section
- As many as you like
- None
Do semantic elements look different from a
<div>by default?- Mostly no. They behave like blocks; the benefit is meaning
- Yes, very different
- They're invisible
- They're always bold
What is the purpose of the
datetimeattribute on<time>?- To show a clock
- To format the date automatically
- To set the page's timezone
- To give a machine-readable date while the visible text stays friendly
How many main elements should a page have?
- Any number
- One
- Two
- None
Which CSS tool is best for the overall page grid of rows and columns?
- float
- CSS Grid
- position: absolute
- tables
What does position: sticky do on a header?
- Removes it on scroll
- Makes it fixed width
- Hides it on mobile
- Keeps it visible at the top while the page scrolls
Why limit the width of text columns?
- To save bandwidth
- Browsers require it
- Lines of about 60 to 80 characters are easier to read
- For SEO only
Why write HTML in reading order even if CSS moves things around?
- It loads faster
- CSS can't move elements
- Search engines ignore CSS
- Keyboard, screen-reader and small-screen users follow the HTML order
What is an iframe used for?
- Embedding another web page inside yours
- Drawing frames around images
- Making forms
- Adding borders
Why should you add
titleto an iframe?- It changes the browser tab title
- It tells screen-reader users what the frame contains
- It's required for it to load
- It shows a tooltip only
Some websites appear blank when put in an iframe. Why?
- Iframes only show images
- The width is too small
- Iframes don't support HTTPS
- Those sites send security headers that forbid being framed
What does youtube-nocookie.com do?
- Removes adverts
- Makes videos load faster
- Hides the YouTube logo
- Avoids setting tracking cookies until the video is played
How do you start an embedded YouTube video at 2 minutes?
- ?time=2m
- ?start=120
- #120
- ?seek=2
Why include the address as text next to an embedded map?
- Maps require it
- To improve map accuracy
- So it's readable if the map doesn't load and for screen-reader and search engine users
- It isn't useful
What is a facade for an embedded video?
- A lightweight thumbnail and play button that loads the real player only on click
- A fake video
- A video filter
- A CSS animation
Why is
<embed>usually avoided for PDFs?- It's not valid HTML
- It only works with images
- It has no fallback content, so nothing helpful shows when the PDF can't be displayed
- It requires JavaScript
Every named entity starts with which character?
- #
- &
- <
- $
With
<meta charset="UTF-8">, can you type emoji directly in HTML?- No, you must use entities
- Only in headings
- Yes
- Only in comments
What is
©?- An error
- A colour code
- A comment
- A numeric entity (it's ©)
What does figure usually contain?
- Only text paragraphs
- Self-contained content such as an image, chart or code listing, often with a caption
- Navigation links
- Form fields
What does a progress element with no value attribute show?
- An indeterminate bar for a task of unknown length
- An empty bar
- A full bar
- Nothing
What does the datetime attribute provide?
- The visible text
- A countdown
- A time zone converter
- A machine-readable version of the date or time
Does figcaption replace an image's alt text?
- No, alt describes the image while the caption adds context
- Yes
- Only for charts
- Only on mobile
What do the low, high and optimum attributes of meter control?
- The bar's size
- Animation speed
- Which ranges count as good or bad, which changes the colour browsers use
- Accessibility labels
Which attribute shows play/pause buttons?
- controls
- buttons
- player
- ui
Why list several
<source>elements?- To play them all at once
- So each browser can pick a format it supports
- To make the video longer
- It's required for audio only
What file format do captions for
<track>use?- .txt
- .srt only
- .mp4
- .vtt (WebVTT)
What draws on a canvas?
- JavaScript
- CSS
- HTML attributes
- The browser automatically
What do the width and height attributes of canvas control?
- The number of drawing pixels
- Only the visible size
- The border
- The zoom level
Which method writes text on a canvas?
- drawText
- writeText
- text
- fillText
Why do canvases look blurry on high-resolution screens?
- Canvas doesn't support colour
- Browsers compress them
- Each canvas pixel is stretched over several screen pixels
- The fallback text overlaps
Why is canvas content not accessible by default?
- It's always hidden
- It's just pixels, with no elements or text that assistive technology can read
- It requires a plug-in
- Canvas can't be used with keyboards
What does SVG stand for?
- Scalable Vector Graphics
- Simple Vector Graphics
- Styled Visual Graphics
- Static Vector Grid
Which attribute colours the inside of an SVG shape?
- color
- background
- fill
- stroke
How should a decorative SVG icon next to visible text be marked?
- role="img"
- aria-hidden="true"
- alt=""
- title=""
When is an SVG file in an img tag better than inline SVG?
- When you need CSS hover effects on parts of it
- For icons that change colour
- Never
- For large, unchanging graphics that benefit from browser caching
What does the path command M do?
- Moves the pen to a point without drawing
- Draws a curve
- Closes the path
- Mirrors the shape
What does a plain script tag without defer or async do while it loads?
- Blocks the browser from building the rest of the page
- Nothing
- Loads in the background
- Runs last
Which kind of script can use import and export?
- Any inline script
- A script with type="module"
- A script with async
- Only scripts in the body
Why prefer external script files for most code?
- They're cached by the browser and easier to maintain
- They run faster than inline code
- Inline scripts are invalid
- They can't be blocked
Which is a good fit for async?
- A script that needs a library loaded first
- A module
- Inline code
- An independent analytics script
What is progressive enhancement?
- Loading scripts gradually
- Upgrading browsers
- Building a working page in HTML first, then adding JavaScript improvements on top
- Using only modules
Is the
<head>content visible on the page?- Yes
- Only the meta tags
- No
- Only on mobile
Roughly how long should a meta description be?
- 10 characters
- About 150 to 160 characters
- 50 characters
- 1000 characters
What is
og:imageused for?- The favicon
- The background image
- The picture shown when the link is shared on social media
- Image SEO alt text
What does
deferdo on a script tag?- Delays the script by 5 seconds
- Prevents the script from running
- Runs it before the page loads
- Downloads it in parallel and runs it after the HTML is parsed
Where do SEO meta tags go?
- At the end of the body
- In the head
- Inside the h1
- In a footer
What does meta robots noindex do?
- Speeds up indexing
- Removes images
- Asks search engines not to show the page in results
- Hides the page from visitors
What format is recommended for structured data?
- Microdata in comments
- CSV
- XML sitemaps
- JSON-LD in a script type="application/ld+json"
What size works well for an Open Graph image?
- 16 by 16 pixels
- About 1200 by 630 pixels
- 100 by 100 pixels
- 4000 by 4000 pixels
Why should structured data match the visible page?
- It loads faster
- JSON-LD requires it technically
- Browsers display it
- Search engines check it, and misleading markup can lose rich results or bring penalties
What does "a11y" mean?
- Ally, a JavaScript library
- An HTML attribute
- Version 11 of HTML
- Accessibility (a + 11 letters + y)
Which attribute announces changing content to screen readers?
- aria-hidden
- aria-change
- aria-live
- role="alert-me"
What is WCAG?
- A CSS framework
- The Web Content Accessibility Guidelines
- A screen reader
- A Google ranking tool
Why is
outline: noneon focus a problem?- Keyboard users can no longer see which element is focused
- It slows the page down
- It breaks links
- It's invalid CSS
What does the
2xinsrcset="logo@2x.png 2x"mean?- Make the image twice as big on screen
- Load it twice
- It's 2 KB
- Use this file on screens with double pixel density (retina)
Why put AVIF and WebP sources before a JPG
<img>?- They look different
- Browsers that support the smaller modern formats use them; others fall back to JPG
- JPG must always be last for SEO
- To show all three
What is "art direction" in responsive images?
- Choosing image colours
- Adding captions
- Showing a different crop or image at different screen sizes
- Compressing images
What is responsive web design?
- A separate site for phones
- A fast website
- A site that responds to clicks
- One page that adapts its layout to any screen size
Why shouldn't you use user-scalable=no?
- It stops people zooming, which many need to read comfortably
- It's slower
- It breaks images
- Search engines ban it
What does max-width: 100% do to an image?
- Makes it fill the screen
- Crops it
- Lets it shrink to fit its container but never grow beyond its natural size
- Hides it on mobile
What does mobile-first mean?
- Phones load the page first
- Write the small-screen layout as the default, then add styles for larger screens
- Only phones are supported
- Desktop styles come first
Which autocomplete value helps phones fill in codes from text messages?
- sms
- otp-code
- numeric
- one-time-code
What does CLS measure?
- Load time
- Server speed
- Image quality
- How much the layout jumps around while loading
What does LCP measure?
- The number of links
- How long the largest visible element takes to appear
- Code length
- Colour contrast
Which tool can audit a page's performance in Chrome?
- View source
- The address bar
- Lighthouse in DevTools
- Print preview
Why is preloading many files a bad idea?
- It removes the priority benefit and competes with critical downloads
- Preload is deprecated
- Browsers ignore more than one
- It breaks images
What does decoding="async" on an image suggest?
- Download later
- Lower quality
- The browser may decode the image off the main thread so it doesn't hold up other work
- Convert the format
Which element is the clickable heading of a
<details>element?<legend><caption><title><summary>
What does
<form method="dialog">do inside a dialog?- Sends data to the server
- Opens another dialog
- Nothing
- Closes the dialog and sets its returnValue
Which element is best for "disk 90% full"?
<progress><range><meter><bar>
Does the popover attribute need JavaScript to work?
- Yes, always
- Only for menus
- No, a button with popovertarget can open it
- Only in Chrome
Which event must call preventDefault to allow dropping?
- dragover
- dragstart
- drop
- dragend
What does contenteditable="true" do?
- Makes text bold
- Lets users edit the element's content directly
- Saves text to the server
- Turns the element into a textarea that submits with forms
What's a good practice when a feature needs location?
- Request it on page load
- Hide the prompt
- Ask when the user clicks a clearly labelled button, and offer an alternative
- Require it for the whole site
Why offer buttons as well as drag and drop for reordering?
- Buttons are faster
- Drag and drop is deprecated
- Browsers require it
- Drag and drop isn't usable by keyboard users and doesn't work everywhere on touch screens
Where should the charset meta tag go?
- First in the head
- At the end of the body
- In the footer
- Anywhere
What happens if two elements share an id?
- Both are styled correctly
- Labels, links and scripts only find the first, and the page is invalid
- The page won't load
- Nothing at all
Can a div go inside a p?
- Yes
- No, paragraphs can only contain inline content
- Only with a class
- Only in HTML5
Which JavaScript function encodes a value for a URL?
- escapeHTML
- toURL
- urlEncode
- encodeURIComponent
Why validate HTML if browsers display it anyway?
- Browsers require valid HTML
- Hidden errors can behave differently across browsers and break accessibility, styling and scripts
- Validation makes pages faster
- Search engines reject invalid pages
About the HTML quiz
The question bank holds 182 questions drawn from 44 HTML lessons: 51 easy, 100 medium and 31 hard. Every time you start, the quiz picks a fresh random selection that matches your settings, so retaking it is a good way to practise. After each answer, or at the end in exam mode, you'll see why the right answer is right, and every question you miss links back to the lesson that teaches it.
What the HTML quiz covers
Basics
- 1Introduction to HTML
- 2HTML Editors & Your First File
- 3HTML Page Structure
- 4HTML Elements
- 5HTML Attributes
- 6HTML Headings
- 7HTML Paragraphs
- 8HTML Text Formatting
- 9HTML Quotations and Citations
- 10Showing Code in HTML
- 11HTML Comments
- 12HTML Colors and Inline Styles
- 13HTML Links
- 14HTML File Paths and URLs
- 15HTML Images
- 16HTML Lists
- 17HTML Buttons
Intermediate
- 18HTML Tables
- 19HTML Forms
- 20HTML Form Controls
- 21HTML Input Types
- 22HTML Form Validation
- 23Block vs Inline: div and span
- 24HTML Classes and IDs
- 25HTML Data Attributes
- 26HTML Semantic Elements
- 27HTML Page Layout
- 28HTML Iframes
- 29Embedding Content in HTML
- 30HTML Entities & Symbols
- 31Figures, Dates, Highlights and Progress Bars
Advanced
- 32HTML Audio & Video
- 33HTML Canvas
- 34HTML SVG Graphics
- 35Adding JavaScript to HTML
- 36HTML Head & Meta Tags
- 37HTML for SEO: Meta Tags and Structured Data
- 38HTML Accessibility (a11y)
- 39HTML Responsive Images
- 40Responsive Web Design with HTML
- 41Faster Pages with HTML
- 42HTML Interactive Elements
- 43HTML5 Web APIs
- 44HTML Best Practices and Validation