Core Concept of Applying Inline CSS in HTML
When you apply CSS styles to an element with the style attribute, it is known as inline CSS.
In this code:
- The style = “color:blue; margin-left:30px;” is used in <h1> tag as inline css
Why is it used?
- When you want to apply small-scale CSS to a particular element, then inline CSS is used.
- To apply CSS with the highest priority.
Real-life Applications
- Dynamic Style via JavaScript: When you want to change the runtime color, visibility, position, or anything about an element.
- HTML Email Templates: Most of the email clients (like Gmail, Outlook) don’t render external or internal CSS, so inline CSS is used.
- Quick Testing and Debugging: When testing the live CSS code, inline CSS is used by applying it to the targeted element inside the developer tools.
Key Benefits of this Program
- Highest Specificity: Inline CSS has the highest priority among external, internal, and inline CSS. So, if you want to apply any rule with the highest priority, the inline approach is best.
- Quick Step-up: No need to make a dedicated external file for small changes.
Limitations of this Program
- Code Maintenance Problem: Due to adding inline CSS to every single element, the code is very hard to maintain.
