CHAPTER 4

CSS How To

CSS can be added to HTML in three common ways: inline CSS, internal CSS and external CSS.

01. What is CSS How To?

Inline CSS is written directly inside an HTML style attribute.
Internal CSS is written inside a style element in the HTML head.
External CSS is written in a separate .css file.
External CSS is useful when the same styles are used across multiple pages.

02. Syntax

<!-- Inline CSS --> <p style="color: blue;"> Hello </p> <!-- Internal CSS --> <style> p { color: blue; } </style> <!-- External CSS --> <link rel="stylesheet" href="style.css" >

03. Example

CSS / HTML Example AIFA Coding Lab
<!DOCTYPE html>
<html>

<head>

    <title>CSS How To</title>

    <style>

        .internal {
            color: blue;
            font-size: 20px;
        }

    </style>

</head>

<body>

    <p style="color: red;">
        Inline CSS
    </p>

    <p class="internal">
        Internal CSS
    </p>

    <p class="external">
        External CSS can be connected
        using a stylesheet.
    </p>

</body>

</html>

04. Important Points

✓ Inline CSS affects a specific element.
✓ Internal CSS is useful for page-specific styling.
✓ External CSS allows styles to be reused across pages.
✓ The link element connects an external stylesheet.

05. Common Mistakes

⚠ Using the wrong stylesheet path.
⚠ Forgetting rel="stylesheet".
⚠ Editing the wrong CSS file.

06. Real World Use

Professional websites commonly use external stylesheets so the same design system can be reused across many pages.

Ready to Practice? 🚀

Open the AIFA CSS Editor and practice this chapter live.

Try It Yourself →
Practice Exercise

Try Three CSS Methods

Create three paragraphs and demonstrate inline, internal and external CSS concepts.