0
0
HTMLmarkup~20 mins

Preformatted text in HTML - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Preformatted Text Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
rendering
intermediate
2: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>
AThe text appears in a single line, ignoring spaces and line breaks.
BThe text appears with spaces preserved but line breaks are ignored.
CThe text appears with line breaks but spaces are collapsed.
DThe text appears exactly as typed, preserving spaces and line breaks.
Attempts:
2 left
💡 Hint
Think about how the
 tag treats spaces and new lines.
🧠 Conceptual
intermediate
1:30remaining
Why use
 instead of normal text tags?
Which reason best explains why a developer would use the
 tag in HTML?
ATo make text bold and italic automatically.
BTo display text exactly as typed, including spaces and line breaks.
CTo add clickable links inside the text.
DTo change the font color to red.
Attempts:
2 left
💡 Hint
Think about how code or poetry is shown on web pages.
📝 Syntax
advanced
2: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'); }
A
&lt;pre&gt;function greet() {
    console.log('Hi');
}&lt;/pre&gt;
B<pre>function greet() {<br> console.log('Hi');<br>}</pre>
C<code>function greet() {\n console.log('Hi');\n}</code>
D<pre><code>function greet() {\n console.log('Hi');\n}</code></pre>
Attempts:
2 left
💡 Hint
Remember that
 preserves whitespace and line breaks, but 
tags do not work inside
 for line breaks.
accessibility
advanced
2:00remaining
How to make preformatted text accessible?
Which practice improves accessibility when using
 to show code or text blocks?
AUse <pre> without any additional attributes; screen readers handle it automatically.
BUse only <div> tags instead of <pre> for better screen reader support.
CAdd aria-label describing the content inside the <pre> tag.
DAvoid using <pre> because it is not accessible.
Attempts:
2 left
💡 Hint
Think about how screen readers understand the purpose of content.
layout
expert
3: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?
AUse CSS property 'white-space: pre-wrap;' on the <pre> to allow line wrapping.
BUse 'overflow: hidden;' on the <pre> to cut off long lines.
CUse 'display: inline;' on the <pre> to make it flow with text.
DUse 'white-space: nowrap;' on the <pre> to prevent wrapping.
Attempts:
2 left
💡 Hint
Think about how to keep long lines from breaking the layout but still preserve formatting.