How to Add CSS

There are 3 ways to apply CSS to HTML elements. These are:

  • Inline CSS: Uses the style attribute in HTML elements.
  • Internal CSS: Uses a <style> element in the <head> section.
  • External CSS: Uses an external CSS file.

Inline CSS:

Uses the style attribute to apply CSS to a single HTML element.

Example:

<h1 style="color:crimson;font-style: italic;">Hello World!!</h1>

Internal CSS:

Uses a <style> element in the <head> section to apply CSS to a single HTML page.

Example:

<style>
h1 {background-color: crimson; color: white;}
p {color: crimson;font-size: 25px;font-style: italic;}
</style>

External CSS:

Uses an external CSS file to apply CSS to multiple HTML pages.

Example:

<link rel="stylesheet" href="styles.css">

style.css:

h1 {
background-color: crimson;
color: white;
}
p {
color: crimson;
font-size: 25px;
font-style: italic;
}