CSS Reference

padding

The padding CSS property defines the padding space between an element content and its border.

November 5, 2022

property

padding

The padding property is a shorthand used to set each of the four sides instead of using separate properties padding-top, padding-right, padding-bottom, padding-left.

Examples

/* each side separately: top, right, bottom, left */ padding: 10px 20px 10px 20px; /* top and bottom, left and right */ padding: 2% 5%; /* set padding to all four sides */ padding: 2em; /* top | left and right | bottom */ padding: 2em 1em 2em;

The padding property can be defined using one, two, three, or four values. Negative values are invalid.

Properties

Property Description
padding defines all padding properties in one declaration
padding-top defines top padding of an element
padding-right defines right padding of an element
padding-bottom defines bottom padding of an element
padding-left defines left padding of an element

Values

Value Description
length sets a padding in px, em, pt, cm, etc.
% sets a padding in percentage of the width of the containing element
inherit used to inherit the value from the parent element

Related Content

Easy Way to Fix Anchor Links Scrolling Too Far

Stories

Easy Way to Fix Anchor Links Scrolling Too Far

Fixed navbar is a very popular way of displaying navigation when a page is scrolled, but you could run into a small detail that needs to be addressed.

How to Avoid Page Flickering When Scrollbars are Dynamically Shown or Hidden?

Stories

How to Avoid Page Flickering When Scrollbars are Dynamically Shown or Hidden?

There are certain cases when you want to dynamically manipulate the page height which will result in flickering.

Changing the Mouse Cursor in CSS With the cursor Property

Stories

Changing the Mouse Cursor in CSS With the cursor Property

Using CSS to change the cursor on your website is a great way to add a little bit of personality to your site.