HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
  • Insights
  • Verify Certificate
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials

HTML5andCSS3.org helps developers learn modern frontend skills with practical tutorials, production-ready snippets, and fast web tools built for everyday coding.

Quick Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Copyright
  • Disclaimer

Top Tools

  • Try It Editor
  • JSON Formatter
  • CSS Minifier
  • HTML Minifier
  • Base64 Encoder / Decoder

Contact

  • business@html5andcss3.org
Newsletter

Learn at your own pace, practice with useful tools, and build websites you're proud of.

© 2011-2026 html5andcss3.org. All rights reserved.

How to Use

CSS Tutorial

CSS Introduction

What is CSSCSS SyntaxHow to Add CSSCSS Comments

CSS Foundations

Cascade & InheritanceCSS SpecificityCSS UnitsBox SizingCSS VariablesCSS Math Functions

CSS Selectors

CSS Element SelectorCSS Class SelectorCSS ID SelectorCSS Universal SelectorCSS Group SelectorCSS CombinatorsCSS Attribute SelectorsCSS Pseudo ClassesCSS Pseudo Elements

CSS Colors and Backgrounds

CSS ColorsCSS HEX ColorsCSS RGB ColorsModern ColorsCSS Background ColorCSS Background ImageLayered Backgrounds

CSS Text & Fonts

CSS Text ColorCSS Text AlignmentCSS Text DecorationCSS Font FamilyCSS Font SizeWeb Fonts & TypographyText Wrapping

CSS Box Model

CSS MarginCSS PaddingCSS BorderCSS OutlineCSS Width and Height

CSS Layout

Normal FlowCSS DisplayCSS PositionAnchor PositioningCSS FloatCSS OverflowCSS Z-indexIntrinsic SizingAspect Ratio & Object FitMulti-column Layout

CSS Flexbox

Flex ContainerFlex DirectionJustify ContentAlign ItemsFlex WrapFlex Item Sizing

CSS Grid

CSS Grid ContainerCSS Grid ColumnsCSS Grid RowsCSS Grid GapCSS Grid Layout ExampleGrid PlacementGrid AreasCSS Subgrid

CSS Lists, Tables & Forms

CSS ListsCSS TablesCSS Form StylingCSS Input Fields

CSS Effects

CSS ShadowsCSS GradientsCSS FiltersCSS OpacityClipping & MaskingBlending & BackdropScroll Snap

CSS Animations & Transitions

CSS TransformCSS 2D TransformCSS 3D TransformCSS TransitionsEntry & Exit TransitionsCSS AnimationsScroll AnimationsView TransitionsMotion Paths

CSS Responsive Design

CSS Media QueriesResponsive LayoutMobile First DesignContainer QueriesPreference Media QueriesFeature Queries

Modern CSS Authoring

Cascade LayersNesting & ScopeLogical PropertiesGenerated Content

CSS Accessibility

Accessible CSSCSS ThemingModern Form StylingCSS User Interface

CSS Output & Performance

Print StylesCSS PerformanceCSS ArchitectureDebugging CSS

CSS Reference

CSS At-rulesCSS FunctionsCSS Tutorial PDF

CSS Projects

Responsive CSS Project
  1. Home
  2. /
  3. Tutorials
  4. /
  5. CSS Tutorial
  6. /
  7. How to Add CSS

CSS Introduction

How to Add CSS

Compare inline, internal, and external CSS, then choose the method that keeps styles reusable, cacheable, and maintainable.

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. The supporting concepts are explained in CSS Syntax and CSS Element Selector.

html

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

2. Internal CSS

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

html

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

3. External CSS

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

html

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

styles.css file

css

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

Choose a maintainable source

External stylesheets are usually the best default because multiple pages can share and cache them. Internal styles are useful for isolated documents or critical page-specific rules. Inline styles have the narrowest reuse and interact with the cascade at high priority, so reserve them for values genuinely supplied by the element or application rather than routine component styling.

Complete Example

html

<!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>

Browser Support

Feature
Chrome
Edge
Firefox
Safari
CSS stylesheets11211

Versions show the first stable desktop release with unprefixed support. Data source: MDN Browser Compatibility Data 8.0.8.

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.

PreviousCSS SyntaxNextCSS Comments