Loading
All articles
Programming 15 min read

What Is CSS? A Simple Guide to the Language That Makes the Web Look Good

A friendly, jargon-free guide to CSS, the language that decides how every web page looks. See Wikipedia with its CSS removed, give one page three different looks, learn how the cascade picks a winner, and how one page fits every screen from a phone to a TV.

nbkhope
On this page

Think of your favorite website. Its colors, its fonts, the way the menu sits at the top, the way the page rearranges itself when you turn your phone sideways. None of that comes from the words on the page. It comes from a second language that works alongside them, called CSS.

CSS stands for Cascading Style Sheets. If HTML is the content of a web page (the headings, paragraphs, links and pictures), CSS is its look: colors, fonts, sizes, spacing and layout. This article explains, in plain language, what CSS is, how it works, and why the web would look like a plain document from 1993 without it.

What happens if you take CSS away

The easiest way to see what CSS does is to remove it. We opened Wikipedia's article about CSS in Google Chrome, took a screenshot, then removed every style sheet from the page and took another:

The same Wikipedia page, with and without CSS. On the left, with CSS: Wikipedia's article about CSS, with a small logo at the top, a search icon, the article title, tabs, the text in neat columns and an information box on the right with the CSS logo. On the right, without CSS: the same page in plain black text on white. The menu has become a long bulleted list of blue underlined links, there are plain checkboxes and gray buttons, and the Wikipedia logo is so big it fills the whole width of the screen. The article itself is pushed far down the page. Real screenshots of Wikipedia's article about CSS in Chrome. The HTML is the same in both

Same page, same HTML, same words. Without CSS, the menu turns into a long list of links, the logo becomes enormous, and you have to scroll a long way to even reach the article. CSS is what turns a pile of content into a designed page.

The parts of a CSS rule

CSS is written as a list of rules. Each rule says "find these elements, and change these things about them":

The parts of a CSS rule, using h1, open curly brace, color colon tomato semicolon, font-size colon 32px semicolon, close curly brace. The h1 at the start is the selector: which elements to style. color is a property: what to change. tomato is a value: the new setting. Each property and value pair, like color: tomato; and font-size: 32px;, is a declaration. The whole thing is called a rule. Every h1 heading on the page becomes big, in a tomato-red color. Below, three places to put CSS: in a separate file linked with a link tag, shared by every page, which is the most common; in a style block inside the page; or right on one tag, with a style attribute, best kept for rare cases
  • The selector (h1) says which elements the rule applies to. Here, every main heading.
  • A property (color) is the thing to change, and its value (tomato) is the new setting. Yes, "tomato" is an official CSS color name.
  • Together, a property and its value form a declaration. A rule can have as many as you like, each ending with a semicolon.

Most websites keep their CSS in separate files, linked from every page with a <link> tag. Change one line in that file, and every page on the site changes at once. That's the whole idea behind the name style sheet: one sheet of style instructions, shared by many pages.

Same HTML, three different looks

Here's the pancake recipe page from our HTML article. We kept the HTML exactly the same and linked it to two different CSS files:

Same HTML, three different looks. Three real screenshots in Chrome of the same recipe page. First, no CSS: black serif text on white, a plain list and a small gray button. Second, style 1, cozy: a cream background, a dashed orange border with rounded corners around the content, rust-colored headings, a line under Ingredients and a round rust-colored button. Third, style 2, dark: a dark navy background, mint green headings, light text, each ingredient in its own rounded dark box, a yellow link and a button with a purple-to-pink gradient. All three use exactly the same HTML file. Only the CSS file linked to it changes

Here's the whole "cozy" style sheet. Even without knowing CSS, you can probably guess what most lines do:

1body {
2  font-family: Georgia, serif;
3  background: #fdf6ec;
4  color: #4a3728;
5  max-width: 420px;
6  margin: 32px auto;
7  padding: 8px 24px 24px;
8  border: 3px dashed #e0a96d;
9  border-radius: 16px;
10}
11h1 { color: #c0562f; }
12h2 {
13  color: #8a5a2b;
14  border-bottom: 2px solid #e0a96d;
15}
16a { color: #c0562f; }
17button {
18  background: #c0562f;
19  color: white;
20  border: none;
21  padding: 10px 20px;
22  border-radius: 999px;
23  font-size: 16px;
24}

This separation of content (HTML) and presentation (CSS) is CSS's big idea. In 2003, a website called the CSS Zen Garden made it famous: it invited designers to restyle one single HTML page using only CSS, and hundreds of wildly different designs came in, from Japanese gardens to comic books, all from the same HTML.

The "cascade": when rules disagree

On a real site, several rules often apply to the same element, and they don't always agree. One rule says paragraphs are blue, another says notes are green. Which one wins? CSS settles it with a set of rules called the cascade, which is where the "Cascading" in the name comes from.

When rules disagree, the more specific one wins. The CSS: p, color blue; dot note, color green; hash special, color red. The HTML: a plain paragraph, a paragraph with the class note, and a paragraph with the class note and the id special. In the real Chrome screenshot, the plain paragraph is blue, the note is green, and the special note is red. From weakest to strongest: the browser's defaults, such as blue links and bold headings; a tag name, like p; a class, like dot note; an ID, like hash special; and a style attribute written on the tag itself. Each paragraph gets the color of the most specific rule that matches it. If two rules are equally specific, the one that comes later wins

The main idea is the more specific rule wins:

  • A rule for all paragraphs (p) is very general.
  • A rule for a class (.note) targets a group of elements you've labeled with class="note" in the HTML. It's more specific, so it beats the first.
  • A rule for an ID (#special) targets one single element, labeled id="special". It's the most specific of the three, so the last paragraph turns red, even though it's also a paragraph and also a note.
  • If two rules are equally specific, the one that comes later wins.

Some properties are also inherited: if you set a font on the <body>, every paragraph and heading inside it uses that font too, unless a more specific rule says otherwise. That's why one line of CSS can change the font of a whole site.

Every element is a box

To a browser, every element on a page, whether it's a heading, a paragraph, an image or a button, is a rectangle. CSS controls the size of each box and the space around it, in layers:

Every element is a box. A diagram of nested rectangles. In the middle is the content, the text or image itself, here the word Hello. Around it is the padding, space between the border and the content. Around that is the border, the line around the box. Outside the border is the margin, empty space that pushes other boxes away. The CSS for this box: width 200px, padding 20px, border 4px solid black, margin 30px. Headings, paragraphs, images and buttons are all boxes like this one. Most page layout is about sizing these boxes and placing them next to, above or inside each other
  • Content: the text or picture itself.
  • Padding: breathing room inside the box, between the content and the border.
  • Border: an optional line around the box.
  • Margin: empty space outside the border that keeps other boxes at a distance.

This is called the box model, and once you know it, web pages start to look like what they really are: boxes inside boxes. A web designer's job is mostly deciding how big those boxes are and where they go. Modern CSS has powerful tools for that, called Flexbox (for lining boxes up in a row or column) and Grid (for arranging them in rows and columns, like a spreadsheet).

Colors in CSS

CSS gives you several ways to write a color. These four all mean exactly the same shade of red:

Four ways to write the same color, shown as four identical tomato-red swatches. tomato: a name, and 148 colors have one. Hash ff6347: a hex code, with red, green and blue in base 16. rgb 255 99 71: red, green and blue from 0 to 255. hsl 9 100 percent 64 percent: hue, saturation and lightness. Reading a hex code: hash, ff, 63, 47. ff equals 255 for red, the maximum. 63 equals 99 for green. 47 equals 71 for blue. Screens make every color by mixing red, green and blue light. With 256 levels for each, CSS can describe 16,777,216 colors

The odd-looking ones, like #ff6347, are called hex codes. Every screen pixel is made of tiny red, green and blue lights, and a hex code says how bright each one is, using two digits each in base 16 (where the digits go from 0 to 9 and then a to f). ff means 255, full brightness. So #ff6347 means "red all the way up, a bit of green, a bit of blue": tomato red. Designers usually pick colors with a color picker, and the picker writes the code for them.

One page, any screen

Today, most visits to websites come from phones, so a page must look good at any width, from a small phone to a huge TV. This is called responsive design, and it's done with CSS:

One page, any screen size. Two real screenshots of the same recipes page in Chrome. On a wide screen, 900 pixels wide, three recipe cards sit side by side in three columns: Pancakes with an orange picture, Waffles with a yellow one and French toast with a purple one. On a phone, 360 pixels wide, the same three cards are stacked in one column. The CSS that does it: dot cards, display grid, grid-template-columns 1fr 1fr 1fr, gap 16px. Then an at-media rule with max-width 600px that sets the cards to a single column. When the screen is 600 pixels wide or less, the page uses one column instead of three

The key is the @media rule. It says "only apply these styles when the screen matches this condition." Here, when the screen is 600 pixels wide or narrower, the three columns become one. The HTML is exactly the same on both screens; the browser simply applies different CSS.

The same trick powers other things you may have noticed: sites that switch to dark mode when your phone does, and pages that print neatly without menus and ads.

Inside a real page's CSS

How much CSS does a real site use? We loaded Wikipedia's article about CSS in Chrome and counted all the style rules the page uses:

Inside a real web page's CSS. We loaded Wikipedia's article about CSS in Chrome and counted its style rules. The 10 most used properties: color, text color, 447 times; display, how a box is laid out or hidden, 293; background-color, 290; mask-image, which cuts out shapes for the icons, 159; width, 148; border-color, 137; margin, space outside a box, 136; font-size, text size, 132; padding, space inside a box, 130; position, where a box is placed, 114. In total: 2,237 rules, 5,578 declarations, 391 different properties, and 228 kilobytes of CSS, sent compressed as 29 kilobytes
  • One page uses 2,237 rules with 5,578 declarations, using 391 different properties.
  • The most common property is plain old color, followed by display, which controls how a box is laid out (or hides it entirely).
  • The CSS files add up to 228 KB, but they travel over the internet compressed to about 29 KB, and your browser keeps them, so the next Wikipedia page you open loads faster.

CSS keeps growing

CSS keeps growing. Number of properties, the things CSS can change. CSS1, 1996: 53, in the first version. CSS2, 1998: 122, in the second version. Chrome, 2026: 674 properties that Chrome 155 tracks for every element. CSS1 and CSS2 counted in their official specifications. Chrome counted with getComputedStyle. The W3C's list of every property in any CSS document, including drafts, had 730 names in 2026

The first version of CSS, in 1996, had 53 properties, mostly about fonts, colors, margins and borders. We asked Chrome how many properties it keeps track of for every single element on a page today: 674. They cover animations, shadows, gradients, columns, grids, scrolling, printing and much more.

There's no "CSS4." After CSS2, the language was split into separate modules (colors, fonts, grid, animations and so on), each updated on its own schedule, so CSS keeps growing a little at a time.

A short history of CSS

In the early web, there was no CSS. Pages were styled with HTML tags like <font color="red"> and <center>, and designers abused tables to lay out pages, even using invisible "spacer" images to push things into place. Every page had to repeat all of it, and changing a site's design meant editing every page by hand.

In 1994, Håkon Wium Lie, a Norwegian working with Tim Berners-Lee at CERN, proposed Cascading HTML Style Sheets. He was soon joined by Bert Bos, who had been working on his own style language, and together they shaped CSS. The first official version, CSS1, came out in December 1996.

Browsers were slow to support it properly. Different browsers drew the same CSS differently for years, and web designers spent much of their time on workarounds. Things improved steadily in the 2000s, and in 2010 the designer Ethan Marcotte coined the term responsive web design, just as smartphones were taking over.

A short history of CSS, as a timeline. 1994: Håkon Wium Lie proposes CSS at CERN. 1996: CSS1, the first version. 1998: CSS2, with positioning and media types. 2000: the first browser with almost all of CSS1. 2003: the CSS Zen Garden shows what CSS can do. 2010: the term responsive web design is coined. 2011: CSS 2.1 is finished. 2017: CSS Grid works in every major browser. 2023: nesting and the has selector arrive in every major browser

Recent years have brought features designers waited decades for: Grid layouts (2017), variables for reusing colors and sizes, nesting rules inside each other, and the :has() selector (both available in every major browser by 2023), which lets a style depend on what's inside an element.

Common questions

Is CSS a programming language? Like HTML, it's usually not considered one. It describes how things should look rather than giving step-by-step instructions. That said, modern CSS can do surprisingly clever things, like animations and layouts that adapt on their own.

Do I need to learn HTML first? Yes, a little. CSS styles HTML elements, so you need to know what a <p> or an <h1> is. The good news: the basics of both can be learned in a weekend.

What are Bootstrap and Tailwind? They're popular collections of ready-made CSS, so developers don't have to write everything from scratch. Underneath, it's all still CSS.

Can I see a website's CSS? Yes. On a computer, right-click any part of a page and choose Inspect. The panel that opens shows that element's HTML on one side and every CSS rule that applies to it on the other. You can even change values and watch the page update (only on your screen, of course).

Glossary

  • CSS: Cascading Style Sheets, the language that controls how web pages look.
  • Style sheet: a file, or block, of CSS rules.
  • Rule: a selector plus a set of declarations, like h1 { color: tomato; }.
  • Selector: the part of a rule that picks which elements to style.
  • Property: something CSS can change, like color or font-size.
  • Value: the setting for a property, like tomato or 32px.
  • Class: a label you give to elements in HTML (class="note") so CSS can style them as a group.
  • ID: a label for one single element (id="special").
  • Cascade: the rules that decide which style wins when several apply.
  • Box model: content, padding, border and margin, the layers of every element's box.
  • Hex code: a color written as # plus six digits, like #ff6347.
  • Responsive design: making one page adapt to every screen size.
  • Media query: an @media rule that applies styles only on certain screens.

Wrapping up

HTML says what's on a page. CSS decides how it looks: the colors, the fonts, the spacing and where everything goes. Its rules pick elements with selectors and change their properties, the cascade settles disagreements, and media queries let one page fit every screen.

Take CSS away, and even Wikipedia turns into a long list of links with a giant logo. Put it back, and the same HTML becomes a page you actually want to read. To see it on any site, right-click and choose Inspect: every style on the page is right there for you to explore.

Thanks for reading!

Know someone who would enjoy this? Send it their way.

More articles

Read next

Comments

Be kind and specific. Comments with links from new accounts appear after a moderator reviews them.