Bird
Raised Fist0
HTMLmarkup~20 mins

Absolute vs relative URLs in HTML - Practice Questions

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
URL Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Absolute URLs
Which of the following is an example of an absolute URL?
Aimages/photo.jpg
B/images/photo.jpg
C../images/photo.jpg
Dhttps://example.com/images/photo.jpg
Attempts:
2 left
💡 Hint
Absolute URLs include the full path starting with the protocol (like https://).
📝 Syntax
intermediate
1:30remaining
Correct Relative URL Usage
Given the current page URL is https://example.com/blog/post1.html, which relative URL correctly links to https://example.com/images/logo.png?
A../../images/logo.png
B../images/logo.png
C/images/logo.png
Dimages/logo.png
Attempts:
2 left
💡 Hint
Relative URLs starting with a slash / start from the root of the website.
❓ rendering
advanced
2:00remaining
Rendering Result of Relative URL
If the current page is https://example.com/products/item.html and the HTML contains <img src="../images/pic.png" alt="Pic">, what is the full URL the browser will request?
Ahttps://example.com/images/pic.png
Bhttps://example.com/products/images/pic.png
Chttps://example.com/products/../images/pic.png
Dhttps://example.com/pic.png
Attempts:
2 left
💡 Hint
The .. means go up one folder from the current page location.
❓ selector
advanced
2:00remaining
CSS URL Selector Behavior
In CSS, if the stylesheet is located at https://example.com/css/style.css and contains background-image: url('../img/bg.png');, which full URL will the browser load?
Ahttps://example.com/img/bg.png
Bhttps://example.com/css/img/bg.png
Chttps://example.com/css/../img/bg.png
Dhttps://example.com/bg.png
Attempts:
2 left
💡 Hint
Relative URLs in CSS are relative to the CSS file location, not the HTML page.
❓ accessibility
expert
2:30remaining
Accessibility Impact of URL Choices
Which statement best explains how using relative URLs can affect accessibility and user experience?
AUsing relative URLs disables keyboard navigation on the page.
BRelative URLs can break links if the page is moved, causing screen readers to fail loading resources.
CAbsolute URLs prevent any accessibility issues because they never break.
DRelative URLs always improve accessibility by reducing page load times.
Attempts:
2 left
💡 Hint
Think about what happens if a page is moved or copied to a different folder.

Practice

(1/5)
1. Which of the following best describes an absolute URL?
easy
A. A link that starts with a slash, like /images/photo.jpg
B. A full web address including protocol and domain, like https://example.com/page
C. A link that points to a file in the same folder, like photo.jpg
D. A URL that only works on your local computer

Solution

  1. Step 1: Understand what an absolute URL is

    An absolute URL includes the full address: protocol (http/https), domain, and path.
  2. Step 2: Compare options to definition

    A full web address including protocol and domain, like https://example.com/page shows a full address with protocol and domain, matching the absolute URL definition.
  3. Final Answer:

    A full web address including protocol and domain, like https://example.com/page -> Option B
  4. Quick Check:

    Absolute URL = full web address [OK]
Hint: Absolute URLs always start with http:// or https:// [OK]
Common Mistakes:
  • Confusing relative URLs with absolute URLs
  • Thinking a URL starting with / is absolute
  • Believing file names alone are absolute URLs
2. Which of these is the correct way to write a relative URL to link to a file named style.css in the same folder?
easy
A. style.css
B. https://example.com/style.css
C. /style.css
D. ../style.css

Solution

  1. Step 1: Understand relative URLs in the same folder

    A relative URL to a file in the same folder can be just the file name.
  2. Step 2: Check options for correct relative URL

    style.css uses just style.css, which correctly points to the file in the same folder.
  3. Final Answer:

    style.css -> Option A
  4. Quick Check:

    Relative URL same folder = file name only [OK]
Hint: Use just the file name for same-folder relative URLs [OK]
Common Mistakes:
  • Using a leading slash which points to root folder
  • Using full URLs when relative is needed
  • Using ../ which points to parent folder
3. Given the current page URL is https://example.com/blog/post1.html, what will the browser load for the relative URL ../images/pic.jpg?
medium
A. https://example.com/images/pic.jpg
B. https://example.com/blog/images/pic.jpg
C. https://example.com/blog/post1.html/images/pic.jpg
D. https://images/pic.jpg

Solution

  1. Step 1: Understand the meaning of .. in relative URLs

    .. means go up one folder from the current page location.
  2. Step 2: Apply to current URL

    Current URL folder is /blog/. Going up one folder leads to /. Then adding images/pic.jpg gives /images/pic.jpg.
  3. Final Answer:

    https://example.com/images/pic.jpg -> Option A
  4. Quick Check:

    .. moves up one folder [OK]
Hint: .. means go up one folder in URL path [OK]
Common Mistakes:
  • Thinking .. stays in the same folder
  • Appending path without going up folder
  • Confusing relative with absolute URLs
4. You wrote this HTML link: <a href="images/photo.jpg">Photo</a> on the page https://example.com/about/index.html, but the image does not load. What is the likely problem?
medium
A. The URL should be absolute starting with https://
B. The relative URL is missing a leading slash to start from root
C. The file extension .jpg is incorrect
D. The relative URL points to a folder that does not exist relative to current page

Solution

  1. Step 1: Understand relative URL resolution

    The relative URL images/photo.jpg looks for an images folder inside the current folder /about/.
  2. Step 2: Check folder existence

    If the images folder is not inside /about/, the link will break. This is the likely cause.
  3. Final Answer:

    The relative URL points to a folder that does not exist relative to current page -> Option D
  4. Quick Check:

    Relative URLs depend on current folder [OK]
Hint: Check if relative folder exists where page is located [OK]
Common Mistakes:
  • Assuming relative URLs start from root without slash
  • Using absolute URLs unnecessarily
  • Ignoring folder structure when linking
5. You want to link to the homepage from a page at https://example.com/products/item.html. Which URL should you use to ensure the link works correctly regardless of the current page location?
hard
A. /index.html
B. index.html
C. https://example.com/index.html
D. ../index.html

Solution

  1. Step 1: Understand absolute vs relative URL behavior

    Relative URLs depend on current page location, so they may break if page moves.
  2. Step 2: Choose URL that works anywhere

    An absolute URL with full domain always works regardless of page location.
  3. Final Answer:

    https://example.com/index.html -> Option C
  4. Quick Check:

    Absolute URL works anywhere [OK]
Hint: Use full URL to avoid relative path issues [OK]
Common Mistakes:
  • Using relative URLs that break if page moves
  • Assuming leading slash always works for all pages
  • Not including protocol and domain for absolute URLs
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard