💡 Tip: Login now to track your course progress and unlock your downloadable certificates instantly!

How to Add CSS

CSS can be added to HTML documents in different ways to style web pages. Choosing the right method depends on the project size and requirements.

There are three main ways to add CSS:

  • Inline CSS
  • Internal CSS
  • External CSS

Each method has its own use case and advantages.

Syntax

1. Inline CSS

Applied directly inside an HTML element using the style attribute.

<p style="color: red;">This is a paragraph.</p>

2. Internal CSS

Defined inside the <style> tag within the <head> section.

<style>
    p {
        color: blue;
    }
</style>

3. External CSS

Written in a separate .css file and linked to HTML.

<link rel="stylesheet" href="styles.css">

styles.css file

p {
    color: green;
}

Attributes

MethodDescriptionUsage Level
Inline CSSApplied directly to individual elementsSmall changes
Internal CSSDefined within the same HTML fileSingle page design
External CSSStored in separate file and reusedLarge projects
Complete Example
<!DOCTYPE html>
<html>
<head>
    <title>How to Add CSS</title>

    <!-- Internal CSS -->
    <style>
        h1 {
            color: blue;
        }
    </style>

    <!-- External CSS -->
    <link rel="stylesheet" href="styles.css">

</head>
<body>

    <!-- Inline CSS -->
    <p style="color: red;">This is inline CSS</p>

    <h1>This is internal CSS</h1>

    <p>This is external CSS</p>

</body>
</html>

Output

Browser Output

  • First paragraph will appear in red color (inline CSS)
  • Heading will appear in blue color (internal CSS)
  • Second paragraph will appear in green color (external CSS, if styles.css is linked properly)

Browser Support

Chrome
Chrome
Firefox
Firefox
Edge
Edge
Safari
Safari
Opera
Opera
IE
IE9+
✅Yes✅Yes✅Yes✅Yes✅Yes✅Yes

Notes

  • Inline CSS has the highest priority
  • Internal CSS is useful for single-page styling
  • External CSS is the best practice for large websites
  • External CSS improves performance and maintainability
  • Multiple CSS methods can be used together, but priority rules apply

Conclusion

Understanding how to add CSS is essential for controlling the appearance of web pages. While all three methods are useful, external CSS is the most recommended approach for scalable and maintainable web development.

Sign In Form

User your email and password to singn in

Don’t have an account, signup here : 

HTML5 & CSS3

Tools and Tutorials

Want a Website

Want a website for your business ?

Please fill out the details below, so we can reach out to you.

Registration Form

Signup to track your record and much more.

We have sent you an email with a registration link. Please click the link to verify your email address, or enter the 6-digit OTP provided in the email.

Didn't receive the OTP. Regenerate OTP Resend