Understand what CSS is and how to apply it to style HTML elements.
<style>), External (.css)CSS rules consist of a selector and a declaration block:
selector {
property: value;
property: value;
}
Element selector:
p {
color: blue;
font-size: 16px;
}
ID selector:
#main-title {
color: red;
}
Class selector:
.button {
background-color: green;
}
<p style="color: blue;"><style> tags in <head>.css file using <link rel="stylesheet" href="style.css">Try the following:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS Practice</title>
<style>
h1 {
color: darkblue;
font-family: Arial, sans-serif;
}
p {
color: gray;
font-size: 14px;
font-family: 'Times New Roman', serif;
}
.button {
background-color: green;
color: white;
padding: 10px 20px;
border: none;
cursor: pointer;
}
</style>
</head>
<body>
<h1 id="main-title">Welcome to CSS</h1>
<p>This is a paragraph styled with CSS.</p>
<button class="button">Click Me</button>
</body>
</html>