Skip to content

Tip: What is a Wrapper Div?

One of the listservs I read regularly recently had the question posted, “What is a wrapper?” An answer provided by Paul Novitski was so clear that I thought it might be a useful tip here. With Paul’s permission, here is his response to the question.

A wrapper is an element, commonly a div, that encloses one or more other
elements in the HTML markup, e.g.:

<div id="wrap">
<h1>Headline</h1>
<p>Paragraph</p>
<p>Paragraph</p>
</div>

The purposes of wrappers are several, including:

  • to group elements semantically, for instance to separate page heading
    from body text from sidebar from footer.
  • to group elements cosmetically, such as with a surrounding border or a
    common background image or color.
  • to group elements in layout, such as to keep them all in the same column
    when columns are floated next to one another.
  • to enable special positioning, as when a wrapper is given relative
    positioning in order to contain child elements with absolute positioning.
  • to make it more convenient to specify elements in CSS and JavaScript by
    referring to their parent, without having to id or class each child
    element, as in:
    div#wrap h1 {...}
    div#wrap p {...}
    var aKids = document.getElementById("wrap")
    .childNodes;

    (Note: the var above should all be on one line)

Some special effects require several nested wrappers, such as when a box is
given rounded corners.

Stumble it!  


4 Comments

  1. Wayne John wrote:

    The best thing to do is to grab Firebug, and begin analyzing others web sites. You’ll begin to see the trend on how divs are used across several sites.
    .-= Wayne John´s last blog ..The poll results are in, web development it is =-.

    Monday, January 18, 2010 at 2:35 pm | Permalink
  2. Thanks! From your post, now I know why they called it “wrapper”
    .-= John Wesley´s last blog ..Hello world! =-.

    Friday, January 22, 2010 at 11:20 am | Permalink
  3. I must confess that this is a great and very useful information to me. Thank you so much for this.
    .-= Uche Nwaobi´s last blog ..Improve Usability of Your Website =-.

    Saturday, January 23, 2010 at 1:21 pm | Permalink
  4. Thanks for the explanation, I usually use master or main, although using wrapper div makes my code easier and more clear.
    COngratulations for the post.

    Friday, October 28, 2011 at 10:23 am | Permalink

What can you contribute?

Your email is never published nor shared. Required fields are marked *
*
*

CommentLuv badge