How can I specify the first p element of each li tag belongs to the same class without doing it manually (in the case there are too many li tags in the ul element), as we know that :first-child pseudo-class only applies style attribute for element, not class attribute?
<ul>
<li>
<p>...</p>
<p>...</p>
</li>
<li>
<p>...</p>
<p>...</p>
</li>
</ul>
You can use
li > p:first-childas selector in the CSS:If you really want to add a class to those elements then you can use JavaScript for it and the
classList.add()function: