space after word can be given a bg color (space before word can)

I want to easily create leading and trailing space with the same background of a word.

(In the image, I want 1 instead of 2)

If I insert a space before the word, the background is the same as the word, but if I insert a space after the word a blank bg is created.

The clumsy workaround I use is to add any character after the word and color de character as the bg. It works until I save and open and colors get different shades and mess up.

Is there an solution?

Can I propose as an improvent that inserting immediately space after a word produces the same result as before a word?

Thanks
image description

I assume that you apply manually the background colour and this explains why you bump into this range extension/reduction problem. The correct way to deal with such situation is with styles, specifically character styles.

Why do you background colour a word (and its surrounding space)? What do you want to convey to the reader? Answers to these questions define a semantic meaning for the word (and more generally any sequence satisfying the definintion).

In such a situation, create a character style, give a mnemotechnic name and mark up the sequences. The marked range is precisely controlled; include the needed spaces in it.

The advantage of this method is the ability to change the background, highlight, font, sier, weight, … from the style definition and changes are immediately effective on all occurrences.

I let you explore the built-in help (and downloadable free manual) to learn how to configure styles.

To show the community your question has been answered, click the ✓ next to the correct answer, and “upvote” by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!

1 Like

…but if I insert a space after the word a blank bg is created.

That’s totally normal. Even if you change the font or font size of a word and you place the cursor directly after the word, it continues writing as before. This is not a mistake.
I suggest you first write your text and mark afterwards the word that should be formatted. For formatting, I would create a style.

image description

image description

Thanks to both. Obviously I use this type of highlighted text all the time for headings. What I have seen after your answers is that the background is applied as expected (both leading and traling spaces are highlighted) in paragraphs, headings, with single words or any other style BUT NOT within TABLE CELLS where I use different colors for schedules, charts, etc. and where the highlighted word needs a word following it. If you delete the word that follows, the highlighted space or spaces goes with it.
I checked that the style in both cases is the predefined one.

As for styles I don’t know how they work (I know I should) and never used them / needed them with MS Word either.

Thanks.

For styles you can read the “Writer Guide”.

You can also apply a style to the characters in a table.

Hi,
I’d like to re-open this topic, as the solution doesn’t work for me.

I made a new character style for highlighting some characters (background color). The aim is to highlight just one word on a page, but there is not enough colour around the word, I don’t want the colour to stop exactly at the end of the word. I applied this style to the word, and the space before and after this word.
As a result, I don’t have the trailing space with the color background, but with blank background ; only the space before is colored.
In the example shown as a GIF, I can see there are other characters after the space to color. In my case, the word is at the end of the line. I can’t have this final space colored. The initial workaround is necessary : adding any character after this space allow me to colour this space.

Finally, the problem is mainly : is it possible to define an area around the character to be colored ? It is possible with borders: I can define a space between the border and the character. How to do the same with the background ?

All the best,

As @ajlittoz mentioned:

In such a situation, create a character style, give a mnemotechnic name and mark up the sequences. The marked range is precisely controlled; include the needed spaces in it.

Since a border is required, it should be chosen in white so that it is not visible.



The space before the word “background” can then be omitted.
Select the color in the “Highlighingt” tab.
41040 HB Text CharacterStyleBackground


41040 HB CharacterStyleBackground.odt (10,0 KB)


With me:
Version: 26.8.0.3 (X86_64)
Build ID: bce0998afefdbc355585ca324285661a2170ba77
CPU threads: 16; OS: Windows 11 X86_64 (build 26200); UI render: Skia/Raster; VCL: win
Locale: de-DE (de_DE); UI: de-DE
Calc: CL threaded

Any problem with not getting the expected results when you apply a style suggests you have also direct formatting. The precedence rule is:

paragraph style overridden by character style overridden by direct formatting

Regarding your question about some extra highlighting before and after the word, you can solve this by adding Borders to your character style.

  • go to Borders tab
  • uncheck Synchronise box and set some Padding at Left and Right
  • define only vertical borders at left and right
  • in Line section, either set Color to white (or to page background colour) or to the same colour as your background highlighting (the latter has my preference because it does not create a constraint with the page style).

hi, thanks for fast answer,

It seems there’s a bug somewhere, or something I missed.
In the document I want to work with (say doc.odt) : it doesn’t work. Even with a dedicated character style, and even with the borders with some padding on left and right only set in the character style. I tried two things :

I did exactly the same as before in a new document (doc2) : it works. I can have trailing space with the same background color without any other character.
I copied the line from my document doc.odt to a new document doc3.odt : it works too.
I copied the style from doc.odt to other new documents : it works too.

So the problem is in my first document doc.odt : I don’t know what’s wrong. I removed all extra direct format (Ctrl+M) and set the paragraph style to default. There is no hierarchy in character style (I think) so I don’t know why there’s such a problem, but as it seems to be linked to one document, so I will start with a new document.

thanks for answer,
all the best,

If you want some detailed analysis, attach your document. No more than 3 pages please and make sure the problem is still present. Remove sensitive and personal data.

1 Like

Here an extract of the document. I tested on other computer, the problem remains.
The first line is with only trailing spaces → no color
the second is the same, with a final character (a dot) → color is ok

BTW in a new document, it seems there’s no need anymore to create a style : direct formatting with a color, then finishing the line with a space keeps the background color.
(I use LibreOffice 25.2.3.2 on linux)

document:
2026-09 for export.odt (13.0 KB)

Don’t use normal space!
Look in the Character Style “green” at Border Tab for “Padding” and “Line”.



41040 HB 2026-09 for export.odt (15,8 KB)

1 Like

many thanks for the document with the style, I will use this one for the document I’m working on :slight_smile:.

As I said, in a new doc, trailing spaces before line break, after a word with a background color (direct formatting, NO style) use the same background color : they are not left blank, and this doesn’t need any style:

How is it possible in a new doc, and not in my first document ?
The file odt:
with normal spaces.odt (10.0 KB)

all the best,

Your original document is in a special Word compatibility mode.


To revert to your expectation, go to Tools → Options, LO Writer → Compatibility and untick Word-compatible trailing blanks.


Remember that M$ Word tends to impose on you a “standardised” workflow designed by developers thnking that you are unable to write a “correct” document b yourself. They have implement many rules to “fix” your typing (not seeing that these rules are in fact fixes for the deficiencies in the poorly specified model). Among these rules is the abuse of spaces (excessive number of faulty spaces).