Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What CSS property is used to align text horizontally within an element?
The text-align property is used to align text horizontally inside an element. It controls whether text is left, right, centered, or justified.
Click to reveal answer
beginner
What are the common values for the text-align property?
Common values include: - left: Aligns text to the left edge. - right: Aligns text to the right edge. - center: Centers the text. - justify: Stretches text so both edges align.
Click to reveal answer
intermediate
How does text-align: justify; affect the text layout?
It adjusts the spacing between words so that each line fills the entire width of the container, making both left and right edges straight, like in newspapers.
Click to reveal answer
intermediate
Does text-align affect block-level or inline elements?
text-align affects the inline content inside block-level elements. It controls how inline text and inline elements are aligned horizontally within their container.
Click to reveal answer
beginner
How can you center text inside a <div> using CSS?
Use text-align: center; on the <div>. This centers all inline text and inline elements inside that container horizontally.
Click to reveal answer
Which CSS property aligns text inside an element?
Atext-position
Balign-text
Ctext-align
Dalign-content
✗ Incorrect
text-align is the correct property to align text horizontally.
What does text-align: right; do?
AAligns text to the left
BJustifies the text
CCenters the text
DAligns text to the right
✗ Incorrect
It aligns the text to the right edge of the container.
Which value makes text stretch so both edges align evenly?
Ajustify
Bcenter
Cleft
Dright
✗ Incorrect
justify adjusts spacing so text lines up on both left and right edges.
If you want to center text inside a paragraph, which CSS rule do you use?
Ap { center-text: true; }
Bp { text-align: center; }
Cp { text-position: center; }
Dp { align-text: center; }
✗ Incorrect
The correct syntax is text-align: center;.
Does text-align affect block-level elements themselves or the inline content inside them?
AIt affects inline content inside block-level elements
BIt affects block-level elements themselves
CIt affects only images
DIt affects margins
✗ Incorrect
text-align controls how inline content inside block containers is aligned.
Explain how the text-align property works and list its common values.
Think about how text lines up inside a box.
You got /3 concepts.
Describe a real-life example where you would use text-align: justify; and why.
Imagine reading a printed page with neat edges.
You got /3 concepts.
Practice
(1/5)
1. What does the CSS property text-align: center; do to the text inside an element?
easy
A. Aligns the text to the left edge of the container
B. Centers the text horizontally within its container
C. Aligns the text to the right edge of the container
D. Justifies the text so both edges are aligned
Solution
Step 1: Understand the text-align property
This property controls horizontal alignment of inline content inside a block container.
Step 2: Interpret the value center
The value center places the text in the middle horizontally.
Final Answer:
Centers the text horizontally within its container -> Option B
Quick Check:
text-align: center = centered text [OK]
Hint: Center text with text-align: center; [OK]
Common Mistakes:
Confusing center with justify
Thinking it aligns text vertically
Mixing up left and right alignment
2. Which of the following is the correct CSS syntax to align text to the right inside a paragraph?
easy
A. p { text-align = right; }
B. p { align-text: right; }
C. p { text-align: right; }
D. p { text-align-right: true; }
Solution
Step 1: Recall correct CSS property syntax
CSS uses property: value; pairs inside curly braces for selectors.
Step 2: Identify correct property and value
text-align is the property, and right is the value. The syntax uses a colon and semicolon.
Final Answer:
p { text-align: right; } -> Option C
Quick Check:
Correct CSS syntax uses colon and semicolon [OK]
Hint: Use colon : not equals = for CSS properties [OK]
Common Mistakes:
Using = instead of :
Wrong property name like align-text
Missing semicolon at end
3. Given the CSS below, how will the text inside the <div> appear?
div {
text-align: justify;
width: 300px;
}
medium
A. Text lines will stretch to fill the width, aligning both left and right edges
B. Text will be centered horizontally inside the div
C. Text will align only to the left edge
D. Text will align only to the right edge
Solution
Step 1: Understand text-align: justify;
This value stretches each line so the text aligns evenly on both left and right edges.
Step 2: Consider container width
The fixed width of 300px means text lines will expand or contract to fill that width fully.
Final Answer:
Text lines will stretch to fill the width, aligning both left and right edges -> Option A
Quick Check:
justify aligns text edges both sides [OK]
Hint: Justify aligns text edges left and right [OK]
Common Mistakes:
Thinking justify centers text
Confusing justify with right alignment
Ignoring container width effect
4. Identify the error in this CSS snippet that aims to center text inside a header:
header {
text-align center;
}
medium
A. Missing semicolon after property name
B. Incorrect property name, should be text-center
C. Value should be uppercase CENTER
D. Missing colon between property and value
Solution
Step 1: Check CSS property syntax
CSS requires a colon ':' between property and value.
Step 2: Locate missing colon
The snippet has text-align center; missing the colon after text-align.
Final Answer:
Missing colon between property and value -> Option D
Quick Check:
Property and value must be separated by colon [OK]
Hint: Always use colon : between property and value [OK]
Common Mistakes:
Omitting colon
Using wrong property name
Confusing semicolon placement
5. You want to align text inside a <section> so that the first line is centered, but all other lines are left aligned. Which CSS approach achieves this?
hard
A. Use text-align: left; on the section and text-align: center; on the first line with ::first-line pseudo-element
B. Use text-align: center; on the section and text-align: left; on a <p> inside
C. Use text-align: center; on the section and text-indent for the first line
D. Use text-align: center; on the section and text-align: left; on the ::first-line pseudo-element
Solution
Step 1: Understand ::first-line pseudo-element
This targets only the first line of text inside an element for styling.
Step 2: Apply alignment logic
Set the whole section text to left aligned, then override the first line to center using ::first-line.
Step 3: Verify option correctness
Use text-align: left; on the section and text-align: center; on the first line with ::first-line pseudo-element correctly applies text-align: center; to the first line and left alignment to the rest.
Final Answer:
Use text-align: left; on the section and text-align: center; on the first line with ::first-line pseudo-element -> Option A
Quick Check:
Use ::first-line to style first line separately [OK]
Hint: Use ::first-line to style first line differently [OK]
Common Mistakes:
Trying to set first line alignment on container only