To add CSS to your HTML file, you can use one of the following methods: inline styles, internal styles, or external styles. Here’s how to do each:
1. Inline Styles
You can add CSS directly to an HTML element using the style attribute.
<h1 style="color: blue;">Welcome to Your First HTML Page!</h1>
2. Internal Styles
You can include CSS within a <style> tag in the <head> section of your HTML document.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Your First HTML Page</title>
<style>
body {
background-color: lightgray;
}
h1 {
color: blue;
}
p {
font-size: 18px;
}
</style>
</head>
<body>
<h1>Welcome to Your First HTML Page!</h1>
<p>This is a simple HTML document created using the terminal.</p>
</body>
</html>
3. External Styles
You can create a separate CSS file and link it to your HTML document.
-
Create a new CSS file named
styles.css:touch styles.css -
Open
styles.cssin a text editor and add your CSS rules:body { background-color: lightgray; } h1 { color: blue; } p { font-size: 18px; } -
Link the CSS file in the
<head>section of your HTML document:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Your First HTML Page</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<h1>Welcome to Your First HTML Page!</h1>
<p>This is a simple HTML document created using the terminal.</p>
</body>
</html>
Choose the method that best fits your needs! If you have any questions or need further assistance, feel free to ask.
