Inline Style in HTML - CSS Inline Styles
Inline Style in HTML - CSS Inline Styles
It
manages the colors, fonts, and layouts of your website elements, as well as allowing you to add effects
or animations to your pages.
We can style an HTML file/page in three ways: external styling, internal styling, and inline styling. In
this article, we'll be focusing on inline styling.
The style attribute works in the same way as any other HTML attribute. We use style, followed by
the equality sign (=), and then a quote where all of the style values will be stored using the standard
CSS property-value pairs - "property: value;".
Note: We can have as many property-value pairs as we want as long as we separate them with a
semicolon (;).
It's worth noting that the style attribute is typically used in the opening HTML tag because that's the
part of the HTML element that can contain text, data, an image, or nothing at all. An example of inline
style is as follows:
<h1 style="color: red; font-size: 40px;">Hello World</h1>
The only difference is that the inline style applies only to the tag to which it is applied, whereas this
second code example affects all p tags on your html page.
<body>
<p style="color: red;">Paragraph one is red.</p>
<p style="color: red;">Paragraph two is also red.</p>
</body>
</html>
The CSS from our inline styles will override the CSS from the internal styling, so both paragraphs will
be red.
Conclusion
In this article, we learned how to use inline style in HTML, when to use it, and some of the benefits and
drawbacks of doing so.
Since inline styling takes precedence over all other styles, one of the best times to use it is when testing
or previewing changes and performing quick fixes on your website.