Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add style elements to semantic tags?

Is it ok to add css styles to semantic elements like

<article style="font-size:1.2em; color:#ccc>text text </article>

or will this get me into trouble and should I use

<div style="font-size:1.2em; color:#ccc>  
<article>text text </article>
</div>
like image 204
Paulcraey Avatar asked Oct 15 '25 16:10

Paulcraey


2 Answers

It is much better to use classes rather than hard-coding styles into your HTML. This allows separation of content from presentation, and makes it much easier to make changes. So I would recommend something like

.article {
    font-size:1.2em; 
    color:#ccc;
}

and

<article class="article">text text </article>
like image 72
WahhabB Avatar answered Oct 17 '25 10:10

WahhabB


Yes, as long as its an HTML/HTML5 tag, you can definitely add classes or styles to semantic HTML elements.

You can refer below links for a list of new semantic elements in HTML5.

  • https://www.w3schools.com/html/html5_new_elements.asp
  • http://www.tutorialrepublic.com/html-reference/html5-tags.php
like image 37
Rhythm Ruparelia Avatar answered Oct 17 '25 10:10

Rhythm Ruparelia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!