CSS Explained: How Websites Get Their Look and Layout

CSS explained in plain terms means understanding how a website’s appearance is decided separately from its words and pictures. The central question is how the same page can look completely different on a phone, a laptop, and a printed sheet, and the short answer is that CSS is a set of rules that tells the browser how each part of a page should look, while the page itself only describes what the parts are.

Before CSS existed, the early web was plain and hard to read. Every page looked much the same, with default fonts and sizes, because the only way to change the look was to mix styling instructions into the content itself. Changing the colour of every heading on a site meant editing every page by hand, and the result was often messy and inconsistent.

CSS changed that by moving all the design decisions into one place. A single stylesheet can set the colours, fonts, spacing, and layout for a whole website, and changing one rule can restyle hundreds of pages at once. This article explains what CSS is, how the browser applies it, and how it compares with other ways of styling a page.

Key takeaways

  • CSS controls how a page looks: colours, fonts, spacing, and layout.
  • It separates design from content, so one set of rules can style many pages.
  • A rule has a selector that picks out elements and declarations that set their style.
  • The cascade decides which rule wins when several rules apply to the same element.
  • Modern CSS handles responsive layouts, so one site fits phones and desktops alike.

What CSS is

CSS stands for Cascading Style Sheets, and it is the language browsers use to decide how a web page should look. HTML describes the content of a page, such as headings, paragraphs, and images, while CSS describes the presentation of that content, such as the size of the headings, the colour of the text, and the space between the paragraphs. The two work together: HTML says what things are, and CSS says how they should appear.

A stylesheet is made of rules, and each rule has two parts. The selector picks out which elements the rule applies to, such as all headings, all links, or only the elements with a particular class name. The declarations then set the style for those elements, each one naming a property and giving it a value, such as a font size, a background colour, or a margin.

The word cascading describes how the browser resolves conflicts. Several rules can apply to the same element, from the browser’s own defaults, from the site’s stylesheet, and from rules attached to a single element, and the cascade is the set of priorities that decides which one wins. Our guide to JavaScript explains the language that adds behaviour to pages once they are styled, and our guide to web accessibility explains why keeping content and design separate also helps screen readers and other assistive tools.

How CSS works

When a browser loads a page, it first reads the HTML and builds a tree of elements, with the page at the top and headings, paragraphs, and images branching below it. It then reads the stylesheets and works out, for every element in that tree, which rules apply and what the final style should be. Only then does it paint the page on the screen, so the design is applied before you ever see the content.

Selectors are the addressing system of CSS. A simple selector can target every paragraph, or every link inside a navigation menu, or a single element by its unique identifier. Class selectors are the workhorses of real stylesheets, because they let a designer mark any group of elements as sharing a style, such as all the buttons, or all the warning messages, without touching the HTML structure.

Every element on a page is treated as a box, and the box model is one of the most important ideas in CSS. Each box has content in the middle, then padding around the content, then a border, then a margin that separates it from its neighbours. Understanding that a heading’s size includes its padding and border, not just its text, explains most of the spacing surprises that beginners meet.

Layout is handled by two modern systems, flexbox and grid. Flexbox arranges items in a row or a column, spreading them out or squeezing them together, which suits navigation bars and rows of cards. Grid divides the page into rows and columns, which suits whole-page layouts and photo galleries. Together they have replaced the old tricks of floating elements and fixed-width tables that designers once relied on.

A laptop on a dark desk showing a glowing green website layout with style panels, the text blurred
A laptop showing a glowing green website layout with style panels, the text blurred, shows how CSS turns plain content into a designed page.

Comparing CSS with other ways to style a page

CSS is not the only way to change how a page looks. Styles can also be written directly on each element, or applied by JavaScript after the page has loaded, and each method has its place.

The table below sets out the main contrasts between the three approaches.

Aspect CSS stylesheet Inline styles JavaScript styling
Where rules live In a separate file On each element In scripts that run later
Reuse across pages One file styles a whole site None, repeated everywhere Shared only through code
Changing a whole site Edit one rule Edit every page Edit the script
Best for Almost all styling One-off exceptions Styles that change live
Easy to maintain Yes, kept in one place No, scattered and duplicated Harder to trace and debug

The practical result is that a stylesheet is the right home for almost all styling, inline styles suit a single exception that will never be repeated, and JavaScript styling is best kept for things that change while the page is running, such as a menu opening or an error appearing.

Where CSS is used

Every website you visit uses CSS, and it is hard to find a page on the modern web that does not. News sites, shops, blogs, and web apps all rely on stylesheets to set their look, and the same stylesheet often serves the desktop site, the mobile site, and the print version, with different rules for each.

Responsive design is the most visible use. A stylesheet can ask the browser how wide the screen is and apply different rules for a phone, a tablet, and a desktop monitor, so one set of pages works everywhere. Columns become a single stack on a narrow screen, menus collapse into a button, and text stays readable without zooming.

Print stylesheets are a quieter use. The same page that looks colourful on screen can be restyled for paper, with backgrounds removed, navigation hidden, and links shown in full, so a printed article reads cleanly. The content does not change at all; only the rules applied to it do.

CSS also styles the apps that live inside the browser. Webmail, maps, document editors, and dashboards are all built from HTML and CSS, with JavaScript adding the interaction. Even many mobile apps use web views styled with CSS for parts of their interface, because it is faster to build and easier to update than native screens.

Design systems are a newer use, where a company keeps a shared library of styles and components that every team reuses. A button, a form, and a card look the same across dozens of products because they share the same rules, and a change to the design system updates them all at once.

Strengths and limits

The greatest strength of CSS is separation. Content, design, and behaviour live in different files, so a designer can restyle a site without touching the words, and a writer can edit the words without breaking the design. That separation also makes sites faster to build, because a new page inherits the whole design from the shared stylesheet.

It is also a strength that CSS is declarative rather than procedural. A designer states what the page should look like, and the browser works out how to achieve it on whatever screen it is running on. That makes responsive design possible without writing a separate version of the site for every device.

The limits are real, though. Browsers have not always agreed on how a rule should be rendered, and older browsers may ignore newer features entirely, so designers still test in more than one browser. Large stylesheets can also become tangled, with rules overriding each other in ways that are hard to trace, and CSS has no built-in logic, so anything that needs a calculation or a decision must be handled elsewhere.

CSS checklist

  • Keep your styles in one stylesheet rather than scattering them across pages.
  • Give classes clear, meaningful names that describe their purpose, not their appearance.
  • Design for the smallest screen first, then add rules for larger ones.
  • Test your pages in more than one browser before publishing them.
  • Use relative units for text size so readers can resize it if they need to.
  • Group related rules together and leave notes for the next person who edits the file.
  • Avoid the important flag except as a last resort, since it makes overrides hard to trace.
  • Keep inline styles for one-off exceptions only, never as the main approach.
  • Check that text has enough contrast against its background to read comfortably.

Frequently asked questions

What does CSS stand for?

CSS stands for Cascading Style Sheets. It is the language that describes how a web page should look, including colours, fonts, spacing, and layout.

Is CSS a programming language?

Not in the usual sense. CSS does not run step-by-step instructions or make decisions the way a programming language does. It declares how things should look, and the browser works out how to apply those declarations.

What is the difference between CSS and HTML?

HTML describes the content and structure of a page, such as headings, paragraphs, and images. CSS describes the presentation of that content, such as its size, colour, and position on the page.

What is the cascade in CSS?

The cascade is the set of rules that decides which style wins when several rules apply to the same element. It considers where a rule comes from, how specific its selector is, and the order in which rules appear.

Do I need CSS to build a website?

Technically no, because a browser will display plain HTML with its own default styles. In practice, yes, because without CSS a site looks unfinished and is hard to read on different screen sizes.

What are flexbox and grid?

They are the two modern layout systems in CSS. Flexbox arranges items in a single row or column, while grid arranges them in rows and columns together, which suits full page layouts.

The bottom line

CSS explained in one line is this: a set of rules that tells the browser how a page should look, kept separate from the content so that one stylesheet can design a whole website.

It is the reason the web is readable, colourful, and usable on screens of every size, and it works best when it is kept tidy, with clear class names, one shared stylesheet, and rules that are tested on more than one browser.

This article is general information about how CSS works, not design advice for a particular website or project.

Latest articles

Scroll to Top