Skip to content
Learn Netverks

Lesson

Step 19/31 61% through track

centering-recipes

Centering patterns that work

Last reviewed Jun 1, 2026 Content v20260601
Track mode
iframe_html
Means
HTML preview sandbox
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Centering patterns that work—the ideas, syntax, and habits you need before moving on in HTML & CSS.

Without a solid grasp of Centering patterns that work, you will repeat mistakes in HTML & CSS exercises and on real pages or scripts.

You will apply Centering patterns that work in contexts like: Landing pages, dashboards, marketing sites, and portfolio pieces built without a framework.

Read the lesson, edit HTML/CSS in the playground, press Run to preview, then answer the lesson MCQs.

When the previous lesson's MCQs feel easy and you can explain Centering patterns that work in your own words.

Centering confuses everyone because context matters: inline text, block in parent, or unknown dimensions. These three recipes cover most UI work.

1. Text centering

text-align: center; on the parent—for inline content and text nodes.

2. Flex centering (favorite)

.center-flex {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 8rem;
}

3. Grid centering

.center-grid {
  display: grid;
  place-items: center;
  min-height: 8rem;
}

Practice

Switch the wrapper class between center-flex and center-grid in the playground.

Important interview questions and answers

  1. Q: How do you center a block horizontally with auto margins?
    A: Set a width and `margin-left: auto; margin-right: auto;` on the block.
  2. Q: Why is flex/grid centering popular?
    A: It centers both axes without calculating positions, even with dynamic content size.
  3. Q: Does `text-align: center` center divs?
    A: No—it centers inline content inside the element, not block-level children.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • What part of this lesson needs a second read?
  • What would you try differently in a real project?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump