Hide copy to clipboard button in markdown

I have a button copy to clipboard. All code boxes in markdown are displayed with the copy to clipboard button. But if I have a code box with text only, then the button is not needed. .text copy-code-button:none does not work. How can I hide the butten?

The result should be:

This should be the code box without the button
This should be a code box without the button
/* Copy to clipboard */
.copy-code-button {
	color: var(--bs-black);
	background-color: var(--bs-gray-200);
	border: 1px solid var(--bs-secondary);
	border-top-right-radius: 4px;
	z-index: 1;
	position: relative;
	display: block;
	margin-bottom: -26px;
	margin-left: auto;
	margin-right: 3px;
	font-size: 0.8em;

.copy-code-button:hover {
	cursor: pointer;
	background-color: var(--bs-gray-500);

.copy-code-button:active {
	background-color: var(--bs-gray-400);

.text copy-code-button {
	display: none !important;

The Output is:


That’s a CSS issue. The simplest approach to solving it is to use the developer tools of your favorite browser and see how this text-only cover is represented in HTML. Probably there’s no class text. And

Is not valid CSS anyway.

Keep in mind, that hugo per default does not add a copy button.

Supposedly these .code… classes are added by a code block render hook.

Check your theme. You can adapt the generic hook to not add the class for text or create a special one for text only

1 Like