Search code examples
htmlcolorshead

Coloring the head in html


Is it possible to color the head in an html file?

I tried doing the same thing you do to color the body, <body style="background-color:rgb(255, 255, 255);">. I did the same with the head, <head style="background-color:rgb(40, 40, 40) ;">. But I ran the file and it doesn't work.

-Any help is appreciated.

Disclaimer: I am a complete beginner when it comes to html.


Solution

  • You can, but it doesn't do you any good unless you cause the <head> to be rendered (it is, by default, display: none).

    document.title="Example"; // Setting the title with JS because this is a Stack Snippet which expects the HTML provided to go in the <body>
    head {
        display: block;
        background: pink;
    }
    
    title {
        display: block;
    }

    Generally speaking, there shouldn't be anything in the <head> that you should want to be rendered.

    It contains metadata about the document, not the document content itself.

    Consequently, this rarely makes any sense except as an exercise in proving that CSS can touch any bit of markup in a page.