totn CSS

CSS: padding-top property

This CSS tutorial explains how to use the CSS property called padding-top with syntax and examples.

Description

The CSS padding-top property defines the padding space on the top of an element.

Syntax

The syntax for the padding-top CSS property is:

padding-top: value;

Parameters or Arguments

value

The padding space to apply to the top of the element. It can be one of the following:

Value Description
fixed Fixed value expressed in px, em, ...
div { padding-top: 4px; }
div { padding-top: 5em; }
percentage Percentage value
div { padding-top: 10%; }
inherit Element will inherit the padding-top from its parent element
div { padding-top: inherit; }

Note

  • The value in the CSS padding-top property can be expressed as either a fixed value or as a percentage.
  • Negative values are not allowed in the CSS padding-top property.
  • When the value is provided as a percentage, it is relative to the width of the containing block.
  • See also padding, padding-bottom, padding-left, and padding-right.

Browser Compatibility

The CSS padding-top property has basic support with the following browsers:

  • Chrome
  • Android
  • Firefox (Gecko)
  • Firefox Mobile (Gecko)
  • Internet Explorer (IE)
  • IE Phone
  • Opera
  • Opera Mobile
  • Safari (WebKit)
  • Safari Mobile

Example

We will discuss the padding-top property below, exploring examples of how to use this property in CSS with a fixed value as well as a percentage value.

Using Fixed Value

Let's look at a CSS padding-top example where we have provided the value as a fixed value.

div { padding-top: 10px; }

In this CSS padding-top example, we have provided a value of 10px which would apply to the top of the element.

Let's look at another CSS padding-top example with a fixed value.

div { padding-top: 5em; }

In this CSS padding-top example, we have provided a value of 5em which would apply to the top of the element.

Using Percentage

Let's look at a CSS padding-top example where we have provided the value as a percentage.

div { padding-top: 4%; }

In this CSS padding-top example, we have provided a value of 4% which would apply to the top of the element.