Complete the code to create preformatted text using the correct HTML tag.
<[1]>This text preserves spaces and line breaks.</[1]>
instead of does not preserve spaces and line breaks.
The <pre> tag preserves spaces and line breaks exactly as written.
Complete the code to show a block of code with preserved formatting.
<[1]> function greet() { console.log('Hello!'); } </[1]>
alone does not preserve line breaks.The <pre> tag preserves the indentation and line breaks of the code block.
Fix the error in the code to properly preserve spaces and line breaks.
<pre>This is [1] text.</pre>The text inside a <pre> tag is called preformatted text because it keeps spaces and line breaks.
Fill both blanks to create a preformatted block with a CSS class.
<[1] class=[2]> Line 1 Line 2 </[1]>
loses preformatted spacing.
Use the <pre> tag for preformatted text and add a class name in quotes for styling.
Fill all three blanks to create a preformatted text block with an aria-label and a CSS class.
<[1] class=[2] aria-label=[3]> Example: 1 2 3 </[1]>
instead of loses spacing.
The <pre> tag preserves formatting, the class attribute styles it, and aria-label improves accessibility by describing the block.
Practice
<pre> tag do in HTML?Solution
Step 1: Understand the purpose of <pre> tag
The <pre> tag is used to display preformatted text, meaning it keeps all spaces and line breaks exactly as typed.Step 2: Compare with other options
Other options describe different HTML tags or functions unrelated to <pre>.Final Answer:
Displays text exactly as typed, preserving spaces and line breaks -> Option BQuick Check:
<pre> preserves spacing = A [OK]
- Thinking <pre> formats text like <p>
- Confusing <pre> with <code> tag
- Assuming <pre> adds styling like bold or links
Solution
Step 1: Identify the correct HTML tag for preformatted text
The correct tag is <pre> to show text exactly as typed.Step 2: Check other options for validity
<preformatted> is not a valid tag, <code> is for code but does not preserve spaces, <p> is for paragraphs without preserving spaces.Final Answer:
<pre>This is preformatted text</pre> -> Option CQuick Check:
Correct tag for preformatted text = B [OK]
- Using <preformatted> which is invalid
- Confusing <code> with <pre>
- Using <p> which does not preserve spaces
Line 1 Line 2 indented Line 3
Solution
Step 1: Understand <pre> tag behavior
The <pre> tag preserves all spaces and line breaks exactly as typed in the code.Step 2: Analyze the given code
The text has line breaks and indentation spaces before 'Line 2 indented'. These will appear exactly as shown.Final Answer:
Line 1 Line 2 indented Line 3 (with spaces and line breaks preserved) -> Option AQuick Check:
<pre> preserves spaces and lines = D [OK]
- Thinking spaces are collapsed like normal text
- Assuming line breaks are ignored
- Confusing <pre> with <p> or <div>
<pre> Hello World </pre>
Solution
Step 1: Examine the code structure
The code shows <pre> tags inside another <pre> block, which means nested preformatted text.Step 2: Understand <pre> nesting effect
Nested <pre> tags cause the inner tags to be shown as text, not as HTML tags, which is usually unintended.Final Answer:
The <pre> tags are inside another <pre>, causing nested preformatted blocks -> Option DQuick Check:
Nested <pre> shows tags as text = A [OK]
- Thinking nested <pre> tags are valid HTML structure
- Assuming spaces inside <pre> are errors
- Ignoring that tags inside <pre> show as text
Solution
Step 1: Identify the requirement for exact spacing and line breaks
Poetry needs spaces and line breaks preserved exactly as typed.Step 2: Choose the HTML tag that preserves formatting
The <pre> tag preserves all spaces and line breaks, making it ideal for poems.Step 3: Evaluate other options
Multiple <p> tags break text into paragraphs but don't preserve spaces; <div> and <span> need extra CSS and don't preserve spaces by default.Final Answer:
Use the <pre> tag to wrap the poem text -> Option AQuick Check:
Exact spacing needs <pre> = C [OK]
- Using <p> which ignores extra spaces
- Relying on CSS alone without <pre>
- Using <span> which is inline and ignores line breaks
Ready to prove it?
Pass the test and this pattern moves unknown
