how to make padding for text only in css
- User
how to make padding for text only in css
- Assistant
If you want to add padding that affects only the text inside an element, but not the element's background or border, pure CSS doesn’t have a direct property for that because padding applies to the entire element box.
However, here are some common approaches depending on what exactly you want:
1. Use
paddingon an inline element wrapping the textSince padding applies to the element’s box, you can wrap the text in an inline element (like a
<span>) and apply padding there.html<div style="background: lightgray; border: 1px solid black;"> <span style="padding: 5px; background: yellow;">This text has padding</span> </div>