Skip to content

Buzzingz

Unleashing the Power of Code

  • HTML
  • CSS
  • Toggle search form

CSS Padding

Posted on March 12, 2023 By shani No Comments on CSS Padding

CSS padding is the space between the content of an element and its border. It is defined using the padding property, which can be set for each side of an element (top, right, bottom, left) or for all sides at once.

Here’s an example of setting padding for all sides of an element:

div {
  padding: 10px;
}

In this example, the padding of 10px will be applied to all sides of the div element.

You can also set different padding values for each side using the padding-top, padding-right, padding-bottom, and padding-left properties:

div {
  padding-top: 5px;
  padding-right: 10px;
  padding-bottom: 15px;
  padding-left: 20px;
}

In this example, the top padding is 5px, the right padding is 10px, the bottom padding is 15px, and the left padding is 20px.

You can also use the padding property to set different values for each side in a shorthand notation. Here are some examples:

div {
  padding: 10px 20px; /* top and bottom padding is 10px, left and right padding is 20px */
}

div {
  padding: 10px 20px 30px; /* top padding is 10px, left and right padding is 20px, bottom padding is 30px */
}

div {
  padding: 10px 20px 30px 40px; /* top padding is 10px, right padding is 20px, bottom padding is 30px, left padding is 40px */
}

You can also use the padding property with the inherit, initial, or unset values to inherit, set to the initial value, or unset the padding of an element, respectively.

div {
  padding: inherit; /* inherits the padding of its parent element */
}

div {
  padding: initial; /* sets the padding to its initial value (usually 0) */
}

div {
  padding: unset; /* unsets the padding of the element */
}

Padding can be used to create space between the content of an element and its border, and to control the layout and spacing of elements on a web page. It’s important to use padding in a consistent and organized way to create a visually pleasing and functional layout.

CSS

Post navigation

Previous Post: CSS Margin Collapse
Next Post: CSS Height, Width and Max-width

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

CSS Tutorial

  • Basic CSS Tutorial For Beginners
  • CSS Introduction
  • CSS Syntax
  • CSS Selectors
  • How To Add CSS
  • CSS Comments
  • CSS Colors
  • CSS Backgrounds
  • CSS Borders
  • CSS Margins
  • CSS Margin Collapse
  • CSS Padding
  • CSS Height, Width and Max-width
  • CSS Box Model
  • CSS Outline
  • CSS Text
  • CSS Fonts
  • CSS Web Safe Fonts
  • CSS Font Fallbacks
  • CSS Font Style
  • CSS Font Size
  • CSS Google Fonts
  • CSS Great Font Pairings
  • CSS Icons
  • CSS Links
  • CSS Lists
  • CSS Tables
  • CSS Layout – display: inline-block
  • CSS Layout – float and clear
  • CSS Layout – Horizontal & Vertical Align
  • CSS Layout – Overflow
  • CSS Layout – The display Property
  • CSS Layout – The z-index Property
  • CSS Layout – width and max-width
  • CSS Layout – The position Property
  • CSS Attribute Selectors
  • CSS Image Sprites
  • CSS Image Gallery
  • CSS Dropdowns
  • CSS Horizontal Navigation Bar
  • CSS Vertical Navigation Bar
  • CSS Navigation Bar
  • CSS Opacity / Transparency
  • CSS Pseudo-elements
  • CSS Pseudo-classes
  • CSS Combinators
  • CSS Math Functions
  • CSS The !important Rule
  • CSS Specificity
  • CSS Units
  • CSS Website Layout
  • CSS Counters
  • CSS Forms
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions

Copyright © 2023 Buzzingz.

Powered by PressBook WordPress theme