Methods to incorporate CSS code in an HTML webpage
There are three main methods to add CSS to an HTML page:
- Inline CSS: Using the
style
attribute within an HTML tag. - Internal CSS: Writing CSS inside the
<style>
tag in the<head>
section. - External CSS: Linking to an external
.css
file.
Example Code:
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<title>CSS Methods</title>
<!– Internal CSS –>
<style>
h1 {
color: blue;
text-align: center;
}
</style>
<!– External CSS (link to external file) –>
<link rel=”stylesheet” href=”styles.css”>
</head>
<body>
<!– Inline CSS –>
<h1 style=”color: red;”>This is a Heading with Inline CSS</h1>
<h1>This is a Heading with Internal CSS</h1>
</body>
</html>
In this example, you can see how to use inline, internal, and external CSS.