Based in Omaha, NE, USA
The Great Platte River Road Archway spanning Interstate 80 near Kearney, Nebraska at blue hour

How Do I Control Text and Pictures with CSS Padding?

Work from home

Make money from home as a Websnoogie reseller

Zero upfront cost and no hidden fees. Sell websites and hosting under your own business name or under ours, and we build, host and support every site. You find the customers and we do the rest. We pay fast, usually within 72 hours. Call us any day from 7 am to 10 pm, or see how it works.

Become a reselleror call 402-813-4034

A smiling African American woman with natural curly hair, in a tan sweater, sits at a computer in a bright home office with a coffee mug and a green plant on the desk and looks up warmly
Laptop on a bright desk showing colorful boxes with different amounts of space around the content, with a ruler beside it

CSS padding adds space inside an element, between its content and its border. You set it with four properties, or one shorthand line. It keeps text and pictures from pressing against the edge of their box.

What padding does

Every box on a web page has content, padding, a border and a margin. Padding is the space between the content and the border. It is a basic tool of website design.

Without padding, text touches the edge of its box. That looks crowded and is hard to read. A few pixels of padding fix it right away.

You can pad text, images, buttons and whole page sections. You can add padding with inline CSS, which sits inside the HTML tag. You can also write a rule in a style sheet file.

Flat illustration of a picture inside a frame with arrows showing the gap between the frame edge and the picture

The four padding properties

Each side of a box has its own property. In these examples, xx stands for the number of pixels.

CSS
padding-top: xxpx;
padding-right: xxpx;
padding-bottom: xxpx;
padding-left: xxpx;

Replace xx with a number, such as 10. You only need the sides you want to change. A side you leave out keeps its default padding, which is usually zero.

Inline padding on text or a picture

Inline CSS goes inside the tag. It changes just that one element.

HTML
<div style="padding-left: 10px;">TEXT OR PICS HERE</div>

This adds 10 pixels of space on the left inside the box. It is quick for a single fix. If you repeat it on many elements, a style sheet is easier to keep up.

A rule in your style sheet

To reuse padding, write a rule once and add the class to your image or text.

CSS
.your-image {
  padding-left: 10px;
}

Now add class="your-image" to any tag. Every element with that class gets the same padding. If you change the number later, all of them change together.

The shorthand for all four sides

You can set every side on one line. The values go in this order: top, right, bottom, left.

CSS
padding: 10px 20px 10px 20px;

/* one value pads all four sides */
padding: 10px;

The first line pads 10 pixels on the top and bottom and 20 pixels on the left and right. The second line pads all four sides the same. Remember the order as clockwise, starting at the top.

When padding helps most

Buttons are a good example. A button with no padding looks cramped, and it is hard to tap on a phone. Ten to fifteen pixels on each side makes it easier to read and press.

Padding also helps pictures. A picture with a few pixels of padding and a light border looks like a framed photo.

Padding is not margin

People mix these two up often. Padding is space inside the border of an element. Margin is space outside it.

If you give a picture a background color, the color fills the padding. It does not fill the margin. That is a quick way to tell which one you are changing.

A common mistake is a box that grows wider after you add padding. The padding adds to the width you set. To keep the size fixed, add box-sizing: border-box; to the rule.

This is not a complete guide to padding. For more detail, see the CSS overview at the W3C. If you want a hand, we are in Omaha and answer the phone at 402-813-4034 every day from 7 am to 10 pm.

Common questions

  • Does padding go inside or outside the border?

    Padding goes inside the border. Margin is the space outside it.

  • What order do the shorthand padding values follow?

    Top, right, bottom, then left. You can remember it as clockwise from the top.

Rod Atwood, the bearded founder of Websnoogie, beside Tami Atwood, who wears glasses, both smiling

AboutRod and Tami Atwood

Rod and Tami Atwood and other Websnoogie contributors write the Websnoogie blog. Rod has built websites since 2004 and founded Websnoogie, LLC in Omaha in 2012. Tami is co-owner, content editor and billing expert. Call us at 402-813-4034 or write to staff@websnoogie.com.

  • Facebook social media logo
  • X social media logo
  • Instagram social media logo
  • Pinterest social media logo
  • LinkedIn social media logo
  • YouTube social media logo
  • TikTok social media logo
  • Threads social media logo
  • Google Business Profile social media logo

Get started with Websnoogie

A smiling couple at a sunlit office desk reviewing a colorful website on a large monitor

A family company in Omaha

Rod, Tami, and their team have built websites, content, and provided SEO services (internet marketing) for over 20 years. You call us, you talk to us. Most new websites are ready in 3 to 5 days, and our hosting runs at 99.999% uptime.

  • Best of Omaha B2B winner, 2021 to 2025
  • BBB accredited with an A+ rating
  • Small businesses, nonprofits and professionals

Sign up now

Due today$449

  • Visa
  • Mastercard
  • American Express
  • Discover
  • Apple Pay
  • Google Pay
  • Cash App Pay
  • PayPal

Secure checkout with Square or PayPal

More info on our products

Contact us now!

Prefer to talk? Call 402-813-4034 or email staff@websnoogie.com. We are open every day, 7 am to 10 pm.

Graphical site map