HTML Styles

In this tutorial, you will learn HTML Styles

The “style” attribute in HTML allows you to add inline styles to specific elements on a web page. Inline styles take precedence over styles defined in a separate CSS file, so they can be used to override the default styles for a specific element. Here’s a basic tutorial on how to use the “style” attribute in HTML:

To add a style to an HTML element, include the “style” attribute within the opening tag of the element. The value of the “style” attribute should be a string of CSS declarations. Each declaration should consist of a property and a value, separated by a colon, with a semicolon separating multiple declarations.

Here’s an example of how to change the text color and font size of a paragraph using the “style” attribute:

<p style="color: blue; font-size: 18px;">This is a sample paragraph</p>

You can also use the “style” attribute to apply styles to multiple elements of the same type at once. For example, the following code applies the same styles to all of the paragraphs in a web page:

<p style="color: blue; font-size: 18px;">This is the first paragraph</p>
<p style="color: blue; font-size: 18px;">This is the second paragraph</p>
<p style="color: blue; font-size: 18px;">This is the third paragraph</p>

You can also use the “style” attribute to add multiple styles to a single element like this :

<p style="color: blue; font-size: 18px; text-align: center;">This is a sample paragraph</p>

It is important to note that although the style attribute allows you to add styles to individual elements, it is considered less maintainable and scalable as it makes it harder to manage the overall design of a website. It is best practice to write CSS in a separate stylesheet because it makes the styling easier to manage and update.

The style attribute is useful in cases where you want to apply some temporary styling or override the styles defined in a CSS file for a specific element, but it is not recommended to use it as a primary way of styling a webpage.

Scroll to Top