'How to select a HTML tag with a specific class? [duplicate]

I need to apply some css styles to a tag with a specific class, for example I need to select article tag with news class.

<article class="news" >
  <div>some stuff</div>
</article>


Solution 1:[1]

You can do it this way with CSS:

article.news{
  /* add styles below */
}

You can do it this way with JavaScript:

let articleNews = document.querySelector("article.news");
// for example
articleNews.style.color = "red";

Solution 2:[2]

Select and style all elements with class="news":

syntax:

.class {
  css declarations;
} 

for example

.news{
  background-color: yellow;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 madaraUchiha