Challenge - 5 Problems
Preformatted Text Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ rendering
intermediate2:00remaining
What is the visual output of this HTML snippet?
Consider the following HTML code using the
tag. What will you see rendered in the browser?
HTML
<pre> Hello World! This is preformatted text. </pre>
Attempts:
2 left
💡 Hint
Think about how the
tag treats spaces and new lines.
✗ Incorrect
The
tag preserves both spaces and line breaks exactly as typed, showing text in a fixed-width font.
🧠 Conceptual
intermediate1:30remaining
Why use
instead of normal text tags?
Which reason best explains why a developer would use the
tag in HTML?
Attempts:
2 left
💡 Hint
Think about how code or poetry is shown on web pages.
✗ Incorrect
The
tag is used to show text exactly as typed, preserving formatting like spaces and line breaks.
📝 Syntax
advanced2:30remaining
Which HTML snippet correctly uses
to show code with indentation?
Select the valid HTML code that will display the following code snippet with indentation preserved:
function greet() { console.log('Hi'); }
function greet() { console.log('Hi'); }
Attempts:
2 left
💡 Hint
Remember that
preserves whitespace and line breaks, but
tags do not work insidefor line breaks.
✗ Incorrect
Option A uses
with newline characters correctly to preserve indentation and line breaks. Option A uses
inside, which breaks the preformatted behavior. Option A useswhich does not preserve whitespace. Option A nestsinsidebut includes newline characters as text, which is redundant.
❓ accessibility
advanced2:00remaining
How to make preformatted text accessible?
Which practice improves accessibility when using
to show code or text blocks?
Attempts:
2 left
💡 Hint
Think about how screen readers understand the purpose of content.
✗ Incorrect
Adding an aria-label helps screen readers understand what the preformatted text represents, improving accessibility.
❓ layout
expert3:00remaining
How does
affect page layout and responsiveness?
Given a
block with very long lines of text, what is the best CSS approach to keep the page layout responsive and readable?
Attempts:
2 left
💡 Hint
Think about how to keep long lines from breaking the layout but still preserve formatting.
✗ Incorrect
The 'white-space: pre-wrap;' CSS property preserves whitespace and line breaks but allows long lines to wrap, improving responsiveness.