A question about id and class

I just wonder why “Hello World” turns into green when I just write:
** id= before classes**

body {
  background-color: black;
  font-family: monospace;
  color: green;
.pink-text {
  color: pink;
.blue-text {
  color: blue;
<h1 id= class="pink-text blue-text">Hello World!</h1>

Hey @heisenberq,

  • Next time you want to showcase a code, use the ``` backtick so it is easier for everyone to read.
    See this post to find the backtick on your keyboard.
    The “preformatted text” tool in the editor (</>) will also add backticks around text.
  • Currently I can’t really understand what you are asking?

i assume that id selector <element id="some-id"> which is in css #some-id will overide the <element class="some-class"> in css .some-class

anywhere it placed i.e :
<element class="some-class" id="some-id">

the id selector win

Oh…That is how you do that! Thank you!

I have edited it according your explanation. Thanks.
I would just add an id for white color. But I just noticed that before I have written id=“white” and I just wrote that: id=
and the text has turned into green even though there wasn’t any green input…

It is incorrect syntax and will break the class otherwise applied. So you are just left with the styles applied to the body, which is the green color for all text.

1 Like

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

Please use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks are not single quotes.


1 Like

I am sorry it is first time that I ask. Thanks for your edit. Next time I will keep it in mind.