EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

CSS Padding Color

By Priya PedamkarPriya Pedamkar

Home » Software Development » Software Development Tutorials » CSS Tutorial » CSS Padding Color

CSS Padding Color

Introduction to CSS Padding Color

There are many features in CSS that can be achieved, using properties directly linked to them. Some of these features including setting the font style, color of the background, deciding the size of the text to be displayed, what happens when we hover over some element. However, there are many features that are not directly achievable. One such feature is the color of the padding. There is no parameter in the padding property to define the color for the padding. So we make use of the background-clip, to obtain that particular effect on a page. Let us have a look at how this feature works.

How to Obtain Padding Color?

As discussed in the introduction, using background-flip property helps us restrict or extend the limit to which the particular background needs to be applied for an element. If offers three specific parameters: content-box, padding-box, border-box.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

The syntax for it is as follows:

background-clip: padding-box (or content-box or border-box)

When we define the background-clip to be limited to the padding-box, it extends the background to the inner edge of the border. The background is not applied to the border here. And this is how we achieve padding color, by using a different property.

How does Padding Color work?

Let us take a look at a few examples to see how this process works:

1. Padding color using background-clip using External CSS

  • Since we are using external CSS for this example, we will start by creating a CSS file first.
  • In the CSS file, we will create a class, where we will specify the background-clip to be limited to the padding-box. Along with this, we will specify other properties for the class.

Code:

.padding{
background-color: lightgreen;
padding: 50px;
background-clip: padding-box;
height: 200px;
width: 200px;
border: dotted darkred;
font-size: 15px;
font-family: 'Courier New', Courier, monospace;
}

  • Now, that the CSS code is done, we will move on to the HTML file. In the header section, we will call for the external CSS file first.

<head>
<title>Padding color using CSS</title>
<link rel = "stylesheet" href = "padding.css">
</head>

  • Now, in the body section, we will code for a paragraph element, calling the class created in the CSS file, such that the style and padding color can be demonstrated.
  • The final HTML code should look like the code snippet below:

Code

<html>
<head>
<title>Padding color using CSS</title>
<link rel = "stylesheet" href = "padding.css">
</head>
<body>
<h2>Padding Color Demonstration</h2>
<p class="padding">This paragraph demonstrates background-clip for padding-box. Using this property, limits the background effect to the inside edge of the borders.</p>
</body>
</html>

Popular Course in this category
CSS Training (9 Courses, 9+ Projects)9 Online Courses | 9 Hands-on Projects | 61+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,454 ratings)
Course Price

View Course

Related Courses
Bootstrap Training (2 Courses, 6+ Projects)jQuery Training (8 Courses, 5 Projects)

Output: Once this code is saved, and the HTML file is opened through a browser, you will be able to see the following output:

CSS Padding Color - 1

  • You can see, that the background color is limited to the inside of the borders. This is a way to achieve padding color through CSS.

2. Using background-clip for content-box and padding-box, to demonstrate the difference, through external CSS.

  • Like the previous example, this example also involves external CSS, so we will create the CSS file first.
  • In the CSS file, we will define two different classes, with the background-clip property set for padding-box and content-box respectively. The idea is to understand how these two are different from each other.

Code:

.content{
background-color: lightblue;
padding: 20px;
font-size: 15px;
height: 200px;
width: 200px;
border: dashed pink;
background-clip: content-box;
}
.padding{
background-color: lightgreen;
padding: 50px;
background-clip: padding-box;
height: 200px;
width: 200px;
border: dotted darkred;
font-size: 15px;
font-family: 'Courier New', Courier, monospace;
}

  • As a next step, we will code for the HTML file. Now, since we are using external CSS we will call for the CSS file in the head section, like this:

Code:

<head>
<title>Padding color using CSS</title>
<link rel = "stylesheet" href = "padding.css">
</head>

  • In the body section, we will use the paragraph element twice, such that both classes that we have styled, shall be included. The final HTML code should look like this:

Code:

<html>
<head>
<title>Padding color using CSS</title>
<link rel = "stylesheet" href = "padding.css">
</head>
<body>
<h2>Padding Color Demonstration</h2>
<p class="padding">This paragraph demonstrates background-clip for padding-box. Using this property, limits the background effect to the inside edge of the borders.</p>
<p class="content">This paragraph demonstrates background-clip for content-box. Using this property, limits the background effect to the content edges.</p>
</body>
</html>

Output: The output of the above code can be seen by saving this html file and opening it through a browser. It will look like this:

CSS Padding Color - 2

  • You can clearly see that when we use padding-box in background-clip, it stretches to the border edges, but in the case of content-box, it is limited to the content.

3. Padding color using background-clip, through Internal CSS

  • Since we are using internal CSS, we will directly code for the HTML file.
  • In the head section, we will style the element <p> within the <style> tag. Here only, we will define the background-clip to be limited to the padding-box. The styling can be as follows:

Code:

<style>
p{
font-size: 15px;
height: 200px;
width: 200px;
padding: 15px;
border: dotted black;
background-color: yellow;
color: blueviolet;
background-clip: padding-box;
font-family: Georgia, 'Times New Roman', Times, serif;
text-align: center;
}
</style>

  • Once the styling is done, we will move on to the body part and code for paragraph element <p>, such that defined style can be demonstrated.
  • The final HTML file should be coded for, as below:

Code:

<html>
<head>
<title>Padding color using Internal CSS</title>
<style>
p{
font-size: 15px;
height: 200px;
width: 200px;
padding: 15px;
border: dotted black;
background-color: yellow;
color: blueviolet;
background-clip: padding-box;
font-family: Georgia, 'Times New Roman', Times, serif;
text-align: center;
}
</style>
</head>
<body>
<h2>Padding Color Demo using internal CSS</h2>
<p>This example demonstrates padding color using internal CSS.</p>
</body>
</html>

Output: The same code when saved as an HTML file, and opened through a browser, will give the following output:

CSS Padding Color - 3

  • Hence, in the above few examples, we learned how to obtain colored padding for any element. This can be used to a developer’s advantage while styling for a particular requirement.

Recommended Articles

This is a guide to CSS Padding Color. Here we discuss an introduction to CSS Padding Color, how to obtain padding work, and examples. You can also go through our other related articles to learn more –

  1. CSS Gradient Generator
  2. CSS Text Outline
  3. CSS Overlay
  4. CSS Box Model

CSS Training (9 Courses, 9+ Projects)

9 Online Courses

9 Hands-on Projects

61+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
CSS Tutorial
  • CSS
    • Introduction To CSS
    • What is CSS?
    • Uses Of CSS
    • Advantages of CSS
    • Career In CSS
    • CSS Commands
    • Is Css Case Sensitive
    • CSS object-fit
    • Types of CSS Selectors
    • CSS Radio Button
    • CSS Attribute Selector
    • CSS first child of class
    • CSS Selector nth Child
    • CSS Parent Selector
    • CSS Child Selector
    • CSS Not Selector
    • CSS Descendant Selector
    • CSS Inline Style
    • Checkbox CSS
    • CSS Appearance
    • CSS Font Properties
    • CSS font-variant
    • CSS Pagination
    • CSS Table Styling
    • CSS Table Cell Padding
    • CSS Padding Color
    • CSS Text Formatting
    • CSS for Text-Shadow
    • CSS text-stroke
    • CSS text-indent
    • CSS Rotate Text
    • CSS Text Color
    • CSS Center Div
    • CSS Arrow
    • CSS Arrow Down
    • CSS offset
    • CSS Cursor
    • CSS Layout
    • CSS Grid Layout
    • Button in CSS
    • CSS Button Border
    • text-align in CSS
    • CSS Horizontal Align
    • CSS Position
    • CSS Box Sizing
    • CSS box-shadow
    • CSS Text Underline
    • CSS Text Outline
    • CSS Blinking Text
    • Text Decoration CSS
    • CSS Vertical Align
    • CSS Word Wrap
    • CSS Padding
    • CSS Font Color
    • CSS Color Generator
    • CSS Margin Right
    • CSS Margin Color
    • CSS Color Codes
    • CSS Color Transparent
    • CSS Color Chart
    • CSS Link Color
    • CSS z-index
    • CSS Curved Border
    • CSS Border Left
    • CSS left
    • CSS Gradient Generator
    • Radial Gradient in CSS
    • CSS Shape Generator
    • CSS Triangle Generator
    • CSS background-color
    • CSS Background Image
    • CSS background-clip
    • CSS background-blend-mode
    • CSS Drop Shadow
    • CSS line height
    • CSS line break
    • Sticky Footer CSS
    • CSS Header Design
    • CSS Border Style
    • CSS Border Generator
    • Sticky Sidebar CSS
    • CSS Transparent Border
    • CSS Border Radius
    • CSS translate
    • CSS transform
    • CSS 3D Transforms
    • CSS Text Transform
    • CSS Transition Effects
    • CSS Transition Property
    • CSS Animation Transition
    • Negative Margin CSS
    • CSS Navigation Bar
    • CSS Overflow
    • CSS overflow-wrap
    • CSS Lists
    • CSS list-style
    • CSS Order
    • CSS Box Model
    • CSS Inner Border
    • CSS Icon
    • Menu Icon CSS
    • CSS Multiple Borders
    • Opacity in CSS
    • CSS Float Right
    • CSS Clear Float
    • CSS clip
    • CSS disabled
    • CSS Border Padding
    • Border Images in CSS
    • CSS Visibility
    • CSS Validator
    • CSS Clearfix
    • CSS Counter
    • CSS Letter Spacing
    • CSS root
    • CSS zoom
    • CSS calc()
    • CSS.supports()
    • CSS Loader
    • Media Query CSS
    • CSS @keyframes
    • CSS @bottom
    • CSS page-break-after Property
    • CSS page-break
    • CSS Position Fixed
    • CSS skew()
    • CSS Row
    • CSS Masking
    • CSS Scrollbar
    • CSS Overlay
    • CSS Important
    • CSS Cursor Hand
    • CSS Inherit
    • CSS Position Relative
    • CSS Compressor
    • CSS tricks
    • CSS Outline Property
    • CSS Flexbox Properties
    • CSS flex-direction
    • CSS content property
    • CSS Typography
    • CSS Formatter
    • CSS nowrap
    • CSS Column
    • GridView CSS
    • CSS Viewport
    • CSS Minify
    • CSS Combinators
    • CSS in React
    • CSS Matrix 
    • CSS Pseudo Elements
    • CSS Pseudo Classes
    • CSS Pointer Events
    • CSS Resize
    • CSS Inheritance
    • CSS Interview Questions
    • Cheat Sheet CSS
  • CSS3
    • What is CSS3?
    • CSS3 Interview Questions
    • Cheat sheet CSS3
  • sass
    • How to Install SASS
    • SASS Interview Questions
    • What is Sass
    • SASS Comments
    • Sass Variables
    • SASS Import
    • SASS if else
    • SASS Nesting
    • SASS @each
    • SASS @at-root
    • SASS @extend
    • SASS @media
    • SASS @for
    • SASS Map
    • SASS Selectors
    • SASS Color Functions
    • SASS Mixins

Related Courses

CSS Training Course

Bootstrap Training Course

JQuery Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - CSS Training (9 Courses, 9+ Projects) Learn More