Safekipedia

CSS

Adapted from Wikipedia · Adventurer experience

A sample of CSS computer code used for web design and styling.

Cascading Style Sheets, or CSS, is a special language used to make web pages look nice and organized. It works together with HTML and JavaScript to build the websites we see every day. HTML gives the content of a page, like text and pictures. CSS decides how that content looks — like colors, fonts, and how the page is laid out.

CSS is important because it helps separate the content from its style. This means you can write your content once and change how it looks without touching the original text. It also makes websites easier to use for everyone, including people who need special ways to see the web, like using a screen reader or a Braille-based device.

CSS can make a website look good on many different devices, like phones, tablets, or printers. The "cascading" part of its name means that if there are multiple rules about how something should look, CSS has a way to decide which rule to use. The rules for CSS are kept up to date by the World Wide Web Consortium.

Besides HTML, CSS can also be used with other types of web languages, such as SVG, XHTML, and even in programs that use the GTK widget toolkit. This makes CSS a flexible tool for anyone who wants to design and build web pages.

Syntax

CSS has a simple syntax and uses English words to set styles for web pages.

A style sheet is a list of rules. Each rule has parts called selectors and a declaration block. Selectors decide which parts of a webpage to style.

Selectors can choose items in many ways. Declaration blocks contain the actual styles, like colors and sizes, that tell the browser how those parts should look.

CSS helps separate the design of a webpage from its content. This makes webpages easier to update and manage. This way, changing a style only needs to be done in one place, not everywhere on the page.

CSS selectors
PatternMatchesFirst defined
in CSS level
Ean element of type E1
E:linkan E element that is the source anchor of a hyperlink whose target is either not yet visited (:link) or already visited (:visited)1
E:visited
E:activean E element during certain user actions1
E:hover2
E:focus
E::first-linethe first formatted line of an E element1
E::first-letterthe first formatted letter of an E element1
.call elements with class="c"1
#myidthe element with id="myid"1
E.warningan E element whose class is "warning" (the document language specifies how class is determined)1
E#myidan E element with ID equal to "myid"1
.c#myidthe element with class="c" and ID equal to "myid"1
E Fan F element descendant of an E element1
*any element2
E[foo]an E element with a "foo" attribute2
E[foo="bar"]an E element whose "foo" attribute value is exactly equal to "bar"2
E[foo~="bar"]an E element whose "foo" attribute value is a list of whitespace-separated values, one of which is exactly equal to "bar"2
E[foo|="en"]an E element whose "foo" attribute has a hyphen-separated list of values beginning (from the left) with "en"2
E:first-childan E element, first child of its parent2
E:lang(fr)an element of type E in language "fr" (the document language specifies how language is determined)2
E::beforegenerated content before an E element's content2
E::aftergenerated content after an E element's content2
E > Fan F element child of an E element2
E + Fan F element immediately preceded by an E element2
E[foo^="bar"]an E element whose "foo" attribute value begins exactly with the string "bar"3
E[foo$="bar"]an E element whose "foo" attribute value ends exactly with the string "bar"3
E[foo*="bar"]an E element whose "foo" attribute value contains the substring "bar"3
E:rootan E element, root of the document3
E:nth-child(n)an E element, the n-th child of its parent3
E:nth-last-child(n)an E element, the n-th child of its parent, counting from the last one3
E:nth-of-type(n)an E element, the n-th sibling of its type3
E:nth-last-of-type(n)an E element, the n-th sibling of its type, counting from the last one3
E:last-childan E element, last child of its parent3
E:first-of-typean E element, first sibling of its type3
E:last-of-typean E element, last sibling of its type3
E:only-childan E element, only child of its parent3
E:only-of-typean E element, only sibling of its type3
E:emptyan E element that has no children (including text nodes)3
E:targetan E element being the target of the referring URI3
E:enableda user interface element E that is enabled3
E:disableda user interface element E that is disabled3
E:checkeda user interface element E that is checked (for instance a radio button or checkbox)3
E:not(s)an E element that does not match simple selector s3
E ~ Fan F element preceded by an E element3
E:has(s)an E element that contains an element matching simple selector s4

Images

Portrait of Håkon Wium Lie, a technology leader and advocate for web standards.
Diagram showing the official structure of CSS web design rules from 2025.

Related articles

This article is a child-friendly adaptation of the Wikipedia article on CSS, available under CC BY-SA 4.0.

Images from Wikimedia Commons. Tap any image to view credits and license.