How to create an icon for a series of Editing actions?

Hello,
Similar to the Font-Color icon to change text color, what is needed is to highlight text of interest, then click the icon on the top, and the highlight text are changed to expected color. I want to to change the background color (say grey) of a code blocks in the document, so that whenever there is code block, I highlight the code and click the icon to change the code text to grey so that all the code blocks are highlighted in the same grey color. How to create such a macro icon in LibreOffice (version 24.8.3.2 X86_64, Ubuntu 24.10 with Linux6.11).

The closest icon is the Font-highlight-color icon, which only change the font part, all remaining space are not changed. I want the whole block/line are uniformly in the same color.

Thanks a lot!

Create a character style for your code block. Apply the style to all your code blocks by selecting the text and double click the character style in the sidebar. After doing that, to change the colour of of your code block, just change the colour in the character style.
Sample below has a character style Source text, just right click on the character style in the sidebar, select Edit style and change the highlight colour in Highlight tab. There is also a paragraph style, Code which could be used instead if code is in separate paragraphs.
CodeHighlight.odt (33.4 KB)

.
Or maybe you want to use an extension like https://extensions.libreoffice.org/en/extensions/show/code-highlighter

Thanks! I need to try this extension.
But, an issue for this method for me is a Text Box need be created each time and copy-paste the code to the Text Box, then do the highlighting actions. Slow with too many “clicking”!

Normally I use the Format → Paragraph → Area → Color → (select intended color from palette dialogue, Good part is the recent colors are recorded by clicking the corresponding square) → OK. This still has too many “clicking”.

It seems a “Paragraph Style” macro icon is what I need, but I do not know the trick to create it. Thanks again.

What text box? I never suggested a text box. Definitely do not use a text box, it cannot use character or paragraph styles.

There is already an existing paragraph style, Preformatted text, that could be modified for use. And an existing character style, Source text.

If there is no direct formatting, or you clear it by selecting the text and pressing Ctrl+M, then a single change to the style will change all instances of that style in the document.
.
I feel that it would be best if you read, at least, the chapter on styles in the Writer Guide, download from English documentation | LibreOffice Documentation - LibreOffice User Guides

Sorry, I misunderstood you, have to go back to the Guide for sure.
Thanks again!