Performance: Text alignment
Text alignment affects the paint and composite stages of rendering but has minimal impact on page load speed or layout recalculations.
Jump into concepts and practice - no test required
div { text-align: center; }div { display: flex; justify-content: center; align-items: center; text-align: left; }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using text-align property | Minimal | 1 reflow | Low paint cost | [OK] Good |
| Using flexbox for text alignment | Moderate | Multiple reflows | Higher paint cost | [X] Bad |
text-align: center; do to the text inside an element?text-align propertycentercenter places the text in the middle horizontally.text-align is the property, and right is the value. The syntax uses a colon and semicolon.<div> appear?div {
text-align: justify;
width: 300px;
}text-align: justify;header {
text-align center;
}text-align center; missing the colon after text-align.<section> so that the first line is centered, but all other lines are left aligned. Which CSS approach achieves this?::first-line pseudo-element::first-line.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.