KoderSolution Logo
HomeArticlesTutorialsForumAI LabRun Code
KoderSolution Logo

The world’s most advanced technical ecosystem for modern software engineers. Learn, build, and grow with next-generation developer tools and resources.

Engineering Newsletter

Join 100,000+ engineers receiving curated high-signal content weekly.

Platforms

  • Technical Articles
  • Interactive Tutorials
  • AI Coding Lab
  • Developer Forum
  • Developer Tools

Pages

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of Service
  • Refund Policy
  • Disclaimer
  • Advertisement

Popular Topics

  • PHP
  • Laravel
  • Python
  • React.Js
  • MySQL
© 2026 KoderSolutionAll Rights Reserved
Developed Bymaksudur.dev
🎨

CSS

Topic Hub & Articles

CSS Introduction

10 min

CSS Syntax

10 min

CSS Selectors

10 min

Recap Quiz

5 Questions

CSS How To

10 min

CSS Comments

10 min

CSS Colors

10 min

Recap Quiz

5 Questions

CSS Backgrounds

10 min

CSS Borders

10 min

CSS Margins

10 min

Recap Quiz

5 Questions

CSS Padding

10 min

CSS Height/Width

10 min

CSS Box Model

10 min

Recap Quiz

5 Questions

CSS Outline

10 min

CSS Text

10 min

CSS Fonts

10 min

Recap Quiz

5 Questions

CSS Icons

10 min

CSS Links

10 min

CSS Lists

10 min

Recap Quiz

5 Questions

CSS Tables

10 min

CSS Display

10 min

CSS Max-width

10 min

Recap Quiz

5 Questions

CSS Position

10 min

CSS Overflow

10 min

CSS Float

10 min

Recap Quiz

5 Questions

CSS Inline-block

10 min

CSS Align

10 min

CSS Combinators

10 min

Recap Quiz

5 Questions

CSS Pseudo-class

10 min

CSS Pseudo-element

10 min

CSS Opacity

10 min

Recap Quiz

5 Questions

CSS Navigation Bar

10 min

CSS Dropdowns

10 min

CSS Image Gallery

10 min

Recap Quiz

5 Questions

CSS Attribute Selectors

10 min

CSS Rounded Corners

10 min

CSS Gradients

10 min

CSS Shadows

10 min

Recap Quiz

5 Questions

CSS 2D Transforms

10 min

CSS 3D Transforms

10 min

CSS Transitions

10 min

Recap Quiz

5 Questions

CSS Animations

10 min

CSS Tooltips

10 min

CSS Images

10 min

Recap Quiz

5 Questions

CSS Flexbox

10 min

CSS Grid

10 min

CSS Media Queries

10 min

Recap Quiz

5 Questions

Progress
0%

0 / 46 Lessons

CSSCSS Tutorial
Lesson

CSS Padding

10 min reading
Free Course

CSS Padding: Creating Internal Spacing Inside Box Boundaries

CSS padding creates empty space inside an element's border, pushing inner content (text, images) away from the element's outer edge boundaries.

Padding Syntax and Shorthand Values

Padding is declared for individual sides (padding-top, padding-right, padding-bottom, padding-left) or via shorthand values:

/* Individual sides */
div {
    padding-top: 16px;
    padding-left: 24px;
}

/* Shorthand declarations */
div { padding: 20px; }                 /* All 4 sides: 20px */
div { padding: 12px 24px; }            /* Top/Bottom: 12px, Left/Right: 24px */
div { padding: 10px 20px 15px 5px; }   /* Clockwise: Top, Right, Bottom, Left */

Key padding features:

  1. Background Expansion: Padding area inherits the element's background-color or background-image.
  2. No Negative Values: Unlike margins, padding values cannot be negative.
  3. Touch Targets: Adding padding to clickable links (<a>) enlarges interactive tap areas on mobile devices.

Padding Box Model Structure

flowchart TD
    A["Border Edge"] --> B["Padding Area (Inherits Background Color)"]
    B --> C["Inner Content Text / Children"]

Practical Code Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CSS Padding Demonstration</title>
    <style>
        .btn-custom {
            display: inline-block;
            background-color: #2563eb;
            color: #ffffff;
            padding: 12px 24px; /* Generous padding for touch targets */
            border-radius: 6px;
            text-decoration: none;
            font-weight: bold;
        }
    </style>
</head>
<body style="background-color: #0f172a; color: #f8fafc; font-family: system-ui, sans-serif; padding: 2rem;">

    <h2>Button Padding Example</h2>
    <a href="#" class="btn-custom">Clickable Button with Padding</a>

</body>
</html>

Best Practices

  • Use symmetric vertical and horizontal shorthand: Write padding: 12px 24px; to create clean, proportionate UI buttons and card components.
  • Enlarge touch targets on mobile: Apply at least 12px padding to interactive links and buttons for comfortable mobile finger tapping.
  • Use box-sizing: border-box: Ensures padding values do not expand the container's declared width.

Self-Check Challenge

Create a CSS class .card that sets padding: 1.5rem; and a background color of #1e293b!

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Recommended Courses & Books

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum