-1

In css, what's the difference of two selector: * and html?

*{

}

and

html{

}

Do these two work differently?

kathy
  • 319
  • 6
  • 16

1 Answers1

1

the *{} selects all elements and all it's children elements where html{} only selects the <html> element

See example

html {
    border: solid 2px orange;
}

* {
    border: solid 2px green;
    font-size: 1.2em;
}
<ul>
  <li>one</li>
  <li>two</li>
  <li>three
  <ul>
    <li>one</li>
    <li>two</li>
    <li>three</li>
  </ul>
  </li>
</ul>

<p>lorem ipsum</p>

Now see even how the font gets bigger cause its em which will take the size from the previous element.

caramba
  • 21,282
  • 18
  • 84
  • 125