CSS describes how HTML elements look on screen, paper, or other media. This guide covers the fundamental ways to add CSS to your pages and the core techniques for styling text, backgrounds, borders, layouts, and animations.
01
Inline
style attr.
02
Internal
<style> tag.
03
External
.css file.
04
Text
Fonts & color.
05
Layout
Flex & Grid.
06
Motion
Animations.
Fundamentals
Introduction
CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation of documents written in HTML or XML. It defines how HTML elements should be displayed on the screen, on paper, or in other media.
This page covers the fundamental ways of using CSS to style web pages effectively — from adding your first color to building responsive layouts.
💡
Beginner Tip
Every CSS rule follows selector { property: value; }. Start with a <style> block in your HTML <head>, target an element like p, and set color: blue; to see instant results.
Foundation
📝 How to Add CSS to HTML
There are three primary ways to include CSS in your HTML documents:
1. Inline CSS
Add styles directly to an HTML element using the style attribute. Quick for one-off changes, but hard to maintain on large sites.
inline.html
<pstyle="color: blue;">This is a blue paragraph.</p>
2. Internal CSS
Write CSS inside a <style> tag in the <head> section. Good for single-page demos and learning.
internal.html
<head><style>p{color:red;}</style></head>
3. External CSS
Link a separate .css file from your HTML. This is the standard approach for real websites — one stylesheet can style many pages.
transition animates the background change over 0.5 seconds when you hover. :hover is a pseudo-class that applies styles on mouse-over.
Tips
💬 Usage Tips
Start internal, go external — Learn in one file, then split CSS into styles.css.
Use semantic HTML — Style h1, p, nav rather than only divs.
Inspect in DevTools — Right-click any element and choose Inspect to see applied CSS.
Group related rules — Keep typography, layout, and component styles in logical sections.
Link to deeper guides — Explore Flexbox and Grid tutorials once basics feel comfortable.
Watch Out
⚠️ Common Pitfalls
Specificity issues — Overusing !important creates conflicting styles that are hard to debug.
Neglecting browser compatibility — Check support for newer properties; most basics work everywhere.
Mixing too many units — Combining px, em, and % carelessly can cause unexpected sizing.
Inline styles everywhere — Makes updates painful; use classes and external files instead.
Forgetting the semicolon — Every declaration needs property: value; with a trailing semicolon.
A11y
♿ Accessibility
Color contrast — Ensure text is readable against backgrounds (WCAG contrast ratios).
Don’t rely on color alone — Use icons, labels, or patterns alongside color cues.
Focus styles — Keep visible outlines on interactive elements for keyboard users.
Readable font sizes — Avoid tiny text; use relative units like rem for scalability.
Motion preferences — Respect prefers-reduced-motion for users who disable animations.
🧠 How CSS Styling Works
1
HTML provides structure
Tags like p, div, and h1 define content and semantics.
HTML
2
CSS rules target elements
Selectors match HTML elements; declarations set visual properties.
Selectors
3
Browser applies the cascade
Multiple rules resolve by specificity, source order, and importance.
Cascade
=
🎨
Styled web page
Colors, spacing, layout, and motion transform plain HTML into polished UI.
Compatibility
🖥 Browser Compatibility
Core CSS properties covered here — colors, fonts, backgrounds, borders, Flexbox, Grid, and transitions — have universal support in modern browsers.
✓ Baseline · Universal support
CSS Fundamentals
Inline, internal, and external CSS work in every browser. Flexbox, Grid, and animations are production-ready.
100%Modern browsers
Google ChromeFull support
Full support
Mozilla FirefoxFull support
Full support
Apple SafariFull support
Full support
Microsoft EdgeFull support
Full support
OperaFull support
Full support
CSS basics100% supported
Bottom line: Everything in this tutorial works in all current browsers without vendor prefixes.
Wrap Up
🎉 Conclusion
CSS provides numerous ways to style and enhance web pages. By understanding inline, internal, and external styles, plus core techniques for text, backgrounds, borders, layouts, and animations, you can create visually appealing and responsive websites.
Practice the four examples above, then move to external stylesheets and dedicated layout tutorials. CSS transforms plain HTML into engaging, interactive experiences.
Inline CSS uses the style attribute on an element. Internal CSS uses a style block in the head. External CSS links a separate .css file with a link tag. External stylesheets are best for real websites.
Start with internal CSS in a style block while learning — everything is in one file. Move to external CSS files once you understand selectors and properties. Avoid inline styles except for quick tests.
Inline CSS applies to one element via the style attribute. Internal CSS writes rules in a style tag that can target many elements with selectors like p or .card.
Yes. Add multiple link tags in the head, each pointing to a different .css file. Later files can override earlier ones depending on specificity and source order.
Yes. CSS styles HTML elements. Learn basic tags like p, div, h1, and a first, then add CSS to control colors, spacing, and layout.