All CSS Selector, properties and values

CSS Reference A to Z: Selectors, Properties and Values

CSS Reference A to Z: Selectors, Properties and Values

CSS (Cascading Style Sheets) controls the presentation and layout of HTML documents. A CSS rule normally contains a selector and one or more property-value declarations.

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 typeSyntaxWhat it selectsExample
Universal*Every element* { box-sizing:border-box; }
Type / elementelementElements by HTML tag namep
Class.classnameElements having a class.card
ID#idnameElement 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 listA, BElements matching A or Bh1, h2, p
Descendant combinatorA BB anywhere inside Aarticle p
Child combinatorA > BB that is a direct child of Aul > li
Next-sibling combinatorA + BB immediately following Ah2 + p
Subsequent-sibling combinatorA ~ BMatching B siblings after Ah2 ~ p
Column combinatorA || BCells belonging to a specified table columncol || 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-classPurpose
:activeElement currently being activated, such as while a link is pressed.
:any-linkAny link with an href, visited or not.
:checkedChecked checkbox, radio button, or selected option.
:defaultDefault form control in a group or form.
:disabledDisabled form control.
:emptyElement with no element or text children.
:enabledEnabled form control.
:first-childElement that is the first child of its parent.
:first-of-typeFirst sibling of its element type.
:focusElement that currently has focus.
:focus-visibleFocused element when the browser determines focus indication should be visible.
:focus-withinElement that itself or one of its descendants has focus.
:has()Matches an element based on a relative selector inside it.
:hoverElement currently under a pointing device.
:in-rangeInput value within its permitted range.
:indeterminateControl in an indeterminate state.
:invalidForm control whose value fails validation.
:is()Matches any selector in the supplied selector list.
:lang()Element based on its language.
:last-childElement that is the last child of its parent.
:last-of-typeLast sibling of its element type.
:linkUnvisited 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-childElement with no element siblings.
:only-of-typeOnly sibling of its element type.
:optionalForm control that is not required.
:out-of-rangeInput value outside its permitted range.
:placeholder-shownInput currently displaying placeholder text.
:read-onlyElement that cannot be edited by the user.
:read-writeElement that the user can edit.
:requiredRequired form control.
:rootDocument root element (usually html).
:scopeReference element for a selector scope.
:targetElement targeted by the URL fragment.
:validForm control whose value passes validation.
:visitedVisited link, subject to browser privacy restrictions.
:where()Matches a selector list but contributes zero specificity.

3. Common pseudo-elements (double colon)

Pseudo-elementPurpose
::afterGenerated content after an element's content.
::beforeGenerated content before an element's content.
::backdropBackdrop behind a dialog or fullscreen element.
::first-letterFirst typographic letter of a block.
::first-lineFirst formatted line of a block.
::file-selector-buttonButton part of a file input.
::markerMarker or bullet of a list item.
::placeholderPlaceholder text in an input or textarea.
::selectionPortion of a document selected by the user.
::slotted()Slotted elements inside a web component's shadow tree.
::cueWebVTT 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.

LetterProperties
Aaccent-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
Bbackdrop-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
Ccaption-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
Ddirection, display, dominant-baseline
Eempty-cells
Ffill, 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
Ggap, 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
Hheight, hyphens
Iimage-rendering, inline-size, inset, inset-block, inset-inline, isolation
Jjustify-content, justify-items, justify-self
KNo widely used standard CSS property currently begins with K. keep-all is a value of word-break, not a property.
Lleft, letter-spacing, line-break, line-height, list-style, list-style-image, list-style-position, list-style-type
Mmargin, 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
Nobject-fit does not belong here; there are no commonly used standard CSS properties beginning with N in the core beginner property set.
Oobject-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
Ppadding, 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
Qquotes
Rresize, right, rotate, row-gap
Sscale, 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
Ttab-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
Uunicode-bidi, user-select
Vvector-effect, vertical-align, view-transition-name, visibility
Wwhite-space, widows, width, will-change, word-break, word-spacing, writing-mode
Xx (SVG presentation property)
Yy (SVG presentation property)
Zz-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 familyCommon values / examplesTypical use
CSS-wide keywordsinherit, initial, unset, revert, revert-layerControl inheritance and cascade behavior; accepted by nearly all properties.
Length unitspx, em, rem, vw, vh, vmin, vmax, svh, lvh, dvh, ch, ex, lh, rlhDimensions, spacing, font sizes and positioning.
Physical unitscm, mm, in, pt, pc, QPrint and physical measurements.
Percentages25%, 50%, 100%Relative sizing; meaning depends on the property.
Color namesred, blue, black, white, transparent, currentColorText, backgrounds, borders and other color properties.
Hex colors#000, #fff, #ff0000, #336699ccColor notation.
Color functionsrgb(), hsl(), hwb(), lab(), lch(), oklab(), oklch(), color()Functional color notation.
Displaynone, block, inline, inline-block, flow-root, flex, inline-flex, grid, inline-grid, table, contents, list-itemdisplay
Positionstatic, relative, absolute, fixed, stickyposition
Font weightnormal, bold, lighter, bolder, 100 to 900font-weight
Font stylenormal, italic, obliquefont-style
Text alignmentstart, end, left, right, center, justifytext-align
Text transformnone, capitalize, uppercase, lowercase, full-widthtext-transform
Overflowvisible, hidden, clip, scroll, autooverflow, overflow-x, overflow-y
Visibilityvisible, hidden, collapsevisibility
Border stylenone, hidden, solid, dashed, dotted, double, groove, ridge, inset, outsetborder-style
Background repeatrepeat, repeat-x, repeat-y, no-repeat, space, roundbackground-repeat
Background sizeauto, cover, contain, length or percentage pairsbackground-size
Box sizingcontent-box, border-boxbox-sizing
Flex directionrow, row-reverse, column, column-reverseflex-direction
Flex wrappingnowrap, wrap, wrap-reverseflex-wrap
Flex alignmentflex-start, flex-end, center, space-between, space-around, space-evenlyCommon alignment values in flex layouts.
Grid sizingfr, auto, min-content, max-content, minmax(), repeat()Grid tracks and layout.
Cursorauto, default, pointer, text, move, wait, help, grab, not-allowed, crosshaircursor
Time unitss, msAnimation and transition durations.
Angle unitsdeg, rad, grad, turnRotation, gradients and transforms.
Resolution unitsdpi, dpcm, dppxResolution media queries and image resolution.
Integer / number0, 1, 2, 0.5Opacity, order, z-index, counters and other numeric properties.

6. Common CSS functions

FunctionExamplePurpose
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-rulePurposeExample
@charsetDeclares stylesheet character encoding; when used, it must appear first.@charset "UTF-8";
@importImports another stylesheet.@import url("theme.css");
@mediaApplies rules when a media condition matches.@media (max-width:600px) { ... }
@supportsApplies rules when a browser supports a feature.@supports (display:grid) { ... }
@font-faceDefines a downloadable font.@font-face { font-family:MyFont; src:url("font.woff2"); }
@keyframesDefines animation stages.@keyframes fade { from {opacity:0} to {opacity:1} }
@layerDefines cascade layers.@layer base, theme;
@containerApplies styles based on a container's size or state.@container (min-width:400px) { ... }
@pageControls printed page layout.@page { margin: 1cm; }
@propertyRegisters a custom property with a defined syntax and behavior.@property --gap { syntax:"<length>"; inherits:false; initial-value:0px; }
@scopeLimits the scope of style rules to a DOM subtree.@scope (.card) { ... }
@starting-styleProvides 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:20px is invalid.
  • Some properties inherit from parents (such as color); others normally do not (such as margin).
  • Shorthand properties such as margin, border, background and font set multiple related longhand properties.
  • CSS values are property-specific. For example, cover is valid for background-size and object-fit, but not for color.
  • 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

Previous Post Next Post