Paris
Paris is known for art, architecture, food, and history.
The w3-container class is one of the most useful classes in W3.CSS.
It adds 16px left and right padding to an HTML element.
This gives content consistent spacing and alignment across a web page.
London is the capital of England.
<div class="w3-container w3-blue">
<h2>London</h2>
<p>London is the capital of England.</p>
</div>
Try it Yourself »
Without a container, content can run all the way to the edge of its parent element.
With w3-container, the content gets consistent horizontal spacing.
No container
With w3-container
<div>
<p>No container</p>
</div>
<div class="w3-container">
<p>With w3-container</p>
</div>
Try it Yourself »
The w3-container class can be used with many HTML elements.
For example:
<div><header><footer><section><article><form>W3.CSS styles classes, not HTML elements.
This means w3-container works the same way on a
<div>, <section>, or <article>.
It also works on other elements like headers <h1>
and paragraphs <p>.
Containers are useful for page headers and footers.
This is the main content of the page.
<header class="w3-container w3-teal">
<h1>My Website</h1>
</header>
<div class="w3-container">
<h2>Welcome</h2>
<p>This is the main content of the page.</p>
</div>
<footer class="w3-container w3-teal">
<p>Copyright 2026</p>
</footer>
Try it Yourself »
Containers are also useful for grouping sections of content.
Discover some of Europe's most popular destinations.
Paris is known for art, architecture, food, and history.
<section class="w3-container w3-light-grey">
<h2>Travel Guide</h2>
<p>Discover some of Europe's most popular destinations.</p>
</section>
<article class="w3-container">
<h3>Paris</h3>
<p>Paris is known for art, architecture, food, and history.</p>
</article>
Try it Yourself »
Combine w3-container with a W3.CSS color class to create colored sections.
Latest stories and updates.
<div class="w3-container w3-indigo">
<h2>News</h2>
</div>
<div class="w3-container w3-pale-blue">
<p>Latest stories and updates.</p>
</div>
Try it Yourself »
The w3-container class adds 16px left and right padding.
It does not add top or bottom padding.
<div class="w3-container w3-blue">
I have no top or bottom padding.
</div>
Try It Yourself »
Normally you will not have to change the default padding of a container because HTML headings and paragraphs provide their own top and bottom margins:
A paragraph inside a container.
<div class="w3-container w3-blue">
<h2>A Heading</h2>
<p>A paragraph inside a container.</p>
</div>
Try it Yourself »
<div class="w3-container w3-blue">
<h1>I am a Heading</h1>
<p>I am a paragraph.</p>
</div>
Try It Yourself »
When you need extra vertical space, combine the container with a padding class:
This container has extra top and bottom padding.
<div class="w3-container w3-blue w3-padding-32">
<h2>More Space</h2>
<p>This container has extra top and bottom padding.</p>
</div>
Try it Yourself »
Containers can form the basic sections of a complete web page.
Discover architecture, food, canals, and Scandinavian design.
<header class="w3-container w3-black">
<h1>City Guide</h1>
</header>
<section class="w3-container w3-padding-32">
<h2>Explore Copenhagen</h2>
<p>Discover architecture, food, canals, and Scandinavian design.</p>
<button class="w3-button w3-teal">Explore</button>
</section>
<footer class="w3-container w3-light-grey">
<p>City Guide</p>
</footer>
Try it Yourself »
Many web pages use <div> elements instead of
<header> and <footer> elements.
There is no difference in the way W3.CSS treats these elements.
The w3-container class gives sections of a page consistent horizontal spacing.
<div>, <header>, <footer>, <section>, <article>, and other elementsExplore more examples to see how w3-container can be used.
<div class="w3-container">
<p>The w3-container class is an important
w3.CSS class.</p>
</div>
Try It Yourself »
To add a color, just add a w3-color class:
<div class="w3-container w3-red">
<p>London is the capital city of England.</p>
</div>
Try It Yourself »
The w3-container class can be used to style headers:
<div class="w3-container w3-teal">
<h1>Header</h1>
</div>
Try It Yourself »
<header class="w3-container w3-teal">
<h1>Header</h1>
</header>
Try It Yourself »
There is no difference in the way W3.CSS treats <div>
and <header> elements.
The w3-container class can be used to style footers:
<div class="w3-container w3-teal">
<h5>Footer</h5>
<p>Footer information goes here</p>
</div>
Try It Yourself »
<footer class="w3-container w3-teal">
<h5>Footer</h5>
<p>Footer information goes here</p>
</footer>
Try It Yourself »
There is no difference in the way W3.CSS treats <div>
and <footer> elements.
The w3-container class can be
used to style <article> and <section> elements:
<div class="w3-container">
<h2>London</h2>
<p>London
is the most populous city in the United Kingdom,
with a
metropolitan area of over 9 million inhabitants.</p>
</div>
<article class="w3-container">
<h2>Paris</h2>
<p>The
Paris area is one of the largest population centers in Europe,
with more than 2 million inhabitants.</p>
</article>
<section
class="w3-container">
<h2>Tokyo</h2>
<p>Tokyo is the
center of the Greater Tokyo Area,
and the most populous
metropolitan area in the world.</p>
</section>
Try It Yourself »
There is no difference in the way W3.CSS treats <div>,
<article> and
<section> elements.
Containers can be rounded:
<div class="w3-container w3-blue w3-round-xlarge">
<p>London is the most populous city in the United Kingdom,
with
a metropolitan area of over 9 million inhabitants.</p>
</div>
Try It Yourself »
Ad-free learning, track your progress, earn XP, streaks, compete in leagues, build and host websites, unlock coding challenges, and much more!
If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com
If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com