# How to apply background color with css to text with line break

**URL:** <https://community.weweb.io/t/how-to-apply-background-color-with-css-to-text-with-line-break/14313>\
**Category:** How do I?\
**Tags:** css, custom-css, background-color\
**Created:** [November 2, 2024, 1:58pm UTC](https://community.weweb.io/t/how-to-apply-background-color-with-css-to-text-with-line-break/14313 "2024-11-02T13:58:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Knight](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@Michael\_Knight](https://community.weweb.io/u/Michael_Knight)\
**Post date:** [November 2, 2024, 1:58pm UTC](https://community.weweb.io/t/how-to-apply-background-color-with-css-to-text-with-line-break/14313/1 "2024-11-02T13:58:19Z")

</div>

Hi!  
I would like to create a text background that is just behind the text even when the line breaks, like this:

 ![image 842](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/e/e6e7a6e9e09d37ee2ce363d5e170261f77cae3bd.png)

I found a solution on stackoverlfow but I am not able to make it work in WeWeb:

> <https://stackoverflow.com/questions/34719894/how-to-apply-background-color-with-css-to-text-with-line-break>

> **[Edit fiddle - JSFiddle - Code Playground](https://jsfiddle.net/og90214y/6/)**
>
> JSFiddle - Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle.

I copied the following code from stackoverflow to the custom CSS of my heading in Weweb:  
background: #f00 none repeat scroll 0 0;  
box-decoration-break: clone;  
-webkit-box-decoration-break: clone;  
color: #fff;  
display: inline;  
font-weight: 300;  
line-height: 1.4;  
margin-bottom: 10px;  
padding: 0 45px;

But it again makes the background spread the whole textbox instead of seperating lines and stopping at the end of the last word of each line.

---

<div class="post-metadata">

**Author:** ![Yaj](https://avatars.discourse-cdn.com/v4/letter/y/eb8c5e/32.png) [@Yaj](https://community.weweb.io/u/Yaj)\
**Post date:** [November 4, 2024, 9:56am UTC](https://community.weweb.io/t/how-to-apply-background-color-with-css-to-text-with-line-break/14313/2 "2024-11-04T09:56:59Z")

</div>

Just tried it out this isn’t looking exactly like you want but just wanted to see if it’s possible so you’ll have to mess around with the settings a bit to get it like that but first

![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/c/c4fcc7b6feaf29dc2e7d0a27b6d3af371f0a5e2a.png)

Get a div and make it a block

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/d/db0f24b5931f62b1093a41fa53945c6b137c0d2d.png)

Add the first css to this element

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/5/538e825b3413a51919bbaa7a63a2587e83f2888d.png)

Then put a text box inside this element like in the first photo and add that second bit of css to the text element

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/c/c1933b9f5fb6ab4d0b3bc26146cf0e60401e38fc.png)

Should get you this result, I did mess around with other settings but I think as long as you do a div that is a block with some text inside it should work then just play around with the design to get the desired effect.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/3/37d79f78198b89fdd5722d2d6937d1bde8fce81a.png)

I made the width of the div fixed as well just so it works

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/c/c205dac98b0aeb72bfa1616e894df3b876589df0.png)

Also i couldn’t see what I was typing when I done this which I wasn’t sure why but just be aware that you might have to copy and paste it or something

---

<div class="post-metadata">

**Author:** ![Michael\_Knight](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@Michael\_Knight](https://community.weweb.io/u/Michael_Knight)\
**Post date:** [November 4, 2024, 9:25pm UTC](https://community.weweb.io/t/how-to-apply-background-color-with-css-to-text-with-line-break/14313/3 "2024-11-04T21:25:15Z")

</div>

Thank you very much Yaj!!! ❤  
Thanks to you I could solve it!!! ❤

What it solved for me was creating the div block and then placing the text component inside it, like you said.  
On the div block I didn’t even need special css.

On the text component I added this css:

```auto
background: #f00 none repeat scroll 0 0;
box-decoration-break: clone;
display: inline;
padding: 0 16px;

```

I then increased the line-height of the text component to add space between the background color of each line.

This is the result 🙂

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/1/198d8e3997d0a2429e25061af4bc2a68ddb324c6.png)

---

<div class="post-metadata">

**Author:** ![Yaj](https://avatars.discourse-cdn.com/v4/letter/y/eb8c5e/32.png) [@Yaj](https://community.weweb.io/u/Yaj)\
**Post date:** [November 5, 2024, 12:19am UTC](https://community.weweb.io/t/how-to-apply-background-color-with-css-to-text-with-line-break/14313/4 "2024-11-05T00:19:32Z")

</div>

Glad I could help!
