Why isn’t my body CSS selector applying?
Asked by
reamPass-B
I'm new to CSS and can't figure out why my styles apply when I use the universal selector (*) but stop applying when I target the body element directly. My CSS currently looks like this:
body {
font-family: Helvetica;
font-size: 22px;
color: seashell;
background-color: black;
opacity: 0.9;
text-align: center;
}
All of my HTML content appears to be inside the body element. Is there something wrong with the selector, my HTML structure, or possibly my editor setup?
Answers
There’s nothing inherently wrong with targeting body. Try reducing the example to a complete HTML file and verify that the stylesheet link is inside the head, for example: . Also make sure the page contains actual content while testing. A full working example makes it much easier to spot a malformed tag, incorrect file path, or CSS rule that comes later and replaces these styles.
Reply to this answer
That body selector is valid, so the problem is probably elsewhere. Open your browser’s developer tools, select the body element, and check the Styles panel. If the rule appears crossed out, another rule is overriding it—often a later rule, an inline style, or a more specific selector. If the rule doesn’t appear at all, make sure the CSS file is actually linked and loaded; check the browser’s Network or Sources panel for a missing stylesheet.
Reply to this answer
Add your answer
Answers are reviewed before publication.
reamPass-B: I’ll inspect the body element in the browser tools and check whether the stylesheet is loading. I’ll also compare the full HTML and CSS for another rule that might be overriding it.