Understanding HTML Styles: A Comprehensive Guide
Ways to Apply Styles in HTML
1. Inline Styles
Example:
<p style="color: red; font-size: 20px;">This is a red-colored paragraph with a font size of 20px.</p>
Output:
This is a red-colored paragraph with a font size of 20px.
Pros:
- Quick and easy for styling individual elements.
- Useful for small changes or testing styles.
Cons:
- Can be difficult to manage and scale.
- Doesn't support reusability.
- Makes the HTML code messy and harder to maintain.
2. Internal Styles
<style>
tag, placed inside the <head>
section of the HTML document. This method allows you to apply styles to the entire document without needing an external stylesheet. It's useful for smaller websites or when specific styles are unique to that particular page.Example:
<head>
<style>
p {
color: blue;
}
</style>
</head>
<body>
<p>This is a blue-colored paragraph with a font size of 18px.</p>
</body>
Output:
This is a blue-colored paragraph with a font size of 18px.