Web Development

CSS

CSS is the style sheet language that defines how HTML documents are displayed on screen, with their colours, fonts, margins, layout and animations.

In this post

CSS is the language that decides how a web page looks. The acronym stands for Cascading Style Sheets. While HTML indicates what each part of the content is, CSS decides how it looks. It controls the colours, fonts, sizes, spacing, positions and even the animations that appear when you hover over a button.

Thanks to this language, the content and the design of a website are kept separate. That means the look can be changed completely without touching a single word of the text. It is what happens when a company refreshes its brand or when one WordPress theme is replaced by another. The content stays, and only the outfit it is presented in changes.

The CSS language works as the stylist of a website. It decides the colours, the type and the position of everything, and it makes the same information look a thousand different ways.

What is CSS?

A CSS style sheet is a document containing design rules. Each rule says which elements it applies to and what they should look like. For example, that all headings should be a certain colour or that images should have a rounded corner. A single sheet can govern hundreds of pages, so a change to one rule is reflected across the whole website at once.

To understand the role of CSS, picture a house. HTML is the structure of walls and rooms. CSS is the decoration, the paint, the furniture and the layout. You can redo the entire decoration without knocking down a single wall. And if you change decorator, the house is still the same. That freedom is what has allowed the web to evolve so much in appearance without rebuilding its content.

Structure of a CSS rule, selector, property and value

Every CSS rule has two parts, the selector and the declarations. The selector indicates which elements it applies to, for example all paragraphs, the elements with the boton class or the one with a specific identifier. The declarations go between curly braces, each made up of a property, such as color, font-size or margin, and its value. A style sheet is nothing more than a list of these rules, and the browser combines them to paint each element.

How a CSS rule changes the look of a button

The cascade, specificity and order of CSS rules

The word cascading in the name of CSS makes sense. The same page can receive styles from several places, such as the browser, the template, the extensions and custom settings, and sometimes their rules contradict each other. CSS resolves the conflict with an order of priority. It takes into account the origin of the rule, how specific it is and the order in which it appears. A rule that targets a specific element beats one that targets all elements of its type, and between two equal rules, the later one wins. This explains many frustrations. Changing a colour and seeing nothing happen usually means that another, more specific rule is in charge. Instead of forcing things with extreme priorities, the sensible approach is to organise the styles, avoid duplicates and document the reasoning. Clean CSS is easier to maintain and faster to download.

Origin and versions of cascading style sheets

In the early years of the web there was no way to control appearance. Pages were displayed in whatever style each browser chose, and authors used tricks with the HTML itself to achieve effects. In October 1994, Håkon Wium Lie, a computer scientist working at CERN, presented a proposal to separate design from content using style sheets. The idea was developed with Bert Bos and the W3C consortium, which in December 1996 published the first official version, called CSS1. It took years for browsers to understand it properly. For a long time, each one interpreted it in its own way, and designers struggled to make a page look the same in all of them. That era left plenty of tales of frustration.

Later versions added capabilities that we now take for granted. Colours with transparency, shadows, rounded corners, animations, downloadable fonts and grids for organising the page. The language came to be developed as independent modules, which lets each new feature progress at its own pace and lets browsers adopt them gradually.

Types of CSS selectors

CSS selectors are the part of each rule that decides which elements it applies to, and there are several types that can be combined to target any part of the page precisely.

Type, class and ID selectors

The basic CSS selectors target a tag type, a class or an identifier. p affects all paragraphs, .boton all elements carrying the boton class and #cabecera the single element with that identifier. Classes are the most widely used because they can be repeated on many elements and combined with each other, while identifiers carry so much priority that they make any later change harder.

Attribute selectors

Attribute selectors pick elements according to their HTML attributes. input[type=email] applies a style only to the email fields of a form, and a[href$=pdf] to links ending in pdf, which is useful for adding a document icon to them without touching the HTML.

Pseudo-classes and pseudo-elements

Pseudo-classes select elements according to their state or position, such as hover for a link under the mouse, focus for the active field or nth-child(2n) for the even rows of a list, and they are written after the selector, separated by a colon. Pseudo-elements, which take a double colon, create parts that do not exist in the HTML, such as first-line for the first line of a paragraph or before to insert an ornament before a heading.

Combinators

Combinators relate two selectors according to their position in the document. A space between them, as in nav a, selects the links found anywhere inside the menu, the greater-than sign limits the selection to direct children, and the plus and tilde signs select the siblings that come after. With them, styles can be applied without filling the HTML with classes.

What CSS is used for on a modern website

Visual identity and brand consistency

The colours, fonts and spacing of a website are the visual voice of a brand. CSS defines them once and applies them everywhere. If a company changes its corporate colour, a few rules are enough for buttons, links and backgrounds to update at the same time. That consistency conveys professionalism and helps visitors recognise the brand instantly.

When a website lacks that care, it shows. Buttons of different sizes, text in three different fonts and uneven margins give a sense of neglect. Good CSS, with well-organised and reusable rules, avoids those mismatches. It is unglamorous work, but it makes the difference between a website that looks cared for and one that looks improvised.

Responsive design with media queries

Today more than half of all visits come from a mobile phone. CSS lets the same page rearrange itself according to the screen size, with a single column on the phone and several on a computer. Text adjusts, images scale and menus transform. This is what is known as responsive design, and it is the reason a modern website looks good on every device. Search engines take it very seriously. A website that is hard to use on a phone loses rankings, because it offers a poor experience to a large part of its audience. That is why testing the website on real phones, and not just on a computer, is one of the most worthwhile checks. Buttons must be big enough for a finger, and text readable without zooming.

How a page rearranges itself on mobile, tablet and desktop

Performance and accessibility

CSS also influences how fast a page loads. Themes and page builders often load enormous style sheets, with rules for features that are never used.

That unnecessary load delays the moment the page appears, especially on phones with slow connections. Removing what is not used and loading only what is essential is one of the simplest performance improvements.

In terms of accessibility, CSS decides whether the contrast between text and background is sufficient, whether the font size is comfortable and whether it is clear which element is selected when navigating with the keyboard. A beautiful design with poor contrast excludes people with low vision. International guidelines set specific minimum contrast levels, which should be respected from the initial design.

How style sheets are built today

Flexbox for rows and columns

For years, CSS layouts relied on awkward tricks, such as tables and floating elements. Flexbox arranges elements in a single row or a single column and shares out the space between them. With the display property set to flex and with justify-content, a button can be centred or the links of a menu spaced apart, and with flex-wrap the cards of a catalogue move to the next line when they do not fit.

Grid for two-dimensional layouts

Grid allows design in two dimensions, with rows and columns at the same time, for more complex structures such as a home page or a catalogue. A single grid-template-columns declaration with the value repeat(3, 1fr) creates three equal columns, and with grid-template-areas you can draw the layout of the header, the content and the sidebar using names instead of measurements.

CSS variables and media queries

CSS variables, officially called custom properties, let you define colours and sizes once and reuse them. They are declared with two hyphens, such as --color-marca, and used with var(--color-marca), so changing the corporate colour means changing a single line. Media queries change the design depending on the screen width, and together they allow a website to stay consistent and adapt to any device with very little code.

The box model

For CSS, every element on the page is a box. At the centre is the content, around it the inner padding, then the border and, on the outside, the margin that separates it from the other boxes. Understanding the box model explains most spacing problems, such as a button wider than expected or two blocks that do not fit together, because the final size depends on how those four layers add up.

How the space taken by a CSS box is calculated

Inline, internal and external styles

Styles can reach the page in three ways. One is writing them on each element, which is quick but messy and is discouraged. Another is including them in a block in the head of the page itself, which is useful for one-off cases. The third, and the most advisable, is an external sheet linked from every page, so that a single file controls the look of the whole site.

The external style sheet has clear advantages over the other options. It is downloaded once and the browser keeps it for subsequent visits, a change is reflected across the whole website at once and the code stays organised in a single place. That is why good practice says design should live in style files and not be mixed with the content.

CSS frameworks and preprocessors

So as not to start from scratch, many projects use frameworks such as Bootstrap, which offers ready-made components and a grid, or Tailwind, which is based on small classes combined in the HTML. Preprocessors such as Sass add variables, nesting and functions that are then compiled into plain CSS. They save time, but they can also load unused styles if they are not configured carefully. If you need to apply this in a project, an experienced web developer can help you get it right from the start.

CSS in WordPress

In WordPress, appearance is governed by the theme and, increasingly, by the block editor and its global styles. Underneath, it is all CSS. When you change a colour from the dashboard, the system modifies the rules for you. And when a plugin adds a form or a button, it brings its own styles, which sometimes clash with those of the theme and produce odd results.

For small adjustments, the dashboard usually offers an additional styles section. It is very convenient, but it should be used in an orderly way. Over the years, a website accumulates patches from different people, some of them contradictory, and becomes hard to maintain. Documenting what was changed and why, even with brief notes, saves hours for whoever has to review it later.

A good practice is not to modify a theme directly, because updates would wipe out the changes. A child theme or the editor’s own global styles are used instead. That way, custom adjustments survive updates. It is the same principle of separation that gave birth to the language, applied to the day-to-day maintenance of a website.

Signs that your styles need a clean-up

A first sign that the CSS needs a clean-up is speed. If the website loads slowly and measurement tools report styles that block the page from appearing, there is probably too much CSS. Many themes include dozens of style files, and each one adds a little delay. Reducing or combining them can gain tenths of a second that visitors do notice. Another sign is consistency, in other words whether buttons, headings and spacing look the same on every page. If there are differences for no reason, there are probably duplicated or contradictory styles. An orderly clean-up, with well-defined common rules, restores consistency and makes future changes easier without breaking anything. The third is testing on devices, opening the website on a phone, a tablet and a computer, with different browsers. If something gets cut off, overlaps or cannot be tapped, it needs fixing. Asking a couple of outsiders to test it usually reveals problems the owners do not see, because they have got used to their own website.

A demonstration that put an end to table-based layouts

In the early 2000s, most websites were designed with tables, a technique intended for displaying data and not for layout. They were hard to maintain and hard for machines to read. Advocates of web standards argued that CSS could do the job better, but many professionals were not convinced and doubted that browsers would support it.

In 2003, the designer Dave Shea launched CSS Zen Garden. The project showed a single page, with exactly the same content, and invited designers from all over the world to create their own style sheet. The results were astonishing. The same information appeared with hundreds of looks so different that they seemed like different pages. Only the design changed, never the text.

The demonstration of that garden of styles was compelling. It showed that design with style sheets was possible, flexible and beautiful, and it persuaded many professionals to abandon tables. Over time, it became the usual way of working. Today, when a website is redesigned without rewriting its content, it is applying the same idea that this virtual garden taught a whole generation.

Frequently asked questions

Frequently asked questions about CSS

What is CSS?

It is the language that controls how a web page looks. While HTML indicates what each part of the content is, CSS decides how it looks, with its colours, fonts, sizes, spacing and positions. It makes it possible to change the entire design of a website without touching its text.

What does CSS stand for?

It stands for Cascading Style Sheets. Style sheets are the documents where design rules are written. Cascading means that, when several rules clash, the browser follows a well-defined order of priority.

Who invented CSS?

Håkon Wium Lie, a Norwegian computer scientist working at CERN, proposed the idea in October 1994. He later teamed up with Bert Bos, and the W3C consortium published the first official version at the end of 1996. Today it is a standard present on every website.

What is the difference between HTML and CSS?

HTML describes the structure and meaning of the content, such as headings and paragraphs. CSS describes its presentation, such as colours and positions. Separating them makes it possible to change the design without rewriting the text, and to keep several versions of the same website with different looks.

What is responsive design with CSS?

It is a design that adjusts to the size of the screen. With CSS, the same page can be shown in a single column on a phone and in several on a computer. Today it is a basic requirement, because most visits come from small devices.

Does CSS affect the speed of a website?

Yes. Excessive CSS, with rules that are never used, delays the moment the page appears. Many themes and page builders load styles for features they do not use. Reviewing and trimming what is unnecessary is one of the simplest improvements for gaining speed.

What is the cascade in CSS?

The cascade is the system CSS uses to decide which rule applies when several match the same element. It takes into account the origin of the rule, how specific it is and the order in which it appears. A rule that targets a specific element beats one that targets all elements of its type, and between two equal rules the later one wins.

Do I need to know CSS to manage a website?

Not for everyday use. The templates and visual editors of content management systems and shop platforms take care of the design. But knowing the basics lets you make small colour or spacing adjustments without asking for help, and understand why a website looks a certain way on a phone or a computer.

I fix design and CSS problems

If your website has misplaced elements, wrong colours or does not adapt well to mobile, I can review and fix the CSS.

About the author

Javier Afán

WordPress developer specialised in security, WooCommerce, and hacked website recovery.

I work on WordPress from a technical angle focused on security, architecture, and the decisions that really affect a project's continuity.