Articles

HTML Wrapper: What It Is and How to Use One

date posted

11/03/26

read time

3 Mins

A person holding a tablet displaying a website security interface. On the left, the cWatch logo is visible with a cloud icon. The screen resembles an HTML Wrapper Tutorial, offering options to scan and protect a site, emphasizing website security features.

Originally published April 14, 2018. Updated November 3, 2026.

What is an HTML wrapper?

An HTML wrapper is an element (usually a div) that holds your page content and centers it at a set maximum width, so text and images don’t stretch edge to edge on wide screens. You give the element a class like wrapper, then use CSS to set a max-width, automatic left and right margins, and a little side padding.

That CSS can live in a <style> tag in the head of the document, or ideally in a separate stylesheet. The three key parts we’ll walk through are the centering, the width of the wrapper, and the internal padding.

How do you create an HTML and CSS wrapper?

Step 1: Wrap your content in a div with a class.

<div class="wrapper">
  <h1>Your headline</h1>
  <p>Your content goes here.</p>
</div>

Step 2: Add the CSS. Here’s the classic version:

/**
* 1. Centers the content.
* 2. Feel free to change this, this sets the width
* 3. Adds some internal 'padding' to the div
*/
.wrapper {
  margin-right: auto; /* 1 */
  margin-left: auto; /* 1 */
  max-width: 1160px; /* 2 */
  padding-right: 10px; /* 3 */
  padding-left: 10px; /* 3 */
}

The modern, shorter version does the same thing with logical properties, which every current browser supports:

.wrapper {
  max-width: 1160px;
  margin-inline: auto;  /* centers it */
  padding-inline: 10px; /* side padding */
  box-sizing: border-box; /* keeps padding inside the max-width */
}

If you haven’t worked with these pieces before, here’s how they fit together: the div is the structure, and the CSS does the styling. max-width caps how wide the content can get, the auto margins split the leftover space evenly on both sides (that’s what centers it), and the padding keeps text from touching the screen edge on phones.

Wrapper vs. container: what’s the difference?

This is great for content or text elements that you want contained, but centered. You can use the same code to set up a ‘container’ element too. Just switch out the word ‘wrapper’ for ‘container’. The usual implication is that a container is a structural element for an overall page, while a wrapper holds a single element or section.

An HTML wrapper is said to be more for a single element than a structural component, though this is open to some interpretation, and by no means coding gospel.

Why did we write this? Hook Agency builds websites and runs marketing for contractors and home service companies. Need a whole site built, not just a wrapper? See Hook’s website design. A Standard Website is an additional $1,000/mo when paired with a recurring service like our Local SEO + AEO.

Learn How To Do Google Local Service Ads Yourself (Free DIY Course)

Want to know how to start getting Local Service Ads leads on your own?

🎥 3 original videos designed to help you get started on LSA Ads.

🔥 Get the ‘Google Guaranteed’ badge to use in other marketing as well.

📈 Only pay per lead, and start getting more leads soon!

Is there you or someone on your team that would like to take it? Enter their info (or yours) below!

  • This field is for validation purposes and should be left unchanged.

Stop wasting your time

Work with a marketing agency that's going to get you what you actually care about, dominate your market, and make you MONEY 💰

Book an Intro Call