How to add CSS?

QuestionsQuestions8 SkillsProYour First Linux LabOct, 01 2025
0119

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.

  1. Create a new CSS file named styles.css:

    touch styles.css
  2. Open styles.css in a text editor and add your CSS rules:

    body {
        background-color: lightgray;
    }
    h1 {
        color: blue;
    }
    p {
        font-size: 18px;
    }
  3. 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.

0 Comments

no data
Be the first to share your comment!