HTML Styles with CSS refer to how you visually format and design HTML elements using CSS (Cascading Style Sheets). CSS allows you to control the appearance of content — such as colors, fonts, spacing, and layout — separately from the structure of the HTML itself.
There are three main types of CSS used to style HTML: Inline, Internal, and External. Each has its own use case depending on how and where you want to apply styles.
Types of CSS
1. Inline CSS
Definition: CSS is written directly inside an HTML element using the style attribute.
Example:
<!DOCTYPE html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<p style="color: red; font-size: 18px;"> This is inline styled text. </p>
</body>
</html>
Output
✅ Used for quick, one-time styling of individual elements.
2. Internal CSS
Definition: CSS is placed within a <style> tag inside the <head> of the HTML document.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
h1
{
color:blue;
font-family:Arial;
}
</style>
</head>
<body>
<h1> This is styled with internal CSS </h1>
</body>
</html>
Output
✅ Useful for applying styles to a single HTML file.
3. External CSS
Definition: CSS is written in a separate .css file and linked to the HTML document using <link>.
Example:
HTML (index.html):
<head>
<link rel="stylesheet"href="styles.css"
</head>
Output
CSS (styles.css):
body
{
background-color:#f4f4f4;
}
p
{
color:green;
font-size:16px;
}
Output
✅ Best for styling multiple pages and maintaining clean code.