What Is CSS and What Is It Used For?

CSS (Cascading Style Sheets) is the language that controls how a web page looks and how its content is laid out. HTML defines what the content is (headings, paragraphs, links, images), while CSS defines how that content appears — colors, fonts, spacing, sizing, and where each element sits on the screen. You use CSS any time you want a page to look intentional rather than like a plain document of stacked text.

The three roles: structure, presentation, behavior

A useful way to keep web technologies straight is to separate them by job:

Technology Role Example responsibility
HTML Structure / content "This is a heading, this is a paragraph, this is a link"
CSS Presentation / layout "Headings are dark blue, paragraphs have 16px spacing, the sidebar sits on the right"
JavaScript Behavior / interactivity "Clicking this button opens a menu, this form validates before submitting"

CSS is not a programming language in the sense of loops and logic — it is a declarative style language. You describe the result you want, and the browser figures out how to apply it.

How a CSS rule is written

A CSS rule has two parts: a selector that picks which elements to style, and a declaration block that lists the styles to apply.

/* selector: p  |  declarations inside { } */
p {
  color: #333333;
  font-size: 16px;
  line-height: 1.5;
  margin-bottom: 1em;
}
  • p is the selector — it targets every <p> element.
  • color, font-size, line-height, margin-bottom are properties.
  • #333333, 16px, 1.5, 1em are the values.
  • Each property–value pair ends with a semicolon; the whole block is wrapped in { }.

The word cascading in the name refers to how the browser resolves conflicts: when multiple rules target the same element, it follows priority rules (origin, specificity, and source order) to decide which one wins. That is why a later rule or a more specific selector can override an earlier one.

What CSS is commonly used for

  • Color and typography — text color, background color, font family, size, weight, and line spacing.
  • Spacing and sizing — margins, padding, width, height, and gaps between elements.
  • Layout — arranging elements in rows, columns, grids, or flexible containers (Flexbox and Grid are the modern layout systems).
  • Responsive design — changing the layout based on screen size using media queries, so a page works on both phones and desktops.
  • Visual states — hover, focus, and active styles for links and buttons.
  • Borders, shadows, and rounded corners — the decorative details that shape a page's look.

Three ways to attach CSS to HTML

  1. External stylesheet (most common) — a separate .css file linked from the HTML <head>:

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

    This is preferred because one file can style an entire site, and the browser can cache it.

  2. Internal stylesheet — a <style> block inside the HTML <head>. Useful for a single page or quick testing.

  3. Inline styles — a style attribute directly on an element, such as <p style="color: red;">. It applies to that one element only and is hard to maintain at scale, so it is generally reserved for one-off cases.

How CSS fits with the rest of a page

When a browser loads a page, it reads the HTML to build the document structure, then applies the CSS to compute how each element should be displayed, and finally paints the result. JavaScript can run alongside this to change styles dynamically — for example, adding a class that CSS has already defined. This separation is why the same HTML can be restyled completely by swapping stylesheets, and why CSS is one of the three core technologies of the web alongside HTML and JavaScript.

animista.net
Animista is a CSS animation library and a place where you can play with a collection of ready-made CSS animations and download only those you will us…
cdnjs.com
cdnjs is the free, open-source CDN for the web's most popular libraries. JavaScript, CSS, and font resources, globally cached on Cloudflare's network…
duiadns.net
Duiadns is an enhanced and free dynamic dns provider with an unique feature named ipv6 for lan. Create a free ddns account today!
geeksforgeeks.org
Your All-in-One Learning Portal. It contains well written, well thought and well explained computer science and programming articles, quizzes and pra…
mybrowseraddon.com
MyBrowserAddon is a community for open-source projects. We can help you create new projects to share with the world!
tabler.io
Tabler is a free HTML admin template packed with well-designed components and features. Start your adventure with Tabler and make your dashboard grea…