Padding

    Utilities for controlling an element’s padding.

    Show all classes

    Control the padding on one side of an element using the utilities.

    For example, pt-6 would add 1.5rem of padding to the top of an element, pr-4 would add 1rem of padding to the right of an element, pb-8 would add 2rem of padding to the bottom of an element, and pl-2 would add 0.5rem of padding to the left of an element.

    Add horizontal padding

    Control the horizontal padding of an element using the px-{size} utilities.

    Padding - 图2

    1. <div class="px-8 ...">px-8</div>

    Add vertical padding

      Control the padding on all sides of an element using the p-{size} utilities.

      Padding - 图4

      Using logical properties

      Use the ps-* and pe-* utilities to set the padding-inline-start and padding-inline-end , which map to either the left or right side based on the text direction.

      1. <div dir="ltr">
      2. <div class="pe-8 ...">pe-8</div>
      3. <div>
      4. <div dir="rtl">
      5. <div class="ps-8 ...">ps-8</div>
      6. <div class="pe-8 ...">pe-8</div>
      7. <div>

      For more control, you can also use the LTR and RTL modifiers to conditionally apply specific styles depending on the current text direction.


      Hover, focus, and other states

      Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:py-8 to only apply the py-8 utility on hover.

      1. <div class="py-4 hover:py-8">
      2. <!-- ... -->
      3. </div>

      You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:py-8 to apply the py-8 utility at only medium screen sizes and above.

      To learn more, check out the documentation on Responsive Design, and other media query modifiers.


      Customizing your theme

      By default, Tailwind’s padding scale uses the . You can customize your spacing scale by editing theme.spacing or theme.extend.spacing in your tailwind.config.js file.

      tailwind.config.js

      1. module.exports = {
      2. spacing: {
      3. '5px': '5px',
      4. }
      5. }
      6. }
      7. }

      Alternatively, you can customize just the padding scale by editing theme.padding or theme.extend.padding in your tailwind.config.js file.

      tailwind.config.js

      1. module.exports = {
      2. theme: {
      3. extend: {
      4. padding: {
      5. '5px': '5px',
      6. }
      7. }
      8. }

      Learn more about customizing the default theme in the theme customization documentation.

      Arbitrary values

      Learn more about arbitrary value support in the arbitrary values documentation.