CSS

From WikiTech, the encyclopedia of technology

Technology · Web Development · 4 min read · 740 words · Updated

CSS
Technology
CSS — article photograph or illustration
Image placeholderPlace the file shown below in the assets/articles folder
File: css.webp
Full nameCascading Style Sheets
PurposePresentation and layout of documents
Maintained byW3C CSS Working Group
Main useStyling HTML and other structured documents
Core conceptsCascade, specificity, box model, layout

Cascading Style Sheets (CSS) is the style sheet language used to control how HTML documents are presented. CSS defines colours, fonts, spacing, borders, layout, animation and responsive behaviour. It allows a document's structure to remain separate from its visual design, so the same HTML can be presented differently on a phone, desktop, printed page or assistive display.[1]

Rules, selectors and declarations

A CSS rule contains a selector and a declaration block. The selector identifies the elements to which the rule applies, while declarations specify properties and values. A selector can target elements by name, class, attribute or relationship to other elements. Classes are commonly used for reusable component styling because they separate presentation hooks from the meaning of an HTML element.

The cascade determines which declarations apply when multiple rules match the same element. It considers origin, importance, cascade layers, specificity and source order. A later rule does not always win if an earlier rule has a stronger selector or importance level. Overly complicated selectors and frequent use of !important make a stylesheet harder to reason about. A predictable naming system and a small number of styling layers help prevent conflicts.

The box model and layout

Every element is laid out using a box model that includes content, padding, border and margin. The box-sizing property controls how declared width and height interact with padding and borders. Many projects use box-sizing: border-box so that an element's declared size includes its padding and border, making component dimensions easier to calculate.

Modern CSS provides layout systems for different problems. Flexbox is suited to arranging items along one dimension, while Grid handles rows and columns together. Normal flow remains useful for document content, and positioning can place elements relative to containers or the viewport. Responsive layouts combine flexible measurements, media queries and content-aware breakpoints rather than assuming every screen has a fixed width.

Typography, colour and accessibility

CSS controls font families, sizes, weights, line height and text spacing. Readability depends on relationships between these values, not merely on choosing a decorative font. Colours should provide sufficient contrast, and information should not be conveyed by colour alone. Focus indicators need to remain visible for keyboard users, while reduced-motion preferences should be respected when animations are not essential.

Design tokens implemented with custom properties can centralise colours, spacing and type scales. This makes a site's visual language easier to update consistently. A clear token system is useful when a project has several page types or a large collection of articles.

Responsive design and rendering

Responsive CSS allows a layout to adapt to available space. Fluid grids, flexible images and media queries can change columns, navigation and typography as the viewport changes. Content should determine breakpoints: a navigation menu should change when it no longer fits, not simply because a device is labelled as a tablet. Testing should include narrow screens, zoomed text and long content.

Browsers parse stylesheets into rules that participate in style calculation and layout. A missing stylesheet, incorrect URL or syntax error can change the appearance of an entire site. Developers should use browser developer tools to inspect network requests, computed styles and console warnings. Cache headers and versioned stylesheet filenames also matter when publishing updates, because a browser may otherwise keep an older CSS file.

Relationship to HTML and JavaScript

CSS does not replace document semantics. HTML describes content and structure, while JavaScript handles dynamic behaviour. Keeping these roles clear helps avoid fragile pages that depend on visual styling for meaning or on scripts for basic navigation. CSS is one of the core technologies of the web, alongside the markup and programming layers.

Further engineering considerations

Cascade, specificity and maintainable stylesheets

When several CSS rules target the same element, the browser resolves them through the cascade. Origin, importance, cascade layer, specificity and source order determine which declaration wins. This explains why a late override does not always fix a visual bug: a more specific selector or an important declaration may take precedence. A maintainable stylesheet uses predictable class names, limits unnecessary specificity and groups related rules so that developers can understand where a value comes from.

Custom properties provide shared design tokens for colours, spacing, typography and component dimensions. They make a site easier to restyle consistently and can adapt to themes or responsive conditions. Layout systems such as Flexbox and Grid should be chosen according to the relationship between elements rather than through arbitrary positioning. A robust design also tests zoom, narrow screens, long translated text and keyboard focus. CSS is therefore not only decoration; it is a system for expressing visual rules while preserving readable, adaptable content built with HTML.

See also

  • HTML – The standard markup language used to structure documents and applications on the World Wide Web.
  • JavaScript – The programming language that powers interactive web pages and a large ecosystem of browser, server and desktop software.
  • React – A JavaScript library for building user interfaces from composable components.
  • Tim Berners-Lee – British computer scientist who invented the World Wide Web.
  • WebAssembly – A portable binary instruction format that runs at near-native speed in browsers and other runtimes.
  • TypeScript – A language that extends JavaScript with a static type system and compiles to ordinary JavaScript.
  • HTTP/3 – The third major version of the Hypertext Transfer Protocol, which runs over QUIC instead of TCP.
  • JSON – A lightweight text format for structured data based on JavaScript object syntax.

References

  1. ↑ MDN CSS: Cascading Style Sheets (developer.mozilla.org)
  2. ↑ W3C CSS Working Group (w3.org)
  3. ↑ CSS Snapshot (w3.org)