How to use style tags in the body element with other HTML?

Spread the love

Sometimes, we want to use style tags in the body element with other HTML.

In this article, we’ll look at how to use style tags in the body element with other HTML.

How to use style tags in the body element with other HTML?

To use style tags in the body element with other HTML, we can put the style element in any element.

For instance, we write

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <div id="scoped-content">
      <style type="text/css" scoped>
        h1 {
          color: red;
        }
      </style>

      <h1>Hello</h1>
    </div>

    <h1>World</h1>
  </body>
</html>

to add a style element that’s in the div.

We add a scoped attribute to make the styles in the style element in the div only applied to the div.

Conclusion

To use style tags in the body element with other HTML, we can put the style element in any element.

Leave a Reply

Your email address will not be published.