Card: Linking CSS

Linking CSS

The Art of Bundling Your Styles

CSS can be integrated into your website in different ways, each with its own charm. The external stylesheet is the wise librarian among the options. It stores your CSS rules in a separate file and manages them centrally for multiple pages. This keeps everything tidy and speeds up your website’s loading time.

Then there’s inline CSS, perfect for quick tweaks when you just want to polish up a corner. On the other hand, internal CSS, nested in the head section, acts like a handy toolbox for individual pages. Choose wisely, as the right method can save you headaches and ensure your website doesn’t look like someone threw paint in the dark.

Link your CSS

Some magical rules you should know

Token: internal integration of a CSS rule

Internal Styling

A Quick Spell for In-Between Moments

Sometimes, a short spell is all you need to place your CSS styles directly in the head section of your webpage. Perfect for spontaneous ideas or quick tests. You open the <style> tag, add your magic, and close it again. Done! But beware: this spell is only for fleeting moments. For long-term magic, rely on external CSS files to keep your work organized and clean.

<head>
    <style>
        body {
            font-family: system-ui;
        }
    </style>
</head>
Token: inline embedding a CSS rule

Inline Styling

Only for Special Cases

Occasionally, you might need a quick trick to enchant an element directly without summoning an entire file. This is where inline styling comes into play. Using the style attribute, you can immediately give an element a stylish transformation. But caution: as with any spell, don’t overdo it! Adding too many styles directly into your HTML can quickly become messy and hard to manage.

    <body>
        <h1 style="color:purple;">Tinkerville</h1>
    </body>
Token: external inclusion of a CSS rule

External Styling

The Best Comes Last

In the head section of your webpage, you place a powerful link pointing to your CSS file. This file, with its magical .css extension, contains all your stylistic masterpieces. External styling is the most elegant way to separate structure from style, keeping your web creation clear and efficient.

<head>
    <link rel="stylesheet" href="css/style.css">
</head>

Why External Styling is Essential

Reusability

With a single stylesheet, you can enchant multiple HTML pages. One spell, endless uses—it saves time and energy.

Easy Maintenance

Make changes in the stylesheet, and—poof—your entire design is updated. Practical, isn’t it?

Faster Load Times

The browser loads the CSS once and stores it, enabling future visits to your site in the blink of an eye.

Flexibility

Want to change the design? No problem! With an external stylesheet, you can effortlessly try different styles without rewriting your entire website.

Clarity

By separating HTML and CSS, your code remains clean and readable. This prevents your work from turning into a tangled mess of characters.

Consistency

With a dedicated stylesheet, you ensure consistent styles across all pages—like a wizard leaving the same mark everywhere.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Linking CSS</title>
    <!-- Internal CSS -->
    <style>
        body {
            background-color: lightgreen;
        }
    </style>
    <!-- External CSS -->
    <link rel="stylesheet" href="css/05-style.css">
</head>

<body>
    <!-- Inline CSS -->
    <p style="color: blue;">set the text color to blue</p>
</body>

</html>
CSS
body {
    background-color: cornsilk;
}
Scroll to Top