1. Inline CSS (Inside HTML Elements)
This method applies styles directly within the HTML tags using the ‘style
‘ attribute.
Inline CSS Example
Hello, World!
This paragraph is styled using inline CSS.
2. Internal CSS (Inside the 'style' Tag)
This method places CSS styles inside the <style>
tag within the <head>
section of the HTML document.
Internal CSS Example
Welcome to My Website
This paragraph is styled using internal CSS.
3. External CSS (Using a Separate .css File)
This method links an external .css
file to the HTML document.
HTML (index.html):
External CSS Example
External CSS Example
This paragraph is styled using an external CSS file.
CSS (style.css):
body {
background-color: lightgray;
text-align: center;
font-family: Arial, sans-serif;
}
h1 {
color: navy;
}
p {
font-size: 18px;
color: darkslategray;
}
4. CSS Classes and IDs
Classes and IDs allow you to apply styles selectively.
CSS Classes and IDs
This is a highlighted heading
This paragraph shares the same class.
This paragraph has a unique ID and different styling.
5. CSS Hover Effect
This example changes the color of a button when the mouse hovers over it.
CSS Hover Effect