Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS

W3.CSS Page Containers

Share

Centered Web Pages

The w3-content and w3-auto classes create web pages with a limited width, centered on the screen.

On large screens, space appears on both sides of the page.

On smaller screens, the page adapts to the available width.

Why Limit the Page Width?

A web page that fills a very wide screen can be difficult to read.

  • Lines of text become long
  • Images can become too large
  • Page elements can appear too far apart

A centered page with a maximum width keeps the layout together with space on both sides.


The w3-content Class

The w3-content class limits the page width and centers the page horizontally on the screen.

Automatic left and right margins center the page.

Add the class to the <body> element or to another container around your page:

Example

<body class="w3-content">

<header class="w3-container w3-blue">
  <h1>My Website</h1>
</header>

<main class="w3-container">
  <h2>Welcome</h2>
  <p>This page has a default maximum width of 980px.</p>
</main>

<footer class="w3-container w3-light-grey">
  <p>My Footer</p>
</footer>

</body>

Try it Yourself »

The w3-content class has a default maximum width of 980px.


Set a Custom Page Width

Use the CSS max-width property to change the default maximum page width.

Examples

Create a page with a maximum width of 1500px:

<body class="w3-content" style="max-width:1500px">

<header class="w3-container w3-blue">
  <h1>My Website</h1>
</header>

<main class="w3-container">
  <h2>Welcome</h2>
  <p>This page has a maximum width of 1500px.</p>
</main>

</body>

Try it Yourself »

Create a page with a maximum width of 800px:

<body class="w3-content" style="max-width:800px">

<header class="w3-container w3-blue">
  <h1>My Website</h1>
</header>

<main class="w3-container">
  <h2>Welcome</h2>
  <p>This page has a maximum width of 800px.</p>
</main>

</body>

Try it Yourself »


The maximum width is a limit, not a fixed width.

The page becomes narrower when less space is available.


Apply w3-content to a Part of the Page

You can also add the w3-content class to a part of your page:

Example

<body>

<header class="w3-container w3-blue">
  <h1>My Website</h1>
</header>

<div class="w3-content">
  <main class="w3-container">
    <h2>Welcome</h2>
    <p>This part is centered with a maximum width.</p>
  </main>
</div>

<footer class="w3-container w3-light-grey">
  <p>Footer</p>
</footer>

</body>

Try it Yourself »



The w3-auto Class

The w3-auto class creates a centered page with a maximum width of 1140px on large screens.

Its maximum width changes at smaller screen sizes:

Screen WidthMaximum Page Width
Above 1205px1140px
Above 992px and up to 1205px95% of the available width
992px or less100% of the available width

Example

<body class="w3-auto">

<header class="w3-container w3-blue">
  <h1>My Website</h1>
</header>

<main class="w3-container">
  <h2>Welcome</h2>
  <p>This page adapts its maximum width to the screen size.</p>
</main>

<footer class="w3-container w3-light-grey">
  <p>My Footer</p>
</footer>

</body>

Try it Yourself »


When to Use w3-content

The w3-content class is useful when you want a consistent maximum page width.

On very wide screens, the page stays centered instead of stretching across the screen.

The default maximum width of 980px works well for many articles, blogs, and simple websites.

You can choose a larger maximum width for pages with more columns or large pictures.


When to Use w3-auto

The w3-auto class is useful when you want the page width to adapt automatically to the screen size.

On smaller laptops with a viewport wider than 992px and up to 1205px, the page uses up to 95% of the available width.

This makes good use of the screen while leaving some space on both sides.

On larger screens, the maximum width is 1140px. On screens 992px wide or less, the page can use the full available width.


Center Text and Images

Centering the page does not center the text or images inside it.

Use w3-center when you want centered text or an inline image inside a page section.

Example

<div class="w3-content">
  <div class="w3-container w3-center">
    <h2>Centered Heading</h2>
    <p>Centered text inside a centered page.</p>
    <img src="img_avatar3.png" alt="Avatar" style="width:100px">
  </div>
</div>

Try it Yourself »


Class Reference

ClassPurpose
w3-content Centers the page horizontally with a default maximum width of 980px.
w3-autoCenters the page horizontally with responsive maximum widths.
w3-centerCenters text and inline elements inside an element.

Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.