HTML structures your content, but CSS defines how it looks. You can control text size, color, background, layout, and more using CSS.
Add the style attribute directly to an HTML element:
<p style="color: blue;">This text is blue.</p>Internal styles are defined in a <style> block inside the <head>:
<head>
<style>
h1 {
color: purple;
}
</style>
</head>External CSS is stored in a separate .css file. Link it inside the <head>:
<link rel="stylesheet" href="styles.css">Steps to use an external CSS file:
styles.css.note {
background-color: #f5f5dc;
padding: 10px;
border-left: 4px solid #999;
}Then import it into your HTML:
<link rel="stylesheet" href="styles.css">Use class selectors to style multiple elements and ID selectors for unique ones:
<p class="note">Note paragraph</p>
<p id="summary">Summary paragraph</p>.note {
color: darkblue;
}
#summary {
font-weight: bold;
}Create a styles.css file with the following:
.note {
background-color: yellow;
font-size: 16px;
}Then apply it in your HTML:
<link rel="stylesheet" href="styles.css">
<p class="note">This is a styled note paragraph.</p>Ask the AI if you need help understanding or want to dive deeper in any topic