CSS Reference A to Z: Selectors, Properties and Values
How to use this reference: Selectors identify elements. Properties identify what you want to change. Values specify how that property behaves. The property list below is a broad practical reference, not a guarantee that every experimental or browser-specific property is included.
1. CSS selectors
| Selector type | Syntax | What it selects | Example |
|---|---|---|---|
| Universal | * | Every element | * { box-sizing:border-box; } |
| Type / element | element | Elements by HTML tag name | p |
| Class | .classname | Elements having a class | .card |
| ID | #idname | Element with the specified ID | #header |
| Attribute exists | [attr] | Elements having an attribute | [disabled] |
| Attribute exact | [attr="value"] | Exact attribute value | [type="email"] |
| Attribute contains word | [attr~="value"] | Space-separated attribute word | [class~="featured"] |
| Attribute starts with language prefix | [attr|="value"] | Exact value or value followed by a hyphen | [lang|="en"] |
| Attribute begins with | [attr^="value"] | Attribute value starting with text | [href^="https"] |
| Attribute ends with | [attr$="value"] | Attribute value ending with text | [href$=".pdf"] |
| Attribute contains substring | [attr*="value"] | Attribute value containing text | [class*="box"] |
| Grouping / selector list | A, B | Elements matching A or B | h1, h2, p |
| Descendant combinator | A B | B anywhere inside A | article p |
| Child combinator | A > B | B that is a direct child of A | ul > li |
| Next-sibling combinator | A + B | B immediately following A | h2 + p |
| Subsequent-sibling combinator | A ~ B | Matching B siblings after A | h2 ~ p |
| Column combinator | A || B | Cells belonging to a specified table column | col || td |
| Nesting selector | & | Parent selector in nested CSS | .card { &:hover { ... } } |
2. Common pseudo-classes (single colon)
A pseudo-class selects an element in a particular state, position, or relationship.
| Pseudo-class | Purpose |
|---|---|
:active | Element currently being activated, such as while a link is pressed. |
:any-link | Any link with an href, visited or not. |
:checked | Checked checkbox, radio button, or selected option. |
:default | Default form control in a group or form. |
:disabled | Disabled form control. |
:empty | Element with no element or text children. |
:enabled | Enabled form control. |
:first-child | Element that is the first child of its parent. |
:first-of-type | First sibling of its element type. |
:focus | Element that currently has focus. |
:focus-visible | Focused element when the browser determines focus indication should be visible. |
:focus-within | Element that itself or one of its descendants has focus. |
:has() | Matches an element based on a relative selector inside it. |
:hover | Element currently under a pointing device. |
:in-range | Input value within its permitted range. |
:indeterminate | Control in an indeterminate state. |
:invalid | Form control whose value fails validation. |
:is() | Matches any selector in the supplied selector list. |
:lang() | Element based on its language. |
:last-child | Element that is the last child of its parent. |
:last-of-type | Last sibling of its element type. |
:link | Unvisited link. |
:not() | Elements that do not match the supplied selector. |
:nth-child() | Child selected by a position formula, such as 2n. |
:nth-last-child() | Child selected by position counted from the end. |
:nth-of-type() | Element selected by position among siblings of the same type. |
:nth-last-of-type() | Same-type sibling selected from the end. |
:only-child | Element with no element siblings. |
:only-of-type | Only sibling of its element type. |
:optional | Form control that is not required. |
:out-of-range | Input value outside its permitted range. |
:placeholder-shown | Input currently displaying placeholder text. |
:read-only | Element that cannot be edited by the user. |
:read-write | Element that the user can edit. |
:required | Required form control. |
:root | Document root element (usually html). |
:scope | Reference element for a selector scope. |
:target | Element targeted by the URL fragment. |
:valid | Form control whose value passes validation. |
:visited | Visited link, subject to browser privacy restrictions. |
:where() | Matches a selector list but contributes zero specificity. |
3. Common pseudo-elements (double colon)
| Pseudo-element | Purpose |
|---|---|
::after | Generated content after an element's content. |
::before | Generated content before an element's content. |
::backdrop | Backdrop behind a dialog or fullscreen element. |
::first-letter | First typographic letter of a block. |
::first-line | First formatted line of a block. |
::file-selector-button | Button part of a file input. |
::marker | Marker or bullet of a list item. |
::placeholder | Placeholder text in an input or textarea. |
::selection | Portion of a document selected by the user. |
::slotted() | Slotted elements inside a web component's shadow tree. |
::cue | WebVTT captions and cues in media. |
4. CSS properties A to Z
This alphabetical list focuses on standard, widely used CSS properties and important modern layout properties. CSS specifications continue to evolve; experimental, deprecated, vendor-prefixed and some specialist SVG properties are not all included.
| Letter | Properties |
|---|---|
| A | accent-color, align-content, align-items, align-self, all, animation, animation-delay, animation-direction, animation-duration, animation-fill-mode, animation-iteration-count, animation-name, animation-play-state, animation-timing-function, appearance, aspect-ratio |
| B | backdrop-filter, backface-visibility, background, background-attachment, background-blend-mode, background-clip, background-color, background-image, background-origin, background-position, background-repeat, background-size, block-size, border, border-block, border-bottom, border-bottom-color, border-bottom-left-radius, border-bottom-right-radius, border-bottom-style, border-bottom-width, border-collapse, border-color, border-image, border-left, border-radius, border-right, border-spacing, border-style, border-top, border-width, bottom, box-decoration-break, box-shadow, box-sizing, break-after, break-before, break-inside |
| C | caption-side, caret-color, clear, clip-path, color, color-scheme, column-count, column-fill, column-gap, column-rule, column-span, column-width, columns, contain, content, content-visibility, counter-increment, counter-reset, cursor |
| D | direction, display, dominant-baseline |
| E | empty-cells |
| F | fill, filter, flex, flex-basis, flex-direction, flex-flow, flex-grow, flex-shrink, flex-wrap, float, flood-color, font, font-family, font-feature-settings, font-kerning, font-size, font-stretch, font-style, font-variant, font-weight, forced-color-adjust |
| G | gap, grid, grid-area, grid-auto-columns, grid-auto-flow, grid-auto-rows, grid-column, grid-column-end, grid-column-gap, grid-column-start, grid-row, grid-row-end, grid-row-gap, grid-row-start, grid-template, grid-template-areas, grid-template-columns, grid-template-rows |
| H | height, hyphens |
| I | image-rendering, inline-size, inset, inset-block, inset-inline, isolation |
| J | justify-content, justify-items, justify-self |
| K | No widely used standard CSS property currently begins with K. keep-all is a value of word-break, not a property. |
| L | left, letter-spacing, line-break, line-height, list-style, list-style-image, list-style-position, list-style-type |
| M | margin, margin-block, margin-bottom, margin-inline, margin-left, margin-right, margin-top, mask, max-block-size, max-height, max-inline-size, max-width, min-block-size, min-height, min-inline-size, min-width, mix-blend-mode |
| N | object-fit does not belong here; there are no commonly used standard CSS properties beginning with N in the core beginner property set. |
| O | object-fit, object-position, offset, opacity, order, orphans, outline, outline-color, outline-offset, outline-style, outline-width, overflow, overflow-anchor, overflow-wrap, overflow-x, overflow-y, overscroll-behavior |
| P | padding, padding-block, padding-bottom, padding-inline, padding-left, padding-right, padding-top, page-break-after, page-break-before, page-break-inside, perspective, perspective-origin, place-content, place-items, place-self, pointer-events, position |
| Q | quotes |
| R | resize, right, rotate, row-gap |
| S | scale, scroll-behavior, scroll-margin, scroll-padding, scroll-snap-align, scroll-snap-stop, scroll-snap-type, scrollbar-color, scrollbar-gutter, scrollbar-width, shape-outside, stroke, stroke-width |
| T | tab-size, table-layout, text-align, text-align-last, text-decoration, text-decoration-color, text-decoration-line, text-decoration-style, text-indent, text-overflow, text-shadow, text-transform, text-wrap, top, touch-action, transform, transform-origin, transform-style, transition, transition-delay, transition-duration, transition-property, transition-timing-function |
| U | unicode-bidi, user-select |
| V | vector-effect, vertical-align, view-transition-name, visibility |
| W | white-space, widows, width, will-change, word-break, word-spacing, writing-mode |
| X | x (SVG presentation property) |
| Y | y (SVG presentation property) |
| Z | z-index, zoom |
5. CSS values and units
A value is chosen according to the property. There is no single universal list of values that works for every property.
| Value family | Common values / examples | Typical use |
|---|---|---|
| CSS-wide keywords | inherit, initial, unset, revert, revert-layer | Control inheritance and cascade behavior; accepted by nearly all properties. |
| Length units | px, em, rem, vw, vh, vmin, vmax, svh, lvh, dvh, ch, ex, lh, rlh | Dimensions, spacing, font sizes and positioning. |
| Physical units | cm, mm, in, pt, pc, Q | Print and physical measurements. |
| Percentages | 25%, 50%, 100% | Relative sizing; meaning depends on the property. |
| Color names | red, blue, black, white, transparent, currentColor | Text, backgrounds, borders and other color properties. |
| Hex colors | #000, #fff, #ff0000, #336699cc | Color notation. |
| Color functions | rgb(), hsl(), hwb(), lab(), lch(), oklab(), oklch(), color() | Functional color notation. |
| Display | none, block, inline, inline-block, flow-root, flex, inline-flex, grid, inline-grid, table, contents, list-item | display |
| Position | static, relative, absolute, fixed, sticky | position |
| Font weight | normal, bold, lighter, bolder, 100 to 900 | font-weight |
| Font style | normal, italic, oblique | font-style |
| Text alignment | start, end, left, right, center, justify | text-align |
| Text transform | none, capitalize, uppercase, lowercase, full-width | text-transform |
| Overflow | visible, hidden, clip, scroll, auto | overflow, overflow-x, overflow-y |
| Visibility | visible, hidden, collapse | visibility |
| Border style | none, hidden, solid, dashed, dotted, double, groove, ridge, inset, outset | border-style |
| Background repeat | repeat, repeat-x, repeat-y, no-repeat, space, round | background-repeat |
| Background size | auto, cover, contain, length or percentage pairs | background-size |
| Box sizing | content-box, border-box | box-sizing |
| Flex direction | row, row-reverse, column, column-reverse | flex-direction |
| Flex wrapping | nowrap, wrap, wrap-reverse | flex-wrap |
| Flex alignment | flex-start, flex-end, center, space-between, space-around, space-evenly | Common alignment values in flex layouts. |
| Grid sizing | fr, auto, min-content, max-content, minmax(), repeat() | Grid tracks and layout. |
| Cursor | auto, default, pointer, text, move, wait, help, grab, not-allowed, crosshair | cursor |
| Time units | s, ms | Animation and transition durations. |
| Angle units | deg, rad, grad, turn | Rotation, gradients and transforms. |
| Resolution units | dpi, dpcm, dppx | Resolution media queries and image resolution. |
| Integer / number | 0, 1, 2, 0.5 | Opacity, order, z-index, counters and other numeric properties. |
6. Common CSS functions
| Function | Example | Purpose |
|---|---|---|
calc() | width:calc(100% - 20px) | Calculates a value from compatible units. |
min() | width:min(100%, 600px) | Returns the smallest argument. |
max() | width:max(50%, 300px) | Returns the largest argument. |
clamp() | font-size:clamp(16px, 3vw, 30px) | Clamps a value between a minimum and maximum. |
var() | color:var(--main-color) | Uses a custom CSS property (variable). |
url() | background-image:url("photo.jpg") | References an external resource. |
rgb() | color:rgb(20 80 160) | Defines an RGB color. |
hsl() | color:hsl(210 70% 45%) | Defines a hue, saturation and lightness color. |
linear-gradient() | background:linear-gradient(to right, red, blue) | Creates a linear color gradient. |
radial-gradient() | background:radial-gradient(circle, white, blue) | Creates a radial color gradient. |
repeating-linear-gradient() | background:repeating-linear-gradient(45deg, #eee 0 5px, #fff 5px 10px) | Creates a repeating linear gradient. |
translate() | transform:translate(10px, 20px) | Moves an element visually. |
rotate() | transform:rotate(15deg) | Rotates an element. |
scale() | transform:scale(1.1) | Scales an element. |
skew() | transform:skew(10deg) | Skews an element. |
matrix() | transform:matrix(1, 0, 0, 1, 20, 10) | Applies a 2D transformation matrix. |
minmax() | grid-template-columns:minmax(150px, 1fr) | Defines a grid track size range. |
repeat() | grid-template-columns:repeat(3, 1fr) | Repeats grid track definitions. |
fit-content() | width:fit-content(400px) | Sizes content within a limit. |
cubic-bezier() | transition-timing-function:cubic-bezier(.2,.8,.2,1) | Defines a custom easing curve. |
steps() | animation-timing-function:steps(4) | Creates stepped animation timing. |
blur() | filter:blur(4px) | Blurs an element. |
brightness() | filter:brightness(1.2) | Adjusts brightness. |
drop-shadow() | filter:drop-shadow(2px 3px 4px #777) | Adds a shadow filter. |
7. Important CSS at-rules
| At-rule | Purpose | Example |
|---|---|---|
@charset | Declares stylesheet character encoding; when used, it must appear first. | @charset "UTF-8"; |
@import | Imports another stylesheet. | @import url("theme.css"); |
@media | Applies rules when a media condition matches. | @media (max-width:600px) { ... } |
@supports | Applies rules when a browser supports a feature. | @supports (display:grid) { ... } |
@font-face | Defines a downloadable font. | @font-face { font-family:MyFont; src:url("font.woff2"); } |
@keyframes | Defines animation stages. | @keyframes fade { from {opacity:0} to {opacity:1} } |
@layer | Defines cascade layers. | @layer base, theme; |
@container | Applies styles based on a container's size or state. | @container (min-width:400px) { ... } |
@page | Controls printed page layout. | @page { margin: 1cm; } |
@property | Registers a custom property with a defined syntax and behavior. | @property --gap { syntax:"<length>"; inherits:false; initial-value:0px; } |
@scope | Limits the scope of style rules to a DOM subtree. | @scope (.card) { ... } |
@starting-style | Provides starting styles for transitions from a not-rendered state. | @starting-style { .panel { opacity:0; } } |
8. Complete CSS example
This example combines a selector, properties, values, a pseudo-class and a pseudo-element.
/* Select an element with class="card" */
.card {
width: 90%;
max-width: 500px;
padding: 20px;
margin: 20px auto;
color: white;
background: linear-gradient(135deg, #3498db, #8e44ad);
border: 2px solid #222;
border-radius: 12px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
transition: transform 0.3s ease;
}
/* Pseudo-class */
.card:hover {
transform: scale(1.03);
}
/* Pseudo-element */
.card::after {
content: "CSS example";
font-weight: bold;
}
9. Important notes
- A selector does not change an element by itself; it identifies the element to which declarations apply.
- A property must accept the value assigned to it. For example,
color:20pxis invalid. - Some properties inherit from parents (such as
color); others normally do not (such asmargin). - Shorthand properties such as
margin,border,backgroundandfontset multiple related longhand properties. - CSS values are property-specific. For example,
coveris valid forbackground-sizeandobject-fit, but not forcolor. - Browser support can differ, especially for newer features. Test important features in the browsers used by your readers.
Further reading: MDN CSS Reference · CSS Selectors · CSS Values

Post a Comment