Ways CSS Can Be Added to HTML
CSS (Cascading Style Sheets) is used to style HTML elements. It can be added to HTML in three
main ways:
1. Inline CSS
CSS is written directly inside an HTML element using the 'style' attribute.
Example:
<p style="color: blue; font-size: 16px;">This is a paragraph with inline CSS.</p>
2. Internal CSS
CSS is written within a <style> tag inside the <head> section of the HTML document.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
h2 {
color: green;
</style>
</head>
<body>
<h2>This is styled using Internal CSS</h2>
</body>
</html>
3. External CSS
CSS is written in a separate file (e.g., style.css) and linked to the HTML document using a <link>
tag.
HTML File:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>This is styled using External CSS</h2>
</body>
</html>
style.css:
h2 {
color: red;
text-align: center;