• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

CSS hover effect not working with <span></span>


Well-Known Coder
Hey there:blush::blush:

I want to make hover effect on my h1 headlines, but it does not work with the <span></span>. It works fine if the header is just wrapped in <h1></h1>, but I need the <span></span> in order for the background color on the header to wrap correctly.

any ideas?

[CODE lang="css" title="hover effect not working" highlight="26"]<!DOCTYPE html>


body {
margin-top: 50px;
color: rgb(184, 170, 140);

.textfield {
color: rgb(239, 61, 74);
line-height: 55px;
margin-left: 200px;
font-size: 25px;
line-height: 1.2;
.textfield span {
background-color: rgb(38, 102, 145);
color: rgb(253, 103, 73);
display: inline;
font-family: "JetBrains Mono", Sans-serif;
text-align: right;

.textfield span:hover {
color: green;

p {
font-family: "JetBrains Mono";
margin-right: 150px;
margin-left: 200px;
line-height: 1.5;


<h1 class = "textfield"> <span> #1 TEST. This is a test to see if the hover effect works. </span></h1>

<p>This is a paragraph</p>

<h1 class = "textfield"> <span> #2 TEST </span></h1>

<p> This is a paragraph </p>




New Threads

Latest posts

Buy us a coffee!

Top Bottom