With the help of sample code, highlight different methods to incorporate CSS code in an HTML webpage.

Methods to incorporate CSS code in an HTML webpage

There are three main methods to add CSS to an HTML page:

  1. Inline CSS: Using the style attribute within an HTML tag.
  2. Internal CSS: Writing CSS inside the <style> tag in the <head> section.
  3. 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.